Skip to content

Commit 6715453

Browse files
committed
Added: Playlists API: add Playlist Items and reorder or replace Playlist Items
1 parent c848a14 commit 6715453

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

src/main/java/Client/SpotifyRestAPI.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
import Controller.PlayerController.baseUserPlayback;
2222
import Controller.PlaylistController.Playlist;
2323
import Controller.PlaylistController.PlaylistItems.BasePlaylistItems;
24+
import Controller.PlaylistController.SnapshotId;
2425
import Model.*;
26+
import com.google.gson.internal.GsonBuildConfig;
2527
import getRequests.AlbumInterface;
2628

2729
import retrofit2.Call;
@@ -1408,6 +1410,44 @@ public BasePlaylistItems getPlaylistItems(SpotifyClient client) throws IOExcepti
14081410

14091411
}
14101412

1413+
public SnapshotId addItemsToPlaylist(SpotifyClient client) throws IOException {
1414+
1415+
String url = baseUrl + String.format("/v1/playlists/%s/tracks/",client.getPlaylist().getPlaylistId());
1416+
1417+
Retrofit retrofit = new Retrofit.Builder()
1418+
.baseUrl(url)
1419+
.addConverterFactory(GsonConverterFactory.create())
1420+
.build();
1421+
1422+
playlistInterface playlistInterface = retrofit.create(Model.playlistInterface.class);
1423+
1424+
Call<SnapshotId> call = playlistInterface.addItemsToPlaylist(getTokenString(client.getToken()),client.getPlaylist().getPlaylistId());
1425+
1426+
Response<SnapshotId> response = call.execute();
1427+
1428+
return response.body();
1429+
1430+
}
1431+
1432+
public SnapshotId reorderOrReplacePlaylistItems(SpotifyClient client) throws IOException {
1433+
1434+
String url = baseUrl + String.format("/v1/playlists/%s/tracks/",client.getPlaylist().getPlaylistId());
1435+
1436+
Retrofit retrofit = new Retrofit.Builder()
1437+
.baseUrl(url)
1438+
.addConverterFactory(GsonConverterFactory.create())
1439+
.build();
1440+
1441+
playlistInterface playlistInterface = retrofit.create(Model.playlistInterface.class);
1442+
1443+
Call<SnapshotId> call = playlistInterface.reorderOrReplacePlaylistsItems(getTokenString(client.getToken()),client.getPlaylist().getPlaylistId());
1444+
1445+
Response<SnapshotId> response = call.execute();
1446+
1447+
return response.body();
1448+
1449+
}
1450+
14111451

14121452

14131453

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package Controller.PlaylistController;
2+
3+
import com.google.gson.annotations.Expose;
4+
import com.google.gson.annotations.SerializedName;
5+
6+
public class SnapshotId {
7+
8+
@SerializedName("snapshot_id")
9+
@Expose
10+
private String snapshotId;
11+
12+
public String getSnapshotId() {
13+
return snapshotId;
14+
}
15+
16+
public void setSnapshotId(String snapshotId) {
17+
this.snapshotId = snapshotId;
18+
}
19+
20+
21+
}

src/main/java/Model/playlistInterface.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import Controller.PlaylistController.Playlist;
44
import Controller.PlaylistController.PlaylistItems.BasePlaylistItems;
5+
import Controller.PlaylistController.SnapshotId;
56
import Controller.PlaylistController.UserPlaylists.BasePlaylist;
67
import retrofit2.Call;
78
import retrofit2.http.*;
@@ -28,4 +29,10 @@ public interface playlistInterface {
2829
@GET("https://api.spotify.com/v1/playlists/{playlistId}/tracks")
2930
Call<BasePlaylistItems> getPlaylistItems(@Header("Authorization") String auth, @Path("playlistId") String playlistId);
3031

32+
@POST("https://api.spotify.com/v1/playlists/{playlistId}/tracks")
33+
Call<SnapshotId> addItemsToPlaylist(@Header("Authorization") String auth, @Path("playlistId") String playlistId);
34+
35+
@PUT("https://api.spotify.com/v1/playlists/{playlistId}/tracks")
36+
Call<SnapshotId> reorderOrReplacePlaylistsItems(@Header("Authorization") String auth, @Path("playlistId") String playlistId);
37+
3138
}

0 commit comments

Comments
 (0)