Skip to content

Commit 3235619

Browse files
committed
Added HasNextPage and HasPreviousPage to Paging-Objects.
Renamed Next and Previous to GetNextPage and GetPreviousPage
1 parent 095967f commit 3235619

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

SpotifyAPI/Web/Models/Paging.cs

+10
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,15 @@ public class Paging<T> : BasicModel
2626

2727
[JsonProperty("total")]
2828
public int Total { get; set; }
29+
30+
public bool HasNextPage()
31+
{
32+
return Next != null;
33+
}
34+
35+
public bool HasPreviousPage()
36+
{
37+
return Next != null;
38+
}
2939
}
3040
}

SpotifyAPI/Web/SpotifyWebAPI.cs

+21-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public SpotifyWebAPI()
4040
public void Dispose()
4141
{
4242
WebClient.Dispose();
43-
GC.SuppressFinalize(this); //TODO
43+
GC.SuppressFinalize(this);
4444
}
4545

4646
#region Search
@@ -1450,16 +1450,34 @@ public async Task<FullTrack> GetTrackAsync(String id, String market = "")
14501450

14511451
#region Util
14521452

1453-
public Paging<T> Next<T>(Paging<T> paging)
1453+
public Paging<T> GetNextPage<T>(Paging<T> paging)
14541454
{
1455+
if (!paging.HasNextPage())
1456+
throw new InvalidOperationException("This Paging-Object has no Next-Page");
14551457
return DownloadData<Paging<T>>(paging.Next);
14561458
}
14571459

1458-
public Paging<T> Previous<T>(Paging<T> paging)
1460+
public async Task<Paging<T>> GetNextPageAsync<T>(Paging<T> paging)
14591461
{
1462+
if (!paging.HasNextPage())
1463+
throw new InvalidOperationException("This Paging-Object has no Next-Page");
1464+
return await DownloadDataAsync<Paging<T>>(paging.Next);
1465+
}
1466+
1467+
public Paging<T> GetPreviousPage<T>(Paging<T> paging)
1468+
{
1469+
if (!paging.HasPreviousPage())
1470+
throw new InvalidOperationException("This Paging-Object has no Previous-Page");
14601471
return DownloadData<Paging<T>>(paging.Previous);
14611472
}
14621473

1474+
public async Task<Paging<T>> GetPreviousPageAsync<T>(Paging<T> paging)
1475+
{
1476+
if (!paging.HasPreviousPage())
1477+
throw new InvalidOperationException("This Paging-Object has no Previous-Page");
1478+
return await DownloadDataAsync<Paging<T>>(paging.Previous);
1479+
}
1480+
14631481
public T UploadData<T>(String url, String uploadData, String method = "POST")
14641482
{
14651483
if (!UseAuth)

0 commit comments

Comments
 (0)