mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2024-12-23 22:56:25 +00:00
Added Albums Client #451
This commit is contained in:
parent
249a535e07
commit
a82f95f0d0
48
SpotifyAPI.Web/Clients/AlbumsClient.cs
Normal file
48
SpotifyAPI.Web/Clients/AlbumsClient.cs
Normal 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());
|
||||
}
|
||||
}
|
||||
}
|
18
SpotifyAPI.Web/Clients/Interfaces/IAlbumsClient.cs
Normal file
18
SpotifyAPI.Web/Clients/Interfaces/IAlbumsClient.cs
Normal 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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
@ -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);
|
||||
|
8
SpotifyAPI.Web/Models/Request/AlbumRequest.cs
Normal file
8
SpotifyAPI.Web/Models/Request/AlbumRequest.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public class AlbumRequest : RequestParams
|
||||
{
|
||||
[QueryParam("market")]
|
||||
public string Market { get; set; }
|
||||
}
|
||||
}
|
14
SpotifyAPI.Web/Models/Request/AlbumTracksRequest.cs
Normal file
14
SpotifyAPI.Web/Models/Request/AlbumTracksRequest.cs
Normal 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; }
|
||||
}
|
||||
}
|
20
SpotifyAPI.Web/Models/Request/AlbumsRequest.cs
Normal file
20
SpotifyAPI.Web/Models/Request/AlbumsRequest.cs
Normal 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; }
|
||||
}
|
||||
}
|
9
SpotifyAPI.Web/Models/Response/AlbumsResponse.cs
Normal file
9
SpotifyAPI.Web/Models/Response/AlbumsResponse.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public class AlbumsResponse
|
||||
{
|
||||
public List<FullAlbum> Albums { get; private set; }
|
||||
}
|
||||
}
|
27
SpotifyAPI.Web/Models/Response/FullAlbum.cs
Normal file
27
SpotifyAPI.Web/Models/Response/FullAlbum.cs
Normal 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; }
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user