mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2024-12-23 14:46:26 +00:00
Added Artists Client #451
This commit is contained in:
parent
bf4c817e70
commit
df6800f2ea
25
.vscode/csharp.code-snippets
vendored
25
.vscode/csharp.code-snippets
vendored
@ -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"
|
||||
}
|
||||
}
|
||||
|
55
SpotifyAPI.Web/Clients/ArtistsClient.cs
Normal file
55
SpotifyAPI.Web/Clients/ArtistsClient.cs
Normal 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());
|
||||
}
|
||||
}
|
||||
}
|
18
SpotifyAPI.Web/Clients/Interfaces/IArtistsClient.cs
Normal file
18
SpotifyAPI.Web/Clients/Interfaces/IArtistsClient.cs
Normal 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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
@ -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);
|
||||
|
35
SpotifyAPI.Web/Models/Request/ArtistsAlbumsRequest.cs
Normal file
35
SpotifyAPI.Web/Models/Request/ArtistsAlbumsRequest.cs
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
17
SpotifyAPI.Web/Models/Request/ArtistsRequest.cs
Normal file
17
SpotifyAPI.Web/Models/Request/ArtistsRequest.cs
Normal 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; }
|
||||
}
|
||||
}
|
15
SpotifyAPI.Web/Models/Request/ArtistsTopTracksRequest.cs
Normal file
15
SpotifyAPI.Web/Models/Request/ArtistsTopTracksRequest.cs
Normal 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; }
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public class ArtistsRelatedArtistsResponse
|
||||
{
|
||||
public List<FullArtist> Artists { get; set; }
|
||||
}
|
||||
}
|
9
SpotifyAPI.Web/Models/Response/ArtistsResponse.cs
Normal file
9
SpotifyAPI.Web/Models/Response/ArtistsResponse.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public class ArtistsResponse
|
||||
{
|
||||
public List<FullArtist> Artists { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public class ArtistsTopTracksResponse
|
||||
{
|
||||
public List<FullTrack> Tracks { get; set; }
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user