Skip to content

Commit 1b83561

Browse files
committed
1 parent 8293f64 commit 1b83561

11 files changed

Lines changed: 256 additions & 2 deletions

‎SpotifyAPI.Web/Clients/Interfaces/ILibraryClient.cs‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,5 +274,38 @@ public interface ILibraryClient
274274
/// </remarks>
275275
/// <returns></returns>
276276
Task<Paging<SimpleAudiobook>> GetAudiobooks(LibraryAudiobooksRequest request, CancellationToken cancel = default);
277+
278+
/// <summary>
279+
/// Save a list of Spotify URIs to the current user's library.
280+
/// </summary>
281+
/// <param name="request">The request-model which contains required and optional parameters.</param>
282+
/// <param name="cancel">The cancellation-token to allow to cancel the request.</param>
283+
/// <remarks>
284+
/// https://developer.spotify.com/documentation/web-api/reference/save-library-items
285+
/// </remarks>
286+
/// <returns></returns>
287+
Task<bool> SaveItems(LibrarySaveItemsRequest request, CancellationToken cancel = default);
288+
289+
/// <summary>
290+
/// Remove a list of Spotify URIs from the current user's library.
291+
/// </summary>
292+
/// <param name="request">The request-model which contains required and optional parameters.</param>
293+
/// <param name="cancel">The cancellation-token to allow to cancel the request.</param>
294+
/// <remarks>
295+
/// https://developer.spotify.com/documentation/web-api/reference/remove-library-items
296+
/// </remarks>
297+
/// <returns></returns>
298+
Task<bool> RemoveItems(LibraryRemoveItemsRequest request, CancellationToken cancel = default);
299+
300+
/// <summary>
301+
/// Check if one or more items are already saved in the current user's library.
302+
/// </summary>
303+
/// <param name="request">The request-model which contains required and optional parameters.</param>
304+
/// <param name="cancel">The cancellation-token to allow to cancel the request.</param>
305+
/// <remarks>
306+
/// https://developer.spotify.com/documentation/web-api/reference/check-library-contains
307+
/// </remarks>
308+
/// <returns></returns>
309+
Task<List<bool>> CheckItems(LibraryCheckItemsRequest request, CancellationToken cancel = default);
277310
}
278311
}

‎SpotifyAPI.Web/Clients/Interfaces/IPlaylistsClient.cs‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,5 +196,64 @@ public interface IPlaylistsClient
196196
/// </remarks>
197197
/// <returns></returns>
198198
Task<SnapshotResponse> ReorderItems(string playlistId, PlaylistReorderItemsRequest request, CancellationToken cancel = default);
199+
200+
/// <summary>
201+
/// Add one or more items to a user's playlist using the new /items endpoint.
202+
/// </summary>
203+
/// <param name="playlistId">The Spotify ID for the playlist.</param>
204+
/// <param name="request">The request-model which contains required and optional parameters.</param>
205+
/// <param name="cancel">The cancellation-token to allow to cancel the request.</param>
206+
/// <remarks>
207+
/// https://developer.spotify.com/documentation/web-api/reference/add-items-to-playlist
208+
/// </remarks>
209+
/// <returns></returns>
210+
Task<SnapshotResponse> AddPlaylistItems(string playlistId, PlaylistAddItemsRequest request, CancellationToken cancel = default);
211+
212+
/// <summary>
213+
/// Get full details of the items of a playlist using the new /items endpoint.
214+
/// </summary>
215+
/// <param name="playlistId">The Spotify ID for the playlist.</param>
216+
/// <param name="cancel">The cancellation-token to allow to cancel the request.</param>
217+
/// <remarks>
218+
/// https://developer.spotify.com/documentation/web-api/reference/get-playlists-items
219+
/// </remarks>
220+
/// <returns></returns>
221+
Task<Paging<PlaylistTrack<IPlayableItem>>> GetPlaylistItems(string playlistId, CancellationToken cancel = default);
222+
223+
/// <summary>
224+
/// Get full details of the items of a playlist using the new /items endpoint.
225+
/// </summary>
226+
/// <param name="playlistId">The Spotify ID for the playlist.</param>
227+
/// <param name="request">The request-model which contains required and optional parameters.</param>
228+
/// <param name="cancel">The cancellation-token to allow to cancel the request.</param>
229+
/// <remarks>
230+
/// https://developer.spotify.com/documentation/web-api/reference/get-playlists-items
231+
/// </remarks>
232+
/// <returns></returns>
233+
Task<Paging<PlaylistTrack<IPlayableItem>>> GetPlaylistItems(string playlistId, PlaylistGetItemsRequest request, CancellationToken cancel = default);
234+
235+
/// <summary>
236+
/// Remove one or more items from a user's playlist using the new /items endpoint.
237+
/// </summary>
238+
/// <param name="playlistId">The Spotify ID for the playlist.</param>
239+
/// <param name="request">The request-model which contains required and optional parameters.</param>
240+
/// <param name="cancel">The cancellation-token to allow to cancel the request.</param>
241+
/// <remarks>
242+
/// https://developer.spotify.com/documentation/web-api/reference/remove-items-playlist
243+
/// </remarks>
244+
/// <returns></returns>
245+
Task<SnapshotResponse> RemovePlaylistItems(string playlistId, PlaylistRemoveItemsRequest request, CancellationToken cancel = default);
246+
247+
/// <summary>
248+
/// Either reorder or replace items in a playlist using the new /items endpoint.
249+
/// </summary>
250+
/// <param name="playlistId">The Spotify ID for the playlist.</param>
251+
/// <param name="request">The request-model which contains required and optional parameters.</param>
252+
/// <param name="cancel">The cancellation-token to allow to cancel the request.</param>
253+
/// <remarks>
254+
/// https://developer.spotify.com/documentation/web-api/reference/reorder-or-replace-playlists-items
255+
/// </remarks>
256+
/// <returns></returns>
257+
Task<SnapshotResponse> UpdatePlaylistItems(string playlistId, PlaylistReorderItemsRequest request, CancellationToken cancel = default);
199258
}
200259
}

‎SpotifyAPI.Web/Clients/LibraryClient.cs‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,5 +178,28 @@ public Task<List<bool>> CheckAudiobooks(LibraryCheckAudiobooksRequest request, C
178178

179179
return API.Get<List<bool>>(SpotifyUrls.LibraryAudiobooksContains(), request.BuildQueryParams(), cancel);
180180
}
181+
182+
public async Task<bool> SaveItems(LibrarySaveItemsRequest request, CancellationToken cancel = default)
183+
{
184+
Ensure.ArgumentNotNull(request, nameof(request));
185+
186+
var statusCode = await API.Put(SpotifyUrls.Library(), null, request.BuildBodyParams(), cancel).ConfigureAwait(false);
187+
return HTTPUtil.StatusCodeIsSuccess(statusCode);
188+
}
189+
190+
public async Task<bool> RemoveItems(LibraryRemoveItemsRequest request, CancellationToken cancel = default)
191+
{
192+
Ensure.ArgumentNotNull(request, nameof(request));
193+
194+
var statusCode = await API.Delete(SpotifyUrls.Library(), null, request.BuildBodyParams(), cancel).ConfigureAwait(false);
195+
return HTTPUtil.StatusCodeIsSuccess(statusCode);
196+
}
197+
198+
public Task<List<bool>> CheckItems(LibraryCheckItemsRequest request, CancellationToken cancel = default)
199+
{
200+
Ensure.ArgumentNotNull(request, nameof(request));
201+
202+
return API.Get<List<bool>>(SpotifyUrls.LibraryContains(), request.BuildQueryParams(), cancel);
203+
}
181204
}
182205
}

‎SpotifyAPI.Web/Clients/PlaylistsClient.cs‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,44 @@ public Task<SnapshotResponse> ReorderItems(string playlistId, PlaylistReorderIte
132132

133133
return API.Put<SnapshotResponse>(URLs.PlaylistTracks(playlistId), null, request.BuildBodyParams(), cancel);
134134
}
135+
136+
public Task<SnapshotResponse> AddPlaylistItems(string playlistId, PlaylistAddItemsRequest request, CancellationToken cancel = default)
137+
{
138+
Ensure.ArgumentNotNullOrEmptyString(playlistId, nameof(playlistId));
139+
Ensure.ArgumentNotNull(request, nameof(request));
140+
141+
return API.Post<SnapshotResponse>(URLs.PlaylistItems(playlistId), null, request.BuildBodyParams(), cancel);
142+
}
143+
144+
public Task<Paging<PlaylistTrack<IPlayableItem>>> GetPlaylistItems(string playlistId, CancellationToken cancel = default)
145+
{
146+
var request = new PlaylistGetItemsRequest();
147+
148+
return GetPlaylistItems(playlistId, request, cancel);
149+
}
150+
151+
public Task<Paging<PlaylistTrack<IPlayableItem>>> GetPlaylistItems(string playlistId, PlaylistGetItemsRequest request, CancellationToken cancel = default)
152+
{
153+
Ensure.ArgumentNotNullOrEmptyString(playlistId, nameof(playlistId));
154+
Ensure.ArgumentNotNull(request, nameof(request));
155+
156+
return API.Get<Paging<PlaylistTrack<IPlayableItem>>>(URLs.PlaylistItems(playlistId), request.BuildQueryParams(), cancel);
157+
}
158+
159+
public Task<SnapshotResponse> RemovePlaylistItems(string playlistId, PlaylistRemoveItemsRequest request, CancellationToken cancel = default)
160+
{
161+
Ensure.ArgumentNotNullOrEmptyString(playlistId, nameof(playlistId));
162+
Ensure.ArgumentNotNull(request, nameof(request));
163+
164+
return API.Delete<SnapshotResponse>(URLs.PlaylistItems(playlistId), null, request.BuildBodyParams(), cancel);
165+
}
166+
167+
public Task<SnapshotResponse> UpdatePlaylistItems(string playlistId, PlaylistReorderItemsRequest request, CancellationToken cancel = default)
168+
{
169+
Ensure.ArgumentNotNullOrEmptyString(playlistId, nameof(playlistId));
170+
Ensure.ArgumentNotNull(request, nameof(request));
171+
172+
return API.Put<SnapshotResponse>(URLs.PlaylistItems(playlistId), null, request.BuildBodyParams(), cancel);
173+
}
135174
}
136175
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Collections.Generic;
2+
3+
namespace SpotifyAPI.Web
4+
{
5+
public class LibraryCheckItemsRequest : RequestParams
6+
{
7+
/// <summary>
8+
/// </summary>
9+
/// <param name="uris">
10+
/// A list of Spotify URIs to check in the user's library. Maximum: 50 URIs.
11+
/// </param>
12+
public LibraryCheckItemsRequest(IList<string> uris)
13+
{
14+
Ensure.ArgumentNotNullOrEmptyList(uris, nameof(uris));
15+
16+
Uris = uris;
17+
}
18+
19+
/// <summary>
20+
/// A list of Spotify URIs to check in the user's library. Maximum: 50 URIs.
21+
/// </summary>
22+
/// <value></value>
23+
[QueryParam("uris")]
24+
public IList<string> Uris { get; }
25+
}
26+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Collections.Generic;
2+
3+
namespace SpotifyAPI.Web
4+
{
5+
public class LibraryRemoveItemsRequest : RequestParams
6+
{
7+
/// <summary>
8+
/// </summary>
9+
/// <param name="uris">
10+
/// A list of Spotify URIs to remove from the user's library.
11+
/// For example: uris=spotify:track:4iV5W9uYEdYUVa79Axb7Rh. Maximum: 50 URIs.
12+
/// </param>
13+
public LibraryRemoveItemsRequest(IList<string> uris)
14+
{
15+
Ensure.ArgumentNotNullOrEmptyList(uris, nameof(uris));
16+
17+
Uris = uris;
18+
}
19+
20+
/// <summary>
21+
/// A list of Spotify URIs to remove from the user's library. Maximum: 50 URIs.
22+
/// </summary>
23+
/// <value></value>
24+
[BodyParam("uris")]
25+
public IList<string> Uris { get; }
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Collections.Generic;
2+
3+
namespace SpotifyAPI.Web
4+
{
5+
public class LibrarySaveItemsRequest : RequestParams
6+
{
7+
/// <summary>
8+
/// </summary>
9+
/// <param name="uris">
10+
/// A list of Spotify URIs to save to the user's library.
11+
/// For example: uris=spotify:track:4iV5W9uYEdYUVa79Axb7Rh. Maximum: 50 URIs.
12+
/// </param>
13+
public LibrarySaveItemsRequest(IList<string> uris)
14+
{
15+
Ensure.ArgumentNotNullOrEmptyList(uris, nameof(uris));
16+
17+
Uris = uris;
18+
}
19+
20+
/// <summary>
21+
/// A list of Spotify URIs to save to the user's library. Maximum: 50 URIs.
22+
/// </summary>
23+
/// <value></value>
24+
[BodyParam("uris")]
25+
public IList<string> Uris { get; }
26+
}
27+
}

‎SpotifyAPI.Web/Models/Request/SearchRequest.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ public SearchRequest(Types type, string query)
7272

7373
/// <summary>
7474
/// Maximum number of results to return.
75-
/// Default: 20
75+
/// Default: 5
7676
/// Minimum: 1
77-
/// Maximum: 50
77+
/// Maximum: 10
7878
/// Note: The limit is applied within each type, not on the total response.
7979
/// For example, if the limit value is 3 and the type is artist,album,
8080
/// the response contains 3 artists and 3 albums.

‎SpotifyAPI.Web/Models/Response/FullPlaylist.cs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,20 @@ public class FullPlaylist
1717

1818
/// <summary>
1919
/// A list of PlaylistTracks, which items can be a FullTrack or FullEpisode
20+
///
21+
/// Used for older API responses
2022
/// </summary>
2123
/// <value></value>
2224
public Paging<PlaylistTrack<IPlayableItem>>? Tracks { get; set; } = default!;
25+
26+
/// <summary>
27+
/// A list of PlaylistTracks, which items can be a FullTrack or FullEpisode
28+
///
29+
/// Used for new API responses
30+
/// </summary>
31+
/// <value></value>
32+
public Paging<PlaylistTrack<IPlayableItem>>? Items { get; set; } = default!;
33+
2334
public string? Type { get; set; } = default!;
2435
public string? Uri { get; set; } = default!;
2536
}

‎SpotifyAPI.Web/Models/Response/PlaylistTrack.cs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ public class PlaylistTrack<T>
1111

1212
[JsonConverter(typeof(PlayableItemConverter))]
1313
public T Track { get; set; } = default!;
14+
15+
[JsonConverter(typeof(PlayableItemConverter))]
16+
public T Item { get; set; } = default!;
1417
}
1518
}
1619

0 commit comments

Comments
 (0)