mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2024-12-24 23:16:28 +00:00
Added Personalization Client #451
This commit is contained in:
parent
df6800f2ea
commit
8fb0ba7974
13
SpotifyAPI.Web/Clients/Interfaces/IPersonalizationClient.cs
Normal file
13
SpotifyAPI.Web/Clients/Interfaces/IPersonalizationClient.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SpotifyAPI.Web
|
||||||
|
{
|
||||||
|
public interface IPersonalizationClient
|
||||||
|
{
|
||||||
|
Task<Paging<FullTrack>> GetTopTracks();
|
||||||
|
Task<Paging<FullTrack>> GetTopTracks(PersonalizationTopRequest request);
|
||||||
|
|
||||||
|
Task<Paging<FullArtist>> GetTopArtists();
|
||||||
|
Task<Paging<FullArtist>> GetTopArtists(PersonalizationTopRequest request);
|
||||||
|
}
|
||||||
|
}
|
@ -28,6 +28,8 @@ namespace SpotifyAPI.Web
|
|||||||
|
|
||||||
IArtistsClient Artists { get; }
|
IArtistsClient Artists { get; }
|
||||||
|
|
||||||
|
IPersonalizationClient Personalization { get; }
|
||||||
|
|
||||||
Task<List<T>> Paginate<T>(Paging<T> firstPage);
|
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, TNext>(Paging<T, TNext> firstPage, Func<TNext, Paging<T, TNext>> mapper);
|
||||||
Task<List<T>> Paginate<T>(Func<Task<Paging<T>>> getFirstPage);
|
Task<List<T>> Paginate<T>(Func<Task<Paging<T>>> getFirstPage);
|
||||||
|
35
SpotifyAPI.Web/Clients/PersonalizationClient.cs
Normal file
35
SpotifyAPI.Web/Clients/PersonalizationClient.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using SpotifyAPI.Web.Http;
|
||||||
|
using URLs = SpotifyAPI.Web.SpotifyUrls;
|
||||||
|
|
||||||
|
namespace SpotifyAPI.Web
|
||||||
|
{
|
||||||
|
public class PersonalizationClient : APIClient, IPersonalizationClient
|
||||||
|
{
|
||||||
|
public PersonalizationClient(IAPIConnector apiConnector) : base(apiConnector) { }
|
||||||
|
|
||||||
|
public Task<Paging<FullArtist>> GetTopArtists()
|
||||||
|
{
|
||||||
|
return API.Get<Paging<FullArtist>>(URLs.PersonalizationTop("artists"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<Paging<FullArtist>> GetTopArtists(PersonalizationTopRequest request)
|
||||||
|
{
|
||||||
|
Ensure.ArgumentNotNull(request, nameof(request));
|
||||||
|
|
||||||
|
return API.Get<Paging<FullArtist>>(URLs.PersonalizationTop("artists"), request.BuildQueryParams());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<Paging<FullTrack>> GetTopTracks()
|
||||||
|
{
|
||||||
|
return API.Get<Paging<FullTrack>>(URLs.PersonalizationTop("tracks"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<Paging<FullTrack>> GetTopTracks(PersonalizationTopRequest request)
|
||||||
|
{
|
||||||
|
Ensure.ArgumentNotNull(request, nameof(request));
|
||||||
|
|
||||||
|
return API.Get<Paging<FullTrack>>(URLs.PersonalizationTop("tracks"), request.BuildQueryParams());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -29,6 +29,7 @@ namespace SpotifyAPI.Web
|
|||||||
Player = new PlayerClient(_apiConnector);
|
Player = new PlayerClient(_apiConnector);
|
||||||
Albums = new AlbumsClient(_apiConnector);
|
Albums = new AlbumsClient(_apiConnector);
|
||||||
Artists = new ArtistsClient(_apiConnector);
|
Artists = new ArtistsClient(_apiConnector);
|
||||||
|
Personalization = new PersonalizationClient(_apiConnector);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IPaginator DefaultPaginator { get; }
|
public IPaginator DefaultPaginator { get; }
|
||||||
@ -53,6 +54,8 @@ namespace SpotifyAPI.Web
|
|||||||
|
|
||||||
public IArtistsClient Artists { get; }
|
public IArtistsClient Artists { get; }
|
||||||
|
|
||||||
|
public IPersonalizationClient Personalization { get; }
|
||||||
|
|
||||||
public Task<List<T>> Paginate<T>(Paging<T> firstPage)
|
public Task<List<T>> Paginate<T>(Paging<T> firstPage)
|
||||||
{
|
{
|
||||||
return DefaultPaginator.Paginate(firstPage, _apiConnector);
|
return DefaultPaginator.Paginate(firstPage, _apiConnector);
|
||||||
|
26
SpotifyAPI.Web/Models/Request/PersonalizationTopRequest.cs
Normal file
26
SpotifyAPI.Web/Models/Request/PersonalizationTopRequest.cs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
namespace SpotifyAPI.Web
|
||||||
|
{
|
||||||
|
public class PersonalizationTopRequest : RequestParams
|
||||||
|
{
|
||||||
|
[QueryParam("limit")]
|
||||||
|
public int? Limit { get; set; }
|
||||||
|
|
||||||
|
[QueryParam("offset")]
|
||||||
|
public int? Offset { get; set; }
|
||||||
|
|
||||||
|
[QueryParam("time_range")]
|
||||||
|
public TimeRange? TimeRangeParam { get; set; }
|
||||||
|
|
||||||
|
public enum TimeRange
|
||||||
|
{
|
||||||
|
[String("long_term")]
|
||||||
|
LongTerm,
|
||||||
|
|
||||||
|
[String("medium_term")]
|
||||||
|
MediumTerm,
|
||||||
|
|
||||||
|
[String("short_term")]
|
||||||
|
ShortTerm
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -103,6 +103,8 @@ namespace SpotifyAPI.Web
|
|||||||
|
|
||||||
public static Uri ArtistRelatedArtists(string artistId) => EUri($"artists/{artistId}/related-artists");
|
public static Uri ArtistRelatedArtists(string artistId) => EUri($"artists/{artistId}/related-artists");
|
||||||
|
|
||||||
|
public static Uri PersonalizationTop(string type) => EUri($"me/top/{type}");
|
||||||
|
|
||||||
private static Uri EUri(FormattableString path) => new Uri(path.ToString(_provider), UriKind.Relative);
|
private static Uri EUri(FormattableString path) => new Uri(path.ToString(_provider), UriKind.Relative);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user