From 323561909e0cbcc241eed992295135bff3f89661 Mon Sep 17 00:00:00 2001 From: "Johnny @PC" Date: Sat, 7 Nov 2015 20:18:39 +0100 Subject: [PATCH] Added HasNextPage and HasPreviousPage to Paging-Objects. Renamed Next and Previous to GetNextPage and GetPreviousPage --- SpotifyAPI/Web/Models/Paging.cs | 10 ++++++++++ SpotifyAPI/Web/SpotifyWebAPI.cs | 24 +++++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/SpotifyAPI/Web/Models/Paging.cs b/SpotifyAPI/Web/Models/Paging.cs index d40a426e..6c37b323 100644 --- a/SpotifyAPI/Web/Models/Paging.cs +++ b/SpotifyAPI/Web/Models/Paging.cs @@ -26,5 +26,15 @@ namespace SpotifyAPI.Web.Models [JsonProperty("total")] public int Total { get; set; } + + public bool HasNextPage() + { + return Next != null; + } + + public bool HasPreviousPage() + { + return Next != null; + } } } \ No newline at end of file diff --git a/SpotifyAPI/Web/SpotifyWebAPI.cs b/SpotifyAPI/Web/SpotifyWebAPI.cs index 56dcc025..77dc8fa4 100644 --- a/SpotifyAPI/Web/SpotifyWebAPI.cs +++ b/SpotifyAPI/Web/SpotifyWebAPI.cs @@ -40,7 +40,7 @@ namespace SpotifyAPI.Web public void Dispose() { WebClient.Dispose(); - GC.SuppressFinalize(this); //TODO + GC.SuppressFinalize(this); } #region Search @@ -1450,16 +1450,34 @@ namespace SpotifyAPI.Web #region Util - public Paging Next(Paging paging) + public Paging GetNextPage(Paging paging) { + if (!paging.HasNextPage()) + throw new InvalidOperationException("This Paging-Object has no Next-Page"); return DownloadData>(paging.Next); } - public Paging Previous(Paging paging) + public async Task> GetNextPageAsync(Paging paging) { + if (!paging.HasNextPage()) + throw new InvalidOperationException("This Paging-Object has no Next-Page"); + return await DownloadDataAsync>(paging.Next); + } + + public Paging GetPreviousPage(Paging paging) + { + if (!paging.HasPreviousPage()) + throw new InvalidOperationException("This Paging-Object has no Previous-Page"); return DownloadData>(paging.Previous); } + public async Task> GetPreviousPageAsync(Paging paging) + { + if (!paging.HasPreviousPage()) + throw new InvalidOperationException("This Paging-Object has no Previous-Page"); + return await DownloadDataAsync>(paging.Previous); + } + public T UploadData(String url, String uploadData, String method = "POST") { if (!UseAuth)