2020-05-05 04:26:37 +01:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Threading.Tasks;
|
2020-05-01 19:05:28 +01:00
|
|
|
using SpotifyAPI.Web.Http;
|
|
|
|
|
|
|
|
namespace SpotifyAPI.Web
|
|
|
|
{
|
|
|
|
public class SpotifyClient : ISpotifyClient
|
|
|
|
{
|
2020-05-02 12:04:26 +01:00
|
|
|
private readonly IAPIConnector _apiConnector;
|
2020-05-01 19:05:28 +01:00
|
|
|
|
|
|
|
public SpotifyClient(string token, string tokenType = "Bearer") :
|
2020-05-02 12:04:26 +01:00
|
|
|
this(SpotifyClientConfig.CreateDefault(token, tokenType))
|
2020-05-01 19:05:28 +01:00
|
|
|
{ }
|
|
|
|
|
2020-05-02 12:04:26 +01:00
|
|
|
public SpotifyClient(SpotifyClientConfig config)
|
2020-05-01 19:05:28 +01:00
|
|
|
{
|
2020-05-02 12:04:26 +01:00
|
|
|
Ensure.ArgumentNotNull(config, nameof(config));
|
2020-05-01 19:05:28 +01:00
|
|
|
|
2020-05-02 12:04:26 +01:00
|
|
|
_apiConnector = config.CreateAPIConnector();
|
2020-05-05 04:26:37 +01:00
|
|
|
DefaultPaginator = config.Paginator;
|
2020-05-01 19:05:28 +01:00
|
|
|
UserProfile = new UserProfileClient(_apiConnector);
|
|
|
|
Browse = new BrowseClient(_apiConnector);
|
2020-05-02 21:48:21 +01:00
|
|
|
Shows = new ShowsClient(_apiConnector);
|
|
|
|
Playlists = new PlaylistsClient(_apiConnector);
|
2020-05-03 21:34:03 +01:00
|
|
|
Search = new SearchClient(_apiConnector);
|
2020-05-04 22:02:53 +01:00
|
|
|
Follow = new FollowClient(_apiConnector);
|
2020-05-04 22:04:59 +01:00
|
|
|
Tracks = new TracksClient(_apiConnector);
|
2020-05-01 19:05:28 +01:00
|
|
|
}
|
|
|
|
|
2020-05-05 04:26:37 +01:00
|
|
|
public IPaginator DefaultPaginator { get; }
|
|
|
|
|
2020-05-01 19:05:28 +01:00
|
|
|
public IUserProfileClient UserProfile { get; }
|
|
|
|
|
|
|
|
public IBrowseClient Browse { get; }
|
2020-05-02 21:48:21 +01:00
|
|
|
|
|
|
|
public IShowsClient Shows { get; }
|
|
|
|
|
|
|
|
public IPlaylistsClient Playlists { get; }
|
2020-05-03 21:34:03 +01:00
|
|
|
|
|
|
|
public ISearchClient Search { get; }
|
2020-05-04 22:02:53 +01:00
|
|
|
|
|
|
|
public IFollowClient Follow { get; }
|
2020-05-04 22:04:59 +01:00
|
|
|
|
|
|
|
public ITracksClient Tracks { get; }
|
2020-05-05 04:26:37 +01:00
|
|
|
|
|
|
|
public Task<List<T>> Paginate<T>(Paging<T> firstPage)
|
|
|
|
{
|
|
|
|
return DefaultPaginator.Paginate(firstPage, _apiConnector);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Task<List<T>> Paginate<T>(Paging<T> firstPage, IPaginator paginator)
|
|
|
|
{
|
|
|
|
Ensure.ArgumentNotNull(paginator, nameof(paginator));
|
|
|
|
|
|
|
|
return paginator.Paginate(firstPage, _apiConnector);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Task<List<T>> Paginate<T>(Func<Task<Paging<T>>> getFirstPage)
|
|
|
|
{
|
|
|
|
return DefaultPaginator.Paginate(getFirstPage, _apiConnector);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Task<List<T>> Paginate<T>(Func<Task<Paging<T>>> getFirstPage, IPaginator paginator)
|
|
|
|
{
|
|
|
|
Ensure.ArgumentNotNull(paginator, nameof(paginator));
|
|
|
|
|
|
|
|
return paginator.Paginate(getFirstPage, _apiConnector);
|
|
|
|
}
|
2020-05-01 19:05:28 +01:00
|
|
|
}
|
|
|
|
}
|