|
16 | 16 | import spotify.models.playlists.PlaylistSimplified; |
17 | 17 | import spotify.models.playlists.PlaylistTrack; |
18 | 18 | import spotify.models.playlists.Snapshot; |
19 | | -import spotify.models.playlists.requests.AddItemPlaylistRequestBody; |
20 | | -import spotify.models.playlists.requests.CreateUpdatePlaylistRequestBody; |
21 | | -import spotify.models.playlists.requests.ReorderPlaylistItemsRequestBody; |
22 | | -import spotify.models.playlists.requests.ReplacePlaylistItemsRequestBody; |
| 19 | +import spotify.models.playlists.requests.*; |
23 | 20 | import spotify.retrofit.services.PlaylistService; |
24 | 21 | import spotify.utils.LoggingUtil; |
25 | 22 | import spotify.utils.ResponseChecker; |
@@ -321,6 +318,39 @@ public void uploadCoverImageToPlaylist(String playlistId, String base64EncodedJp |
321 | 318 | } |
322 | 319 | } |
323 | 320 |
|
| 321 | + @Override |
| 322 | + public Snapshot deleteItemsFromPlaylist(String playlistId, String snapshotId, DeleteItemsPlaylistRequestBody items) { |
| 323 | + if (playlistId == null || playlistId.isEmpty()) { |
| 324 | + final String errorMessage = "Playlist id is empty!"; |
| 325 | + logger.error(errorMessage); |
| 326 | + throw new IllegalArgumentException(errorMessage); |
| 327 | + } |
| 328 | + |
| 329 | + if (snapshotId != null && snapshotId.isEmpty()) { |
| 330 | + logger.warn("An empty snapshot id was passed in. The snapshot id has now been set to NULL."); |
| 331 | + snapshotId = null; |
| 332 | + } |
| 333 | + |
| 334 | + logger.trace("Constructing HTTP call to remove items from a playlist."); |
| 335 | + Call<Snapshot> httpCall = playlistService.deleteItemsFromPlaylist("Bearer " + this.accessToken, playlistId, items); |
| 336 | + |
| 337 | + try { |
| 338 | + logger.info("Executing HTTP call to remove items from a playlist."); |
| 339 | + logger.debug(String.format("Removing items from playlist %s with snapshot id %s", playlistId, snapshotId)); |
| 340 | + logger.debug(String.format("Removing the following items %s", items)); |
| 341 | + LoggingUtil.logHttpCall(logger, httpCall); |
| 342 | + Response<Snapshot> response = httpCall.execute(); |
| 343 | + |
| 344 | + ResponseChecker.throwIfRequestHasNotBeenFulfilledCorrectly(response, HttpStatusCode.OK); |
| 345 | + |
| 346 | + logger.info("Items have been successfully removed from the playlist"); |
| 347 | + return response.body(); |
| 348 | + } catch (IOException ex) { |
| 349 | + logger.error("HTTP request to remove items from playlist has failed"); |
| 350 | + throw new HttpRequestFailedException(ex.getMessage()); |
| 351 | + } |
| 352 | + } |
| 353 | + |
324 | 354 | private void validateParametersReorderFunction(String playlistId, ReorderPlaylistItemsRequestBody requestBody) { |
325 | 355 | if (playlistId == null || playlistId.isEmpty()) { |
326 | 356 | final String errorMessage = "Playlist id can not be empty!"; |
|
0 commit comments