Skip to content

Commit 8648117

Browse files
committed
fix: add ReplacePlaylistItems, which uses the new endpoint
fixes #1040
1 parent 7b0952c commit 8648117

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

SpotifyAPI.Web/Clients/Interfaces/IPlaylistsClient.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public interface IPlaylistsClient
169169
/// https://developer.spotify.com/documentation/web-api/reference-beta/#endpoint-replace-playlists-tracks
170170
/// </remarks>
171171
/// <returns></returns>
172-
[Obsolete("Use UpdatePlaylistItems instead, which uses the new PUT /playlists/{id}/items endpoint.")]
172+
[Obsolete("Use ReplacePlaylistItems instead, which uses the new PUT /playlists/{id}/items endpoint.")]
173173
Task<SnapshotResponse> ReplaceItems(string playlistId, PlaylistReplaceItemsRequest request, CancellationToken cancel = default);
174174

175175
/// <summary>
@@ -276,5 +276,18 @@ public interface IPlaylistsClient
276276
/// </remarks>
277277
/// <returns></returns>
278278
Task<SnapshotResponse> UpdatePlaylistItems(string playlistId, PlaylistReorderItemsRequest request, CancellationToken cancel = default);
279+
280+
/// <summary>
281+
/// Replace all the items in a playlist, overwriting its existing items.
282+
/// This powerful request can be useful for replacing items, re-ordering existing items, or clearing the playlist.
283+
/// </summary>
284+
/// <param name="playlistId">The Spotify ID for the playlist.</param>
285+
/// <param name="request">The request-model which contains required and optional parameters.</param>
286+
/// <param name="cancel">The cancellation-token to allow to cancel the request.</param>
287+
/// <remarks>
288+
/// https://developer.spotify.com/documentation/web-api/reference-beta/#endpoint-replace-playlists-tracks
289+
/// </remarks>
290+
/// <returns></returns>
291+
Task<SnapshotResponse> ReplacePlaylistItems(string playlistId, PlaylistReplaceItemsRequest request, CancellationToken cancel = default);
279292
}
280293
}

SpotifyAPI.Web/Clients/PlaylistsClient.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public Task<FullPlaylist> Get(string playlistId, PlaylistGetRequest request, Can
110110
return API.Get<FullPlaylist>(URLs.Playlist(playlistId), request.BuildQueryParams(), cancel);
111111
}
112112

113-
[System.Obsolete("This endpoint (PUT /playlists/{playlist_id}/tracks) has been removed. Use UpdatePlaylistItems instead, which uses the new PUT /playlists/{id}/items endpoint.")]
113+
[System.Obsolete("This endpoint (PUT /playlists/{playlist_id}/tracks) has been removed. Use ReplacePlaylistItems instead, which uses the new PUT /playlists/{id}/items endpoint.")]
114114
public Task<SnapshotResponse> ReplaceItems(string playlistId, PlaylistReplaceItemsRequest request, CancellationToken cancel = default)
115115
{
116116
Ensure.ArgumentNotNullOrEmptyString(playlistId, nameof(playlistId));
@@ -187,5 +187,13 @@ public Task<SnapshotResponse> UpdatePlaylistItems(string playlistId, PlaylistReo
187187

188188
return API.Put<SnapshotResponse>(URLs.PlaylistItems(playlistId), null, request.BuildBodyParams(), cancel);
189189
}
190+
191+
public Task<SnapshotResponse> ReplacePlaylistItems(string playlistId, PlaylistReplaceItemsRequest request, CancellationToken cancel = default)
192+
{
193+
Ensure.ArgumentNotNullOrEmptyString(playlistId, nameof(playlistId));
194+
Ensure.ArgumentNotNull(request, nameof(request));
195+
196+
return API.Put<SnapshotResponse>(URLs.PlaylistItems(playlistId), null, request.BuildBodyParams(), cancel);
197+
}
190198
}
191199
}

0 commit comments

Comments
 (0)