Skip to content

Commit b216f97

Browse files
Jiankai ZhengJiankai Zheng
authored andcommitted
feat(api): api call to delete saved tracks
1 parent 827f05d commit b216f97

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/main/java/spotify/api/impl/LibraryApiRetrofit.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,4 +281,26 @@ public void deleteShows(List<String> listOfShowIds, Map<String, String> options)
281281
throw new HttpRequestFailedException(ex.getMessage());
282282
}
283283
}
284+
285+
@Override
286+
public void deleteTracks(List<String> listOfTrackIds) {
287+
String trackIds = String.join(",", listOfTrackIds);
288+
289+
logger.trace("Constructing HTTP call to delete the saved tracks");
290+
Call<Void> httpCall = libraryService.deleteTracks("Bearer " + this.accessToken, trackIds);
291+
292+
try {
293+
logger.info("Executing HTTP call to delete the saved tracks.");
294+
logger.debug(String.format("Deleting saved tracks with following track ids: %s.", trackIds));
295+
LoggingUtil.logHttpCall(logger, httpCall);
296+
Response<Void> response = httpCall.execute();
297+
298+
ResponseChecker.throwIfRequestHasNotBeenFulfilledCorrectly(response, HttpStatusCode.OK);
299+
300+
logger.info("Saved tracks have been successfully deleted");
301+
} catch (IOException ex) {
302+
logger.error("HTTP request to delete saved tracks has failed.");
303+
throw new HttpRequestFailedException(ex.getMessage());
304+
}
305+
}
284306
}

src/main/java/spotify/api/interfaces/LibraryApi.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@ public interface LibraryApi {
3030
void deleteAlbums(List<String> listOfAlbumIds);
3131

3232
void deleteShows(List<String> listOfShowIds, Map<String, String> options);
33+
34+
void deleteTracks(List<String> listOfTrackIds);
3335
}

src/main/java/spotify/api/spotify/SpotifyApi.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,11 @@ public void deleteShows(List<String> listOfShowIds, Map<String, String> options)
281281
libraryApi.deleteShows(listOfShowIds, options);
282282
}
283283

284+
public void deleteTracks(List<String> listOfTracksIds) {
285+
logger.info("Requesting to delete saved tracks");
286+
libraryApi.deleteTracks(listOfTracksIds);
287+
}
288+
284289
private void setup(final String accessToken) {
285290
logger.trace("Constructing Retrofit APIs");
286291
this.trackApi = new TrackApiRetrofit(accessToken);

0 commit comments

Comments
 (0)