From 67427cdb729b469c6db5f914aa4438b5c9bfbae1 Mon Sep 17 00:00:00 2001 From: Jonas Dellinger Date: Mon, 20 May 2019 16:57:24 +0200 Subject: [PATCH] Added overload for NextPage stuff CursorPaging --- SpotifyAPI.Web/Models/CursorPaging.cs | 7 +++- SpotifyAPI.Web/SpotifyWebAPI.cs | 60 +++++++++++++++++++-------- 2 files changed, 48 insertions(+), 19 deletions(-) diff --git a/SpotifyAPI.Web/Models/CursorPaging.cs b/SpotifyAPI.Web/Models/CursorPaging.cs index 3496212c4..3499ede27 100644 --- a/SpotifyAPI.Web/Models/CursorPaging.cs +++ b/SpotifyAPI.Web/Models/CursorPaging.cs @@ -22,5 +22,10 @@ public class CursorPaging : BasicModel [JsonProperty("total")] public int Total { get; set; } + + public bool HasNext() + { + return !string.IsNullOrEmpty(Next); + } } -} \ No newline at end of file +} diff --git a/SpotifyAPI.Web/SpotifyWebAPI.cs b/SpotifyAPI.Web/SpotifyWebAPI.cs index 1efe23865..96870ac79 100644 --- a/SpotifyAPI.Web/SpotifyWebAPI.cs +++ b/SpotifyAPI.Web/SpotifyWebAPI.cs @@ -120,7 +120,7 @@ public Task SearchItemsAsync(string q, SearchType type, int limit = { return DownloadDataAsync(_builder.SearchItems(q, type, limit, offset, market)); } - + /// /// Get Spotify catalog information about artists, albums, tracks or playlists that match a keyword string. /// @@ -542,7 +542,7 @@ public Task GetCategoryPlaylistsAsync(string categoryId, strin /// /// Create a playlist-style listening experience based on seed artists, tracks and genres. /// - /// A comma separated list of Spotify IDs for seed artists. + /// A comma separated list of Spotify IDs for seed artists. /// Up to 5 seed values may be provided in any combination of seed_artists, seed_tracks and seed_genres. /// /// A comma separated list of any genres in the set of available genre seeds. @@ -570,7 +570,7 @@ public Recommendations GetRecommendations(List artistSeed = null, List /// Create a playlist-style listening experience based on seed artists, tracks and genres asynchronously. /// - /// A comma separated list of Spotify IDs for seed artists. + /// A comma separated list of Spotify IDs for seed artists. /// Up to 5 seed values may be provided in any combination of seed_artists, seed_tracks and seed_genres. /// /// A comma separated list of any genres in the set of available genre seeds. @@ -1219,8 +1219,8 @@ public Task> CheckSavedAlbumsAsync(List ids) /// /// Get the current user’s top tracks based on calculated affinity. /// - /// Over what time frame the affinities are computed. - /// Valid values: long_term (calculated from several years of data and including all new data as it becomes available), + /// Over what time frame the affinities are computed. + /// Valid values: long_term (calculated from several years of data and including all new data as it becomes available), /// medium_term (approximately last 6 months), short_term (approximately last 4 weeks). /// The number of entities to return. Default: 20. Minimum: 1. Maximum: 50 /// 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. @@ -1234,8 +1234,8 @@ public Paging GetUsersTopTracks(TimeRangeType timeRange = TimeRangeTy /// /// Get the current user’s top tracks based on calculated affinity asynchronously. /// - /// Over what time frame the affinities are computed. - /// Valid values: long_term (calculated from several years of data and including all new data as it becomes available), + /// Over what time frame the affinities are computed. + /// Valid values: long_term (calculated from several years of data and including all new data as it becomes available), /// medium_term (approximately last 6 months), short_term (approximately last 4 weeks). /// The number of entities to return. Default: 20. Minimum: 1. Maximum: 50 /// 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. @@ -1249,8 +1249,8 @@ public Task> GetUsersTopTracksAsync(TimeRangeType timeRange = /// /// Get the current user’s top artists based on calculated affinity. /// - /// Over what time frame the affinities are computed. - /// Valid values: long_term (calculated from several years of data and including all new data as it becomes available), + /// Over what time frame the affinities are computed. + /// Valid values: long_term (calculated from several years of data and including all new data as it becomes available), /// medium_term (approximately last 6 months), short_term (approximately last 4 weeks). /// The number of entities to return. Default: 20. Minimum: 1. Maximum: 50 /// 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. @@ -1264,8 +1264,8 @@ public Paging GetUsersTopArtists(TimeRangeType timeRange = TimeRange /// /// Get the current user’s top artists based on calculated affinity asynchronously. /// - /// Over what time frame the affinities are computed. - /// Valid values: long_term (calculated from several years of data and including all new data as it becomes available), + /// Over what time frame the affinities are computed. + /// Valid values: long_term (calculated from several years of data and including all new data as it becomes available), /// medium_term (approximately last 6 months), short_term (approximately last 4 weeks). /// The number of entities to return. Default: 20. Minimum: 1. Maximum: 50 /// 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. @@ -1634,7 +1634,7 @@ public async Task UpdatePlaylistAsync(string userId, string playl body.Add("description", newDescription); return await UploadDataAsync(_builder.UpdatePlaylist(userId, playlistId), body.ToString(Formatting.None), "PUT").ConfigureAwait(false) ?? new ErrorResponse(); } - + /// /// Change a playlist’s name and public/private state asynchronously. (The user must, of course, own the playlist.) /// @@ -2390,7 +2390,7 @@ public Task TransferPlaybackAsync(string deviceId, bool play = fa new List { deviceId }, play); /// - /// Transfer playback to a new device and determine if it should start playing. + /// Transfer playback to a new device and determine if it should start playing. /// NOTE: Although an array is accepted, only a single device_id is currently supported. Supplying more than one will return 400 Bad Request /// /// A array containing the ID of the device on which playback should be started/transferred. @@ -2410,7 +2410,7 @@ public ErrorResponse TransferPlayback(List deviceIds, bool play = false) } /// - /// Transfer playback to a new device and determine if it should start playing. + /// Transfer playback to a new device and determine if it should start playing. /// NOTE: Although an array is accepted, only a single device_id is currently supported. Supplying more than one will return 400 Bad Request /// /// A array containing the ID of the device on which playback should be started/transferred. @@ -2596,7 +2596,7 @@ public Task SkipPlaybackToPreviousAsync(string deviceId = "") /// /// Seeks to the given position in the user’s currently playing track. /// - /// The position in milliseconds to seek to. Must be a positive number. + /// The position in milliseconds to seek to. Must be a positive number. /// Passing in a position that is greater than the length of the track will cause the player to start playing the next song. /// The id of the device this command is targeting. If not supplied, the user's currently active device is the target. /// @@ -2608,7 +2608,7 @@ public ErrorResponse SeekPlayback(int positionMs, string deviceId = "") /// /// Seeks to the given position in the user’s currently playing track. /// - /// The position in milliseconds to seek to. Must be a positive number. + /// The position in milliseconds to seek to. Must be a positive number. /// Passing in a position that is greater than the length of the track will cause the player to start playing the next song. /// The id of the device this command is targeting. If not supplied, the user's currently active device is the target. /// @@ -2694,11 +2694,23 @@ public TOut GetNextPage(Paging paging) where TOut : BasicModel return DownloadData(paging.Next); } + public TOut GetNextPage(CursorPaging paging) where TOut : BasicModel + { + if (!paging.HasNext()) + throw new InvalidOperationException("This CursorPaging-Object has no Next-Page"); + return DownloadData(paging.Next); + } + public Paging GetNextPage(Paging paging) { return GetNextPage, T>(paging); } + public CursorPaging GetNextPage(CursorPaging paging) + { + return GetNextPage, T>(paging); + } + public Task GetNextPageAsync(Paging paging) where TOut : BasicModel { if (!paging.HasNextPage()) @@ -2706,11 +2718,23 @@ public Task GetNextPageAsync(Paging paging) where TOut : B return DownloadDataAsync(paging.Next); } + public Task GetNextPageAsync(CursorPaging paging) where TOut : BasicModel + { + if (!paging.HasNext()) + throw new InvalidOperationException("This Paging-Object has no Next-Page"); + return DownloadDataAsync(paging.Next); + } + public Task> GetNextPageAsync(Paging paging) { return GetNextPageAsync, T>(paging); } + public Task> GetNextPageAsync(CursorPaging paging) + { + return GetNextPageAsync, T>(paging); + } + public TOut GetPreviousPage(Paging paging) where TOut : BasicModel { if (!paging.HasPreviousPage()) @@ -2789,7 +2813,7 @@ private static ListResponse ExtractDataToListResponse(Tuple { List = null, @@ -2889,7 +2913,7 @@ public T DownloadData(string url) where T : BasicModel private int GetTooManyRequests(ResponseInfo info) { // 429 is "TooManyRequests" value specified in Spotify API - if (429 != (int)info.StatusCode) + if (429 != (int)info.StatusCode) { return -1; }