11using System ;
22using System . Collections . Generic ;
3- using System . Threading ;
43using System . Threading . Tasks ;
54using SpotifyAPI . Web . Http ;
65using System . Runtime . CompilerServices ;
6+ using System . Threading ;
77
88namespace SpotifyAPI . Web
99{
@@ -29,14 +29,7 @@ public SpotifyClient(SpotifyClientConfig config)
2929#pragma warning restore CA2208
3030 }
3131
32- _apiConnector = new APIConnector (
33- config . BaseAddress ,
34- config . Authenticator ,
35- config . JSONSerializer ,
36- config . HTTPClient ,
37- config . RetryHandler ,
38- config . HTTPLogger
39- ) ;
32+ _apiConnector = config . BuildAPIConnector ( ) ;
4033 _apiConnector . ResponseReceived += ( sender , response ) =>
4134 {
4235 LastResponse = response ;
@@ -124,6 +117,79 @@ public Task<IList<T>> PaginateAll<T, TNext>(
124117 return ( paginator ?? DefaultPaginator ) . PaginateAll ( firstPage , mapper , _apiConnector ) ;
125118 }
126119
120+ private Task < T > FetchPage < T > ( string ? nextUrl )
121+ {
122+ if ( nextUrl == null )
123+ {
124+ throw new APIPagingException ( "The paging object has no next page" ) ;
125+ }
126+
127+ return _apiConnector . Get < T > ( new Uri ( nextUrl , UriKind . Absolute ) ) ;
128+ }
129+
130+ /// <summary>
131+ /// Fetches the next page of the paging object
132+ /// </summary>
133+ /// <param name="paging">A paging object which has a next page</param>
134+ /// <typeparam name="T"></typeparam>
135+ /// <returns></returns>
136+ public Task < Paging < T > > NextPage < T > ( Paging < T > paging )
137+ {
138+ Ensure . ArgumentNotNull ( paging , nameof ( paging ) ) ;
139+ return FetchPage < Paging < T > > ( paging . Next ) ;
140+ }
141+
142+ /// <summary>
143+ /// Fetches the next page of the cursor paging object
144+ /// </summary>
145+ /// <param name="cursorPaging">A cursor paging object which has a next page</param>
146+ /// <typeparam name="T"></typeparam>
147+ /// <returns></returns>
148+ public Task < CursorPaging < T > > NextPage < T > ( CursorPaging < T > cursorPaging )
149+ {
150+ Ensure . ArgumentNotNull ( cursorPaging , nameof ( cursorPaging ) ) ;
151+ return FetchPage < CursorPaging < T > > ( cursorPaging . Next ) ;
152+ }
153+
154+ /// <summary>
155+ /// Fetches the next page of the complex IPaginatable object.
156+ /// </summary>
157+ /// <param name="paginatable">A complex IPaginatable object with a next page</param>
158+ /// <typeparam name="T"></typeparam>
159+ /// <typeparam name="TNext">The type of the next page</typeparam>
160+ /// <returns></returns>
161+ public Task < TNext > NextPage < T , TNext > ( IPaginatable < T , TNext > paginatable )
162+ {
163+ Ensure . ArgumentNotNull ( paginatable , nameof ( paginatable ) ) ;
164+ return FetchPage < TNext > ( paginatable . Next ) ;
165+ }
166+
167+ /// <summary>
168+ /// Fetches the previous page of the paging object.
169+ /// </summary>
170+ /// <param name="paging">A paging object with a previous page</param>
171+ /// <typeparam name="T"></typeparam>
172+ /// <returns></returns>
173+ public Task < Paging < T > > PreviousPage < T > ( Paging < T > paging )
174+ {
175+ Ensure . ArgumentNotNull ( paging , nameof ( paging ) ) ;
176+ return FetchPage < Paging < T > > ( paging . Previous ) ;
177+ }
178+
179+
180+ /// <summary>
181+ /// Fetches the previous page of the complex paging object.
182+ /// </summary>
183+ /// <param name="paging">A complex paging object with a previous page</param>
184+ /// <typeparam name="T"></typeparam>
185+ /// <typeparam name="TNext">The type of the next page</typeparam>
186+ /// <returns></returns>
187+ public Task < TNext > PreviousPage < T , TNext > ( Paging < T , TNext > paging )
188+ {
189+ Ensure . ArgumentNotNull ( paging , nameof ( paging ) ) ;
190+ return FetchPage < TNext > ( paging . Previous ) ;
191+ }
192+
127193#if NETSTANDARD2_1
128194
129195 /// <summary>
0 commit comments