mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2024-12-23 14:46:26 +00:00
Added Library Client #451
This commit is contained in:
parent
39d0260bbd
commit
320aa5f134
27
SpotifyAPI.Web/Clients/Interfaces/ILibraryClient.cs
Normal file
27
SpotifyAPI.Web/Clients/Interfaces/ILibraryClient.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public interface ILibraryClient
|
||||
{
|
||||
Task<bool> RemoveAlbums(LibraryRemoveAlbumsRequest request);
|
||||
Task<bool> RemoveTracks(LibraryRemoveTracksRequest request);
|
||||
Task<bool> RemoveShows(LibraryRemoveShowsRequest request);
|
||||
|
||||
Task<bool> SaveTracks(LibrarySaveTracksRequest request);
|
||||
Task<bool> SaveAlbums(LibrarySaveAlbumsRequest request);
|
||||
Task<bool> SaveShows(LibrarySaveShowsRequest request);
|
||||
|
||||
Task<List<bool>> CheckTracks(LibraryCheckTracksRequest request);
|
||||
Task<List<bool>> CheckAlbums(LibraryCheckAlbumsRequest request);
|
||||
Task<List<bool>> CheckShows(LibraryCheckShowsRequest request);
|
||||
|
||||
Task<Paging<SavedTrack>> GetTracks();
|
||||
Task<Paging<SavedTrack>> GetTracks(LibraryTracksRequest request);
|
||||
Task<Paging<SavedAlbum>> GetAlbums();
|
||||
Task<Paging<SavedAlbum>> GetAlbums(LibraryAlbumsRequest request);
|
||||
Task<Paging<SavedShow>> GetShows();
|
||||
Task<Paging<SavedShow>> GetShows(LibraryShowsRequest request);
|
||||
}
|
||||
}
|
@ -32,6 +32,8 @@ namespace SpotifyAPI.Web
|
||||
|
||||
IEpisodesClient Episodes { get; }
|
||||
|
||||
ILibraryClient Library { 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);
|
||||
|
117
SpotifyAPI.Web/Clients/LibraryClient.cs
Normal file
117
SpotifyAPI.Web/Clients/LibraryClient.cs
Normal file
@ -0,0 +1,117 @@
|
||||
using System.Net;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using SpotifyAPI.Web.Http;
|
||||
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public class LibraryClient : APIClient, ILibraryClient
|
||||
{
|
||||
public LibraryClient(IAPIConnector apiConnector) : base(apiConnector) { }
|
||||
|
||||
public Task<List<bool>> CheckAlbums(LibraryCheckAlbumsRequest request)
|
||||
{
|
||||
Ensure.ArgumentNotNull(request, nameof(request));
|
||||
|
||||
return API.Get<List<bool>>(SpotifyUrls.LibraryAlbumsContains(), request.BuildQueryParams());
|
||||
}
|
||||
|
||||
public Task<List<bool>> CheckShows(LibraryCheckShowsRequest request)
|
||||
{
|
||||
Ensure.ArgumentNotNull(request, nameof(request));
|
||||
|
||||
return API.Get<List<bool>>(SpotifyUrls.LibraryShowsContains(), request.BuildQueryParams());
|
||||
}
|
||||
|
||||
public Task<List<bool>> CheckTracks(LibraryCheckTracksRequest request)
|
||||
{
|
||||
Ensure.ArgumentNotNull(request, nameof(request));
|
||||
|
||||
return API.Get<List<bool>>(SpotifyUrls.LibraryTracksContains(), request.BuildQueryParams());
|
||||
}
|
||||
|
||||
public Task<Paging<SavedAlbum>> GetAlbums()
|
||||
{
|
||||
return API.Get<Paging<SavedAlbum>>(SpotifyUrls.LibraryAlbums());
|
||||
}
|
||||
|
||||
public Task<Paging<SavedAlbum>> GetAlbums(LibraryAlbumsRequest request)
|
||||
{
|
||||
Ensure.ArgumentNotNull(request, nameof(request));
|
||||
|
||||
return API.Get<Paging<SavedAlbum>>(SpotifyUrls.LibraryAlbums(), request.BuildQueryParams());
|
||||
}
|
||||
|
||||
public Task<Paging<SavedShow>> GetShows()
|
||||
{
|
||||
return API.Get<Paging<SavedShow>>(SpotifyUrls.LibraryShows());
|
||||
}
|
||||
|
||||
public Task<Paging<SavedShow>> GetShows(LibraryShowsRequest request)
|
||||
{
|
||||
Ensure.ArgumentNotNull(request, nameof(request));
|
||||
|
||||
return API.Get<Paging<SavedShow>>(SpotifyUrls.LibraryShows(), request.BuildQueryParams());
|
||||
}
|
||||
|
||||
public Task<Paging<SavedTrack>> GetTracks()
|
||||
{
|
||||
return API.Get<Paging<SavedTrack>>(SpotifyUrls.LibraryTracks());
|
||||
}
|
||||
|
||||
public Task<Paging<SavedTrack>> GetTracks(LibraryTracksRequest request)
|
||||
{
|
||||
Ensure.ArgumentNotNull(request, nameof(request));
|
||||
|
||||
return API.Get<Paging<SavedTrack>>(SpotifyUrls.LibraryTracks(), request.BuildQueryParams());
|
||||
}
|
||||
|
||||
public async Task<bool> RemoveAlbums(LibraryRemoveAlbumsRequest request)
|
||||
{
|
||||
Ensure.ArgumentNotNull(request, nameof(request));
|
||||
|
||||
var statusCode = await API.Delete(SpotifyUrls.LibraryAlbums(), null, request.BuildBodyParams()).ConfigureAwait(false);
|
||||
return statusCode == HttpStatusCode.OK;
|
||||
}
|
||||
|
||||
public async Task<bool> RemoveShows(LibraryRemoveShowsRequest request)
|
||||
{
|
||||
Ensure.ArgumentNotNull(request, nameof(request));
|
||||
|
||||
var statusCode = await API.Delete(SpotifyUrls.LibraryShows(), null, request.BuildBodyParams()).ConfigureAwait(false);
|
||||
return statusCode == HttpStatusCode.OK;
|
||||
}
|
||||
|
||||
public async Task<bool> RemoveTracks(LibraryRemoveTracksRequest request)
|
||||
{
|
||||
Ensure.ArgumentNotNull(request, nameof(request));
|
||||
|
||||
var statusCode = await API.Delete(SpotifyUrls.LibraryTracks(), null, request.BuildBodyParams()).ConfigureAwait(false);
|
||||
return statusCode == HttpStatusCode.OK;
|
||||
}
|
||||
|
||||
public async Task<bool> SaveAlbums(LibrarySaveAlbumsRequest request)
|
||||
{
|
||||
Ensure.ArgumentNotNull(request, nameof(request));
|
||||
|
||||
var statusCode = await API.Put(SpotifyUrls.LibraryAlbums(), request.BuildQueryParams(), null).ConfigureAwait(false);
|
||||
return statusCode == HttpStatusCode.Created;
|
||||
}
|
||||
|
||||
public async Task<bool> SaveShows(LibrarySaveShowsRequest request)
|
||||
{
|
||||
Ensure.ArgumentNotNull(request, nameof(request));
|
||||
|
||||
var statusCode = await API.Put(SpotifyUrls.LibraryShows(), request.BuildQueryParams(), null).ConfigureAwait(false);
|
||||
return statusCode == HttpStatusCode.Created;
|
||||
}
|
||||
|
||||
public async Task<bool> SaveTracks(LibrarySaveTracksRequest request)
|
||||
{
|
||||
Ensure.ArgumentNotNull(request, nameof(request));
|
||||
|
||||
var statusCode = await API.Put(SpotifyUrls.LibraryTracks(), request.BuildQueryParams(), null).ConfigureAwait(false);
|
||||
return statusCode == HttpStatusCode.Created;
|
||||
}
|
||||
}
|
||||
}
|
@ -42,6 +42,7 @@ namespace SpotifyAPI.Web
|
||||
Artists = new ArtistsClient(_apiConnector);
|
||||
Personalization = new PersonalizationClient(_apiConnector);
|
||||
Episodes = new EpisodesClient(_apiConnector);
|
||||
Library = new LibraryClient(_apiConnector);
|
||||
}
|
||||
|
||||
public IPaginator DefaultPaginator { get; }
|
||||
@ -70,6 +71,8 @@ namespace SpotifyAPI.Web
|
||||
|
||||
public IEpisodesClient Episodes { get; }
|
||||
|
||||
public ILibraryClient Library { get; }
|
||||
|
||||
public Task<List<T>> Paginate<T>(Paging<T> firstPage)
|
||||
{
|
||||
return DefaultPaginator.Paginate(firstPage, _apiConnector);
|
||||
|
14
SpotifyAPI.Web/Models/Request/LibraryAlbumsRequest.cs
Normal file
14
SpotifyAPI.Web/Models/Request/LibraryAlbumsRequest.cs
Normal file
@ -0,0 +1,14 @@
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public class LibraryAlbumsRequest : RequestParams
|
||||
{
|
||||
[QueryParam("limit")]
|
||||
public int? Limit { get; set; }
|
||||
|
||||
[QueryParam("offset")]
|
||||
public int? Offset { get; set; }
|
||||
|
||||
[QueryParam("market")]
|
||||
public string Market { get; set; }
|
||||
}
|
||||
}
|
18
SpotifyAPI.Web/Models/Request/LibraryCheckAlbumsRequest.cs
Normal file
18
SpotifyAPI.Web/Models/Request/LibraryCheckAlbumsRequest.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public class LibraryCheckAlbumsRequest : RequestParams
|
||||
{
|
||||
public LibraryCheckAlbumsRequest(IList<string> ids)
|
||||
{
|
||||
Ensure.ArgumentNotNull(ids, nameof(ids));
|
||||
|
||||
Ids = ids;
|
||||
}
|
||||
|
||||
|
||||
[QueryParam("ids")]
|
||||
public IList<string> Ids { get; }
|
||||
}
|
||||
}
|
17
SpotifyAPI.Web/Models/Request/LibraryCheckShowsRequest.cs
Normal file
17
SpotifyAPI.Web/Models/Request/LibraryCheckShowsRequest.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public class LibraryCheckShowsRequest : RequestParams
|
||||
{
|
||||
public LibraryCheckShowsRequest(IList<string> ids)
|
||||
{
|
||||
Ensure.ArgumentNotNull(ids, nameof(ids));
|
||||
|
||||
Ids = ids;
|
||||
}
|
||||
|
||||
[QueryParam("ids")]
|
||||
public IList<string> Ids { get; }
|
||||
}
|
||||
}
|
17
SpotifyAPI.Web/Models/Request/LibraryCheckTracksRequest.cs
Normal file
17
SpotifyAPI.Web/Models/Request/LibraryCheckTracksRequest.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public class LibraryCheckTracksRequest : RequestParams
|
||||
{
|
||||
public LibraryCheckTracksRequest(IList<string> ids)
|
||||
{
|
||||
Ensure.ArgumentNotNull(ids, nameof(ids));
|
||||
|
||||
Ids = ids;
|
||||
}
|
||||
|
||||
[QueryParam("ids")]
|
||||
public IList<string> Ids { get; }
|
||||
}
|
||||
}
|
17
SpotifyAPI.Web/Models/Request/LibraryRemoveAlbumsRequest.cs
Normal file
17
SpotifyAPI.Web/Models/Request/LibraryRemoveAlbumsRequest.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public class LibraryRemoveAlbumsRequest : RequestParams
|
||||
{
|
||||
public LibraryRemoveAlbumsRequest(IList<string> ids)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyList(ids, nameof(ids));
|
||||
|
||||
Ids = ids;
|
||||
}
|
||||
|
||||
[BodyParam("ids")]
|
||||
public IList<string> Ids { get; }
|
||||
}
|
||||
}
|
17
SpotifyAPI.Web/Models/Request/LibraryRemoveShowsRequest.cs
Normal file
17
SpotifyAPI.Web/Models/Request/LibraryRemoveShowsRequest.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public class LibraryRemoveShowsRequest : RequestParams
|
||||
{
|
||||
public LibraryRemoveShowsRequest(IList<string> ids)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyList(ids, nameof(ids));
|
||||
|
||||
Ids = ids;
|
||||
}
|
||||
|
||||
[BodyParam("ids")]
|
||||
public IList<string> Ids { get; }
|
||||
}
|
||||
}
|
17
SpotifyAPI.Web/Models/Request/LibraryRemoveTracksRequest.cs
Normal file
17
SpotifyAPI.Web/Models/Request/LibraryRemoveTracksRequest.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public class LibraryRemoveTracksRequest : RequestParams
|
||||
{
|
||||
public LibraryRemoveTracksRequest(IList<string> ids)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyList(ids, nameof(ids));
|
||||
|
||||
Ids = ids;
|
||||
}
|
||||
|
||||
[BodyParam("ids")]
|
||||
public IList<string> Ids { get; }
|
||||
}
|
||||
}
|
17
SpotifyAPI.Web/Models/Request/LibrarySaveAlbumsRequest.cs
Normal file
17
SpotifyAPI.Web/Models/Request/LibrarySaveAlbumsRequest.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public class LibrarySaveAlbumsRequest : RequestParams
|
||||
{
|
||||
public LibrarySaveAlbumsRequest(IList<string> ids)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyList(ids, nameof(ids));
|
||||
|
||||
Ids = ids;
|
||||
}
|
||||
|
||||
[QueryParam("ids")]
|
||||
public IList<string> Ids { get; }
|
||||
}
|
||||
}
|
17
SpotifyAPI.Web/Models/Request/LibrarySaveShowsRequest.cs
Normal file
17
SpotifyAPI.Web/Models/Request/LibrarySaveShowsRequest.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public class LibrarySaveShowsRequest : RequestParams
|
||||
{
|
||||
public LibrarySaveShowsRequest(IList<string> ids)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyList(ids, nameof(ids));
|
||||
|
||||
Ids = ids;
|
||||
}
|
||||
|
||||
[QueryParam("ids")]
|
||||
public IList<string> Ids { get; }
|
||||
}
|
||||
}
|
17
SpotifyAPI.Web/Models/Request/LibrarySaveTracksRequest.cs
Normal file
17
SpotifyAPI.Web/Models/Request/LibrarySaveTracksRequest.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public class LibrarySaveTracksRequest : RequestParams
|
||||
{
|
||||
public LibrarySaveTracksRequest(IList<string> ids)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyList(ids, nameof(ids));
|
||||
|
||||
Ids = ids;
|
||||
}
|
||||
|
||||
[QueryParam("ids")]
|
||||
public IList<string> Ids { get; }
|
||||
}
|
||||
}
|
14
SpotifyAPI.Web/Models/Request/LibraryShowsRequest.cs
Normal file
14
SpotifyAPI.Web/Models/Request/LibraryShowsRequest.cs
Normal file
@ -0,0 +1,14 @@
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public class LibraryShowsRequest : RequestParams
|
||||
{
|
||||
[QueryParam("limit")]
|
||||
public int? Limit { get; set; }
|
||||
|
||||
[QueryParam("offset")]
|
||||
public int? Offset { get; set; }
|
||||
|
||||
[QueryParam("market")]
|
||||
public string Market { get; set; }
|
||||
}
|
||||
}
|
14
SpotifyAPI.Web/Models/Request/LibraryTracksRequest.cs
Normal file
14
SpotifyAPI.Web/Models/Request/LibraryTracksRequest.cs
Normal file
@ -0,0 +1,14 @@
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public class LibraryTracksRequest : RequestParams
|
||||
{
|
||||
[QueryParam("limit")]
|
||||
public int? Limit { get; set; }
|
||||
|
||||
[QueryParam("offset")]
|
||||
public int? Offset { get; set; }
|
||||
|
||||
[QueryParam("market")]
|
||||
public string Market { get; set; }
|
||||
}
|
||||
}
|
10
SpotifyAPI.Web/Models/Response/SavedAlbum.cs
Normal file
10
SpotifyAPI.Web/Models/Response/SavedAlbum.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public class SavedAlbum
|
||||
{
|
||||
public DateTime AddedAt { get; set; }
|
||||
public FullAlbum Album { get; set; }
|
||||
}
|
||||
}
|
10
SpotifyAPI.Web/Models/Response/SavedShow.cs
Normal file
10
SpotifyAPI.Web/Models/Response/SavedShow.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public class SavedShow
|
||||
{
|
||||
public DateTime AddedAt { get; set; }
|
||||
public FullShow Show { get; set; }
|
||||
}
|
||||
}
|
10
SpotifyAPI.Web/Models/Response/SavedTrack.cs
Normal file
10
SpotifyAPI.Web/Models/Response/SavedTrack.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace SpotifyAPI.Web
|
||||
{
|
||||
public class SavedTrack
|
||||
{
|
||||
public DateTime AddedAt { get; set; }
|
||||
public FullTrack Track { get; set; }
|
||||
}
|
||||
}
|
@ -113,6 +113,18 @@ namespace SpotifyAPI.Web
|
||||
|
||||
public static Uri Episodes() => EUri($"episodes");
|
||||
|
||||
public static Uri LibraryAlbumsContains() => EUri($"me/albums/contains");
|
||||
|
||||
public static Uri LibraryAlbums() => EUri($"me/albums");
|
||||
|
||||
public static Uri LibraryTracksContains() => EUri($"me/tracks/contains");
|
||||
|
||||
public static Uri LibraryTracks() => EUri($"me/tracks");
|
||||
|
||||
public static Uri LibraryShowsContains() => EUri($"me/shows/contains");
|
||||
|
||||
public static Uri LibraryShows() => EUri($"me/shows");
|
||||
|
||||
private static Uri EUri(FormattableString path) => new Uri(path.ToString(_provider), UriKind.Relative);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user