2020-05-05 04:26:37 +01:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2022-11-27 12:29:35 +00:00
|
|
|
using System.Threading;
|
2020-05-05 04:26:37 +01:00
|
|
|
using System.Threading.Tasks;
|
2020-06-13 11:55:48 +01:00
|
|
|
using SpotifyAPI.Web;
|
2022-11-27 12:29:35 +00:00
|
|
|
using SpotifyAPI.Web.Http;
|
2020-05-05 04:26:37 +01:00
|
|
|
|
|
|
|
namespace SpotifyAPI.Web
|
|
|
|
{
|
2020-05-30 22:20:42 +01:00
|
|
|
/// <summary>
|
|
|
|
/// A paginator allows to cycle through all resources of the spotify API
|
|
|
|
/// </summary>
|
2020-05-05 04:26:37 +01:00
|
|
|
public interface IPaginator
|
|
|
|
{
|
2020-05-30 22:20:42 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Fetches all pages and returns them grouped in a list
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="firstPage">The first page. Will be included in the result list!</param>
|
|
|
|
/// <param name="connector">An API Connector to make requests to spotify</param>
|
2022-11-18 11:30:09 +00:00
|
|
|
/// <param name="cancel">The cancellation-token to allow to cancel the request.</param>
|
2020-05-30 22:20:42 +01:00
|
|
|
/// <typeparam name="T">Paging Type</typeparam>
|
|
|
|
/// <returns>A list containing all pages, including the firstPage</returns>
|
2022-11-18 11:30:09 +00:00
|
|
|
Task<IList<T>> PaginateAll<T>(IPaginatable<T> firstPage, IAPIConnector connector, CancellationToken cancel = default);
|
2020-05-30 22:20:42 +01:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Fetches all pages and returns them grouped in a list.
|
|
|
|
/// Supports a mapping method which takes care of JSON mapping problems.
|
|
|
|
/// To give an example, the Search method always returns the paging objects nested in a key. The mapper functions
|
|
|
|
/// tells the paginate function where to find the actual paging object in the response.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="firstPage">The first page. Will be included in the result list!</param>
|
|
|
|
/// <param name="mapper">A function which returns the actual paging object in another response object</param>
|
|
|
|
/// <param name="connector">An API Connector to make requests to spotify</param>
|
2022-11-18 11:30:09 +00:00
|
|
|
/// <param name="cancel">The cancellation-token to allow to cancel the request.</param>
|
2020-05-30 22:20:42 +01:00
|
|
|
/// <typeparam name="T">Paging Type</typeparam>
|
|
|
|
/// <typeparam name="TNext">Outer response Type</typeparam>
|
|
|
|
/// <returns>A list containing all pages, including the firstPage</returns>
|
|
|
|
Task<IList<T>> PaginateAll<T, TNext>(
|
2020-06-13 11:55:48 +01:00
|
|
|
IPaginatable<T, TNext> firstPage,
|
|
|
|
Func<TNext, IPaginatable<T, TNext>> mapper,
|
2022-11-18 11:30:09 +00:00
|
|
|
IAPIConnector connector,
|
|
|
|
CancellationToken cancel = default
|
2020-05-20 19:59:11 +01:00
|
|
|
);
|
2020-05-05 16:52:23 +01:00
|
|
|
|
2020-05-30 22:20:42 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Fetches all pages and returns one by one using IAsyncEnumerable
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="firstPage">The first page. Will be included in the result list!</param>
|
|
|
|
/// <param name="connector">An API Connector to make requests to spotify</param>
|
2022-11-18 11:30:09 +00:00
|
|
|
/// <param name="cancel">A cancel</param>
|
2020-05-30 22:20:42 +01:00
|
|
|
/// <typeparam name="T">Paging Type</typeparam>
|
|
|
|
/// <returns></returns>
|
2020-06-13 11:55:48 +01:00
|
|
|
IAsyncEnumerable<T> Paginate<T>(IPaginatable<T> firstPage, IAPIConnector connector, CancellationToken cancel = default);
|
2020-05-30 22:20:42 +01:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Fetches all pages and returns them grouped in a list.
|
|
|
|
/// Supports a mapping method which takes care of JSON mapping problems.
|
|
|
|
/// To give an example, the Search method always returns the paging objects nested in a key. The mapper functions
|
|
|
|
/// tells the paginate function where to find the actual paging object in the response.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="firstPage">The first page. Will be included in the result list!</param>
|
|
|
|
/// <param name="mapper">A function which returns the actual paging object in another response object</param>
|
|
|
|
/// <param name="connector">An API Connector to make requests to spotify</param>
|
2022-11-18 11:30:09 +00:00
|
|
|
/// <param name="cancel">A cancel</param>
|
2020-05-30 22:20:42 +01:00
|
|
|
/// <typeparam name="T">Paging Type</typeparam>
|
|
|
|
/// <typeparam name="TNext">Outer response Type</typeparam>
|
|
|
|
/// <returns></returns>
|
2020-05-20 19:59:11 +01:00
|
|
|
IAsyncEnumerable<T> Paginate<T, TNext>(
|
2020-06-13 11:55:48 +01:00
|
|
|
IPaginatable<T, TNext> firstPage,
|
|
|
|
Func<TNext, IPaginatable<T, TNext>> mapper,
|
2020-05-20 19:59:11 +01:00
|
|
|
IAPIConnector connector,
|
|
|
|
CancellationToken cancel = default
|
|
|
|
);
|
2020-05-05 04:26:37 +01:00
|
|
|
}
|
|
|
|
}
|