Spotify.NET/SpotifyAPI.Web/Clients/SpotifyClient.cs

72 lines
2.0 KiB
C#
Raw Normal View History

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
{
private readonly IAPIConnector _apiConnector;
2020-05-01 19:05:28 +01:00
public SpotifyClient(string token, string tokenType = "Bearer") :
this(SpotifyClientConfig.CreateDefault(token, tokenType))
2020-05-01 19:05:28 +01:00
{ }
public SpotifyClient(SpotifyClientConfig config)
2020-05-01 19:05:28 +01:00
{
Ensure.ArgumentNotNull(config, nameof(config));
2020-05-01 19:05:28 +01:00
_apiConnector = config.CreateAPIConnector();
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);
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
}
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; }
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; }
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
}
}