Skip to content

Commit 67427cd

Browse files
committed
Added overload for NextPage stuff CursorPaging
1 parent 4cfda50 commit 67427cd

File tree

2 files changed

+48
-19
lines changed

2 files changed

+48
-19
lines changed

SpotifyAPI.Web/Models/CursorPaging.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,10 @@ public class CursorPaging<T> : BasicModel
2222

2323
[JsonProperty("total")]
2424
public int Total { get; set; }
25+
26+
public bool HasNext()
27+
{
28+
return !string.IsNullOrEmpty(Next);
29+
}
2530
}
26-
}
31+
}

SpotifyAPI.Web/SpotifyWebAPI.cs

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public Task<SearchItem> SearchItemsAsync(string q, SearchType type, int limit =
120120
{
121121
return DownloadDataAsync<SearchItem>(_builder.SearchItems(q, type, limit, offset, market));
122122
}
123-
123+
124124
/// <summary>
125125
/// Get Spotify catalog information about artists, albums, tracks or playlists that match a keyword string.
126126
/// </summary>
@@ -542,7 +542,7 @@ public Task<CategoryPlaylist> GetCategoryPlaylistsAsync(string categoryId, strin
542542
/// <summary>
543543
/// Create a playlist-style listening experience based on seed artists, tracks and genres.
544544
/// </summary>
545-
/// <param name="artistSeed">A comma separated list of Spotify IDs for seed artists.
545+
/// <param name="artistSeed">A comma separated list of Spotify IDs for seed artists.
546546
/// Up to 5 seed values may be provided in any combination of seed_artists, seed_tracks and seed_genres.
547547
/// </param>
548548
/// <param name="genreSeed">A comma separated list of any genres in the set of available genre seeds.
@@ -570,7 +570,7 @@ public Recommendations GetRecommendations(List<string> artistSeed = null, List<s
570570
/// <summary>
571571
/// Create a playlist-style listening experience based on seed artists, tracks and genres asynchronously.
572572
/// </summary>
573-
/// <param name="artistSeed">A comma separated list of Spotify IDs for seed artists.
573+
/// <param name="artistSeed">A comma separated list of Spotify IDs for seed artists.
574574
/// Up to 5 seed values may be provided in any combination of seed_artists, seed_tracks and seed_genres.
575575
/// </param>
576576
/// <param name="genreSeed">A comma separated list of any genres in the set of available genre seeds.
@@ -1219,8 +1219,8 @@ public Task<ListResponse<bool>> CheckSavedAlbumsAsync(List<string> ids)
12191219
/// <summary>
12201220
/// Get the current user’s top tracks based on calculated affinity.
12211221
/// </summary>
1222-
/// <param name="timeRange">Over what time frame the affinities are computed.
1223-
/// Valid values: long_term (calculated from several years of data and including all new data as it becomes available),
1222+
/// <param name="timeRange">Over what time frame the affinities are computed.
1223+
/// Valid values: long_term (calculated from several years of data and including all new data as it becomes available),
12241224
/// medium_term (approximately last 6 months), short_term (approximately last 4 weeks). </param>
12251225
/// <param name="limit">The number of entities to return. Default: 20. Minimum: 1. Maximum: 50</param>
12261226
/// <param name="offest">The index of the first entity to return. Default: 0 (i.e., the first track). Use with limit to get the next set of entities.</param>
@@ -1234,8 +1234,8 @@ public Paging<FullTrack> GetUsersTopTracks(TimeRangeType timeRange = TimeRangeTy
12341234
/// <summary>
12351235
/// Get the current user’s top tracks based on calculated affinity asynchronously.
12361236
/// </summary>
1237-
/// <param name="timeRange">Over what time frame the affinities are computed.
1238-
/// Valid values: long_term (calculated from several years of data and including all new data as it becomes available),
1237+
/// <param name="timeRange">Over what time frame the affinities are computed.
1238+
/// Valid values: long_term (calculated from several years of data and including all new data as it becomes available),
12391239
/// medium_term (approximately last 6 months), short_term (approximately last 4 weeks). </param>
12401240
/// <param name="limit">The number of entities to return. Default: 20. Minimum: 1. Maximum: 50</param>
12411241
/// <param name="offest">The index of the first entity to return. Default: 0 (i.e., the first track). Use with limit to get the next set of entities.</param>
@@ -1249,8 +1249,8 @@ public Task<Paging<FullTrack>> GetUsersTopTracksAsync(TimeRangeType timeRange =
12491249
/// <summary>
12501250
/// Get the current user’s top artists based on calculated affinity.
12511251
/// </summary>
1252-
/// <param name="timeRange">Over what time frame the affinities are computed.
1253-
/// Valid values: long_term (calculated from several years of data and including all new data as it becomes available),
1252+
/// <param name="timeRange">Over what time frame the affinities are computed.
1253+
/// Valid values: long_term (calculated from several years of data and including all new data as it becomes available),
12541254
/// medium_term (approximately last 6 months), short_term (approximately last 4 weeks). </param>
12551255
/// <param name="limit">The number of entities to return. Default: 20. Minimum: 1. Maximum: 50</param>
12561256
/// <param name="offest">The index of the first entity to return. Default: 0 (i.e., the first track). Use with limit to get the next set of entities.</param>
@@ -1264,8 +1264,8 @@ public Paging<FullArtist> GetUsersTopArtists(TimeRangeType timeRange = TimeRange
12641264
/// <summary>
12651265
/// Get the current user’s top artists based on calculated affinity asynchronously.
12661266
/// </summary>
1267-
/// <param name="timeRange">Over what time frame the affinities are computed.
1268-
/// Valid values: long_term (calculated from several years of data and including all new data as it becomes available),
1267+
/// <param name="timeRange">Over what time frame the affinities are computed.
1268+
/// Valid values: long_term (calculated from several years of data and including all new data as it becomes available),
12691269
/// medium_term (approximately last 6 months), short_term (approximately last 4 weeks). </param>
12701270
/// <param name="limit">The number of entities to return. Default: 20. Minimum: 1. Maximum: 50</param>
12711271
/// <param name="offest">The index of the first entity to return. Default: 0 (i.e., the first track). Use with limit to get the next set of entities.</param>
@@ -1634,7 +1634,7 @@ public async Task<ErrorResponse> UpdatePlaylistAsync(string userId, string playl
16341634
body.Add("description", newDescription);
16351635
return await UploadDataAsync<ErrorResponse>(_builder.UpdatePlaylist(userId, playlistId), body.ToString(Formatting.None), "PUT").ConfigureAwait(false) ?? new ErrorResponse();
16361636
}
1637-
1637+
16381638
/// <summary>
16391639
/// Change a playlist’s name and public/private state asynchronously. (The user must, of course, own the playlist.)
16401640
/// </summary>
@@ -2390,7 +2390,7 @@ public Task<ErrorResponse> TransferPlaybackAsync(string deviceId, bool play = fa
23902390
new List<string> { deviceId }, play);
23912391

23922392
/// <summary>
2393-
/// Transfer playback to a new device and determine if it should start playing.
2393+
/// Transfer playback to a new device and determine if it should start playing.
23942394
/// NOTE: Although an array is accepted, only a single device_id is currently supported. Supplying more than one will return 400 Bad Request
23952395
/// </summary>
23962396
/// <param name="deviceIds">A array containing the ID of the device on which playback should be started/transferred.</param>
@@ -2410,7 +2410,7 @@ public ErrorResponse TransferPlayback(List<string> deviceIds, bool play = false)
24102410
}
24112411

24122412
/// <summary>
2413-
/// Transfer playback to a new device and determine if it should start playing.
2413+
/// Transfer playback to a new device and determine if it should start playing.
24142414
/// NOTE: Although an array is accepted, only a single device_id is currently supported. Supplying more than one will return 400 Bad Request
24152415
/// </summary>
24162416
/// <param name="deviceIds">A array containing the ID of the device on which playback should be started/transferred.</param>
@@ -2596,7 +2596,7 @@ public Task<ErrorResponse> SkipPlaybackToPreviousAsync(string deviceId = "")
25962596
/// <summary>
25972597
/// Seeks to the given position in the user’s currently playing track.
25982598
/// </summary>
2599-
/// <param name="positionMs">The position in milliseconds to seek to. Must be a positive number.
2599+
/// <param name="positionMs">The position in milliseconds to seek to. Must be a positive number.
26002600
/// Passing in a position that is greater than the length of the track will cause the player to start playing the next song.</param>
26012601
/// <param name="deviceId">The id of the device this command is targeting. If not supplied, the user's currently active device is the target.</param>
26022602
/// <returns></returns>
@@ -2608,7 +2608,7 @@ public ErrorResponse SeekPlayback(int positionMs, string deviceId = "")
26082608
/// <summary>
26092609
/// Seeks to the given position in the user’s currently playing track.
26102610
/// </summary>
2611-
/// <param name="positionMs">The position in milliseconds to seek to. Must be a positive number.
2611+
/// <param name="positionMs">The position in milliseconds to seek to. Must be a positive number.
26122612
/// Passing in a position that is greater than the length of the track will cause the player to start playing the next song.</param>
26132613
/// <param name="deviceId">The id of the device this command is targeting. If not supplied, the user's currently active device is the target.</param>
26142614
/// <returns></returns>
@@ -2694,23 +2694,47 @@ public TOut GetNextPage<TOut, TIn>(Paging<TIn> paging) where TOut : BasicModel
26942694
return DownloadData<TOut>(paging.Next);
26952695
}
26962696

2697+
public TOut GetNextPage<TOut, TIn>(CursorPaging<TIn> paging) where TOut : BasicModel
2698+
{
2699+
if (!paging.HasNext())
2700+
throw new InvalidOperationException("This CursorPaging-Object has no Next-Page");
2701+
return DownloadData<TOut>(paging.Next);
2702+
}
2703+
26972704
public Paging<T> GetNextPage<T>(Paging<T> paging)
26982705
{
26992706
return GetNextPage<Paging<T>, T>(paging);
27002707
}
27012708

2709+
public CursorPaging<T> GetNextPage<T>(CursorPaging<T> paging)
2710+
{
2711+
return GetNextPage<CursorPaging<T>, T>(paging);
2712+
}
2713+
27022714
public Task<TOut> GetNextPageAsync<TOut, TIn>(Paging<TIn> paging) where TOut : BasicModel
27032715
{
27042716
if (!paging.HasNextPage())
27052717
throw new InvalidOperationException("This Paging-Object has no Next-Page");
27062718
return DownloadDataAsync<TOut>(paging.Next);
27072719
}
27082720

2721+
public Task<TOut> GetNextPageAsync<TOut, TIn>(CursorPaging<TIn> paging) where TOut : BasicModel
2722+
{
2723+
if (!paging.HasNext())
2724+
throw new InvalidOperationException("This Paging-Object has no Next-Page");
2725+
return DownloadDataAsync<TOut>(paging.Next);
2726+
}
2727+
27092728
public Task<Paging<T>> GetNextPageAsync<T>(Paging<T> paging)
27102729
{
27112730
return GetNextPageAsync<Paging<T>, T>(paging);
27122731
}
27132732

2733+
public Task<CursorPaging<T>> GetNextPageAsync<T>(CursorPaging<T> paging)
2734+
{
2735+
return GetNextPageAsync<CursorPaging<T>, T>(paging);
2736+
}
2737+
27142738
public TOut GetPreviousPage<TOut, TIn>(Paging<TIn> paging) where TOut : BasicModel
27152739
{
27162740
if (!paging.HasPreviousPage())
@@ -2789,7 +2813,7 @@ private static ListResponse<T> ExtractDataToListResponse<T>(Tuple<ResponseInfo,
27892813
};
27902814
}
27912815
else
2792-
{
2816+
{
27932817
ret = new ListResponse<T>
27942818
{
27952819
List = null,
@@ -2889,7 +2913,7 @@ public T DownloadData<T>(string url) where T : BasicModel
28892913
private int GetTooManyRequests(ResponseInfo info)
28902914
{
28912915
// 429 is "TooManyRequests" value specified in Spotify API
2892-
if (429 != (int)info.StatusCode)
2916+
if (429 != (int)info.StatusCode)
28932917
{
28942918
return -1;
28952919
}

0 commit comments

Comments
 (0)