Added Artists Client #451

This commit is contained in:
Jonas Dellinger 2020-05-08 11:10:53 +02:00
parent bf4c817e70
commit df6800f2ea
12 changed files with 203 additions and 4 deletions

View File

@ -1,18 +1,35 @@
{
"model": {
"model-class": {
"scope": "csharp",
"prefix": "model",
"prefix": "model-class",
"body": [
"namespace SpotifyAPI.Web",
"{",
" public class $1",
" public class $TM_FILENAME_BASE",
" {",
" public ${2:string} ${3:Name} { get; private set; }",
" public ${2:string} ${3:Name} { get; set; }",
"",
" $4",
" }",
"}"
],
"description": "Creates a new model"
},
"request-class": {
"scope": "csharp",
"prefix": "request-class",
"body": [
"namespace SpotifyAPI.Web",
"{",
" public class $TM_FILENAME_BASE : RequestParams",
" {",
" [QueryParam(\"${3:Name}\")]",
" public ${2:string} ${3:Name} { get; set; }",
"",
" $4",
" }",
"}"
],
"description": "Creates a new request"
}
}

View File

@ -0,0 +1,55 @@
using System.Threading.Tasks;
using SpotifyAPI.Web.Http;
using URLs = SpotifyAPI.Web.SpotifyUrls;
namespace SpotifyAPI.Web
{
public class ArtistsClient : APIClient, IArtistsClient
{
public ArtistsClient(IAPIConnector apiConnector) : base(apiConnector) { }
public Task<FullArtist> Get(string artistId)
{
Ensure.ArgumentNotNullOrEmptyString(artistId, nameof(artistId));
return API.Get<FullArtist>(URLs.Artist(artistId));
}
public Task<Paging<SimpleAlbum>> GetAlbums(string artistId)
{
Ensure.ArgumentNotNullOrEmptyString(artistId, nameof(artistId));
return API.Get<Paging<SimpleAlbum>>(URLs.ArtistAlbums(artistId));
}
public Task<Paging<SimpleAlbum>> GetAlbums(string artistId, ArtistsAlbumsRequest request)
{
Ensure.ArgumentNotNullOrEmptyString(artistId, nameof(artistId));
Ensure.ArgumentNotNull(request, nameof(request));
return API.Get<Paging<SimpleAlbum>>(URLs.ArtistAlbums(artistId), request.BuildQueryParams());
}
public Task<ArtistsRelatedArtistsResponse> GetRelatedArtists(string artistId)
{
Ensure.ArgumentNotNullOrEmptyString(artistId, nameof(artistId));
return API.Get<ArtistsRelatedArtistsResponse>(URLs.ArtistRelatedArtists(artistId));
}
public Task<ArtistsResponse> GetSeveral(ArtistsRequest request)
{
Ensure.ArgumentNotNull(request, nameof(request));
return API.Get<ArtistsResponse>(URLs.Artists(), request.BuildQueryParams());
}
public Task<ArtistsTopTracksResponse> GetTopTracks(string artistId, ArtistsTopTracksRequest request)
{
Ensure.ArgumentNotNullOrEmptyString(artistId, nameof(artistId));
Ensure.ArgumentNotNull(request, nameof(request));
return API.Get<ArtistsTopTracksResponse>(URLs.ArtistTopTracks(artistId), request.BuildQueryParams());
}
}
}

View File

@ -0,0 +1,18 @@
using System.Threading.Tasks;
namespace SpotifyAPI.Web
{
public interface IArtistsClient
{
Task<ArtistsResponse> GetSeveral(ArtistsRequest request);
Task<FullArtist> Get(string artistId);
Task<Paging<SimpleAlbum>> GetAlbums(string artistId);
Task<Paging<SimpleAlbum>> GetAlbums(string artistId, ArtistsAlbumsRequest request);
Task<ArtistsTopTracksResponse> GetTopTracks(string artistId, ArtistsTopTracksRequest request);
Task<ArtistsRelatedArtistsResponse> GetRelatedArtists(string artistId);
}
}

View File

@ -26,6 +26,8 @@ namespace SpotifyAPI.Web
IAlbumsClient Albums { get; }
IArtistsClient Artists { 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

@ -28,6 +28,7 @@ namespace SpotifyAPI.Web
Tracks = new TracksClient(_apiConnector);
Player = new PlayerClient(_apiConnector);
Albums = new AlbumsClient(_apiConnector);
Artists = new ArtistsClient(_apiConnector);
}
public IPaginator DefaultPaginator { get; }
@ -50,6 +51,8 @@ namespace SpotifyAPI.Web
public IAlbumsClient Albums { get; }
public IArtistsClient Artists { get; }
public Task<List<T>> Paginate<T>(Paging<T> firstPage)
{
return DefaultPaginator.Paginate(firstPage, _apiConnector);

View File

@ -0,0 +1,35 @@
using System;
namespace SpotifyAPI.Web
{
public class ArtistsAlbumsRequest : RequestParams
{
[QueryParam("include_groups")]
public IncludeGroups? IncludeGroupsParam { get; set; }
[QueryParam("market")]
public string Market { get; set; }
[QueryParam("limit")]
public int? Limit { get; set; }
[QueryParam("offset")]
public int? Offset { get; set; }
[Flags]
public enum IncludeGroups
{
[String("album")]
Album,
[String("single")]
Single,
[String("appears_on")]
AppearsOn,
[String("compilation")]
Compilation
}
}
}

View File

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

View File

@ -0,0 +1,15 @@
namespace SpotifyAPI.Web
{
public class ArtistsTopTracksRequest : RequestParams
{
public ArtistsTopTracksRequest(string market)
{
Ensure.ArgumentNotNullOrEmptyString(market, nameof(market));
Market = market;
}
[QueryParam("market")]
public string Market { get; }
}
}

View File

@ -0,0 +1,9 @@
using System.Collections.Generic;
namespace SpotifyAPI.Web
{
public class ArtistsRelatedArtistsResponse
{
public List<FullArtist> Artists { get; set; }
}
}

View File

@ -0,0 +1,9 @@
using System.Collections.Generic;
namespace SpotifyAPI.Web
{
public class ArtistsResponse
{
public List<FullArtist> Artists { get; set; }
}
}

View File

@ -0,0 +1,9 @@
using System.Collections.Generic;
namespace SpotifyAPI.Web
{
public class ArtistsTopTracksResponse
{
public List<FullTrack> Tracks { get; set; }
}
}

View File

@ -93,6 +93,16 @@ namespace SpotifyAPI.Web
public static Uri AlbumTracks(string albumId) => EUri($"albums/{albumId}/tracks");
public static Uri Artists() => EUri($"artists");
public static Uri Artist(string artistId) => EUri($"artists/{artistId}");
public static Uri ArtistAlbums(string artistId) => EUri($"artists/{artistId}/albums");
public static Uri ArtistTopTracks(string artistId) => EUri($"artists/{artistId}/top-tracks");
public static Uri ArtistRelatedArtists(string artistId) => EUri($"artists/{artistId}/related-artists");
private static Uri EUri(FormattableString path) => new Uri(path.ToString(_provider), UriKind.Relative);
}
}