Added Albums Client #451

This commit is contained in:
Jonas Dellinger 2020-05-07 22:33:29 +02:00
parent 249a535e07
commit a82f95f0d0
10 changed files with 155 additions and 0 deletions

View File

@ -0,0 +1,48 @@
using System.Threading.Tasks;
using SpotifyAPI.Web.Http;
using URLs = SpotifyAPI.Web.SpotifyUrls;
namespace SpotifyAPI.Web
{
public class AlbumsClient : APIClient, IAlbumsClient
{
public AlbumsClient(IAPIConnector apiConnector) : base(apiConnector) { }
public Task<FullAlbum> Get(string albumId)
{
Ensure.ArgumentNotNullOrEmptyString(albumId, nameof(albumId));
return API.Get<FullAlbum>(URLs.Album(albumId));
}
public Task<FullAlbum> Get(string albumId, AlbumRequest request)
{
Ensure.ArgumentNotNullOrEmptyString(albumId, nameof(albumId));
Ensure.ArgumentNotNull(request, nameof(request));
return API.Get<FullAlbum>(URLs.Album(albumId), request.BuildQueryParams());
}
public Task<AlbumsResponse> GetSeveral(AlbumsRequest request)
{
Ensure.ArgumentNotNull(request, nameof(request));
return API.Get<AlbumsResponse>(URLs.Albums(), request.BuildQueryParams());
}
public Task<Paging<SimpleTrack>> GetTracks(string albumId)
{
Ensure.ArgumentNotNullOrEmptyString(albumId, nameof(albumId));
return API.Get<Paging<SimpleTrack>>(URLs.AlbumTracks(albumId));
}
public Task<Paging<SimpleTrack>> GetTracks(string albumId, AlbumTracksRequest request)
{
Ensure.ArgumentNotNullOrEmptyString(albumId, nameof(albumId));
Ensure.ArgumentNotNull(request, nameof(request));
return API.Get<Paging<SimpleTrack>>(URLs.AlbumTracks(albumId), request.BuildQueryParams());
}
}
}

View File

@ -0,0 +1,18 @@
using System.Threading.Tasks;
namespace SpotifyAPI.Web
{
public interface IAlbumsClient
{
Task<AlbumsResponse> GetSeveral(AlbumsRequest request);
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716")]
Task<FullAlbum> Get(string albumId);
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716")]
Task<FullAlbum> Get(string albumId, AlbumRequest request);
Task<Paging<SimpleTrack>> GetTracks(string albumId);
Task<Paging<SimpleTrack>> GetTracks(string albumId, AlbumTracksRequest request);
}
}

View File

@ -24,6 +24,8 @@ namespace SpotifyAPI.Web
IPlayerClient Player { get; }
IAlbumsClient Albums { get; }
Task<List<T>> Paginate<T>(Paging<T> firstPage);
Task<List<T>> Paginate<T, TNext>(Paging<T, TNext> firstPage, Func<TNext, Paging<T, TNext>> mapper);
Task<List<T>> Paginate<T>(Func<Task<Paging<T>>> getFirstPage);

View File

@ -27,6 +27,7 @@ namespace SpotifyAPI.Web
Follow = new FollowClient(_apiConnector);
Tracks = new TracksClient(_apiConnector);
Player = new PlayerClient(_apiConnector);
Albums = new AlbumsClient(_apiConnector);
}
public IPaginator DefaultPaginator { get; }
@ -47,6 +48,8 @@ namespace SpotifyAPI.Web
public IPlayerClient Player { get; }
public IAlbumsClient Albums { get; }
public Task<List<T>> Paginate<T>(Paging<T> firstPage)
{
return DefaultPaginator.Paginate(firstPage, _apiConnector);

View File

@ -0,0 +1,8 @@
namespace SpotifyAPI.Web
{
public class AlbumRequest : RequestParams
{
[QueryParam("market")]
public string Market { get; set; }
}
}

View File

@ -0,0 +1,14 @@
namespace SpotifyAPI.Web
{
public class AlbumTracksRequest : RequestParams
{
[QueryParam("market")]
public string Market { get; set; }
[QueryParam("limit")]
public int? Limit { get; set; }
[QueryParam("offset")]
public int? Offset { get; set; }
}
}

View File

@ -0,0 +1,20 @@
using System.Collections.Generic;
namespace SpotifyAPI.Web
{
public class AlbumsRequest : RequestParams
{
public AlbumsRequest(IList<string> ids)
{
Ensure.ArgumentNotNullOrEmptyList(ids, nameof(ids));
Ids = ids;
}
[QueryParam("ids")]
public IList<string> Ids { get; }
[QueryParam("market")]
public string Market { get; set; }
}
}

View File

@ -0,0 +1,9 @@
using System.Collections.Generic;
namespace SpotifyAPI.Web
{
public class AlbumsResponse
{
public List<FullAlbum> Albums { get; private set; }
}
}

View File

@ -0,0 +1,27 @@
using System.Collections.Generic;
namespace SpotifyAPI.Web
{
public class FullAlbum
{
public string AlbumType { get; private set; }
public List<SimpleArtist> Artists { get; private set; }
public List<string> AvailableMarkets { get; private set; }
public List<Copyright> Copyrights { get; private set; }
public Dictionary<string, string> ExternalIds { get; private set; }
public Dictionary<string, string> ExternalUrls { get; private set; }
public List<string> Genres { get; private set; }
public string Href { get; private set; }
public string Id { get; private set; }
public List<Image> Images { get; private set; }
public string Label { get; private set; }
public string Name { get; private set; }
public int Popularity { get; private set; }
public string ReleaseDate { get; private set; }
public string ReleaseDatePrecision { get; private set; }
public Dictionary<string, string> Restrictions { get; private set; }
public Paging<SimpleTrack> Tracks { get; private set; }
public string Type { get; private set; }
public string Uri { get; private set; }
}
}

View File

@ -87,6 +87,12 @@ namespace SpotifyAPI.Web
public static Uri PlayerPrevious() => EUri($"me/player/previous");
public static Uri Albums() => EUri($"albums");
public static Uri Album(string albumId) => EUri($"albums/{albumId}");
public static Uri AlbumTracks(string albumId) => EUri($"albums/{albumId}/tracks");
private static Uri EUri(FormattableString path) => new Uri(path.ToString(_provider), UriKind.Relative);
}
}