diff --git a/SpotifyAPI.Web/Clients/Interfaces/ILibraryClient.cs b/SpotifyAPI.Web/Clients/Interfaces/ILibraryClient.cs new file mode 100644 index 00000000..ee4a4811 --- /dev/null +++ b/SpotifyAPI.Web/Clients/Interfaces/ILibraryClient.cs @@ -0,0 +1,27 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace SpotifyAPI.Web +{ + public interface ILibraryClient + { + Task RemoveAlbums(LibraryRemoveAlbumsRequest request); + Task RemoveTracks(LibraryRemoveTracksRequest request); + Task RemoveShows(LibraryRemoveShowsRequest request); + + Task SaveTracks(LibrarySaveTracksRequest request); + Task SaveAlbums(LibrarySaveAlbumsRequest request); + Task SaveShows(LibrarySaveShowsRequest request); + + Task> CheckTracks(LibraryCheckTracksRequest request); + Task> CheckAlbums(LibraryCheckAlbumsRequest request); + Task> CheckShows(LibraryCheckShowsRequest request); + + Task> GetTracks(); + Task> GetTracks(LibraryTracksRequest request); + Task> GetAlbums(); + Task> GetAlbums(LibraryAlbumsRequest request); + Task> GetShows(); + Task> GetShows(LibraryShowsRequest request); + } +} diff --git a/SpotifyAPI.Web/Clients/Interfaces/ISpotifyClient.cs b/SpotifyAPI.Web/Clients/Interfaces/ISpotifyClient.cs index 8c518c77..2bd04f59 100644 --- a/SpotifyAPI.Web/Clients/Interfaces/ISpotifyClient.cs +++ b/SpotifyAPI.Web/Clients/Interfaces/ISpotifyClient.cs @@ -32,6 +32,8 @@ namespace SpotifyAPI.Web IEpisodesClient Episodes { get; } + ILibraryClient Library { get; } + Task> Paginate(Paging firstPage); Task> Paginate(Paging firstPage, Func> mapper); Task> Paginate(Func>> getFirstPage); diff --git a/SpotifyAPI.Web/Clients/LibraryClient.cs b/SpotifyAPI.Web/Clients/LibraryClient.cs new file mode 100644 index 00000000..55a66836 --- /dev/null +++ b/SpotifyAPI.Web/Clients/LibraryClient.cs @@ -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> CheckAlbums(LibraryCheckAlbumsRequest request) + { + Ensure.ArgumentNotNull(request, nameof(request)); + + return API.Get>(SpotifyUrls.LibraryAlbumsContains(), request.BuildQueryParams()); + } + + public Task> CheckShows(LibraryCheckShowsRequest request) + { + Ensure.ArgumentNotNull(request, nameof(request)); + + return API.Get>(SpotifyUrls.LibraryShowsContains(), request.BuildQueryParams()); + } + + public Task> CheckTracks(LibraryCheckTracksRequest request) + { + Ensure.ArgumentNotNull(request, nameof(request)); + + return API.Get>(SpotifyUrls.LibraryTracksContains(), request.BuildQueryParams()); + } + + public Task> GetAlbums() + { + return API.Get>(SpotifyUrls.LibraryAlbums()); + } + + public Task> GetAlbums(LibraryAlbumsRequest request) + { + Ensure.ArgumentNotNull(request, nameof(request)); + + return API.Get>(SpotifyUrls.LibraryAlbums(), request.BuildQueryParams()); + } + + public Task> GetShows() + { + return API.Get>(SpotifyUrls.LibraryShows()); + } + + public Task> GetShows(LibraryShowsRequest request) + { + Ensure.ArgumentNotNull(request, nameof(request)); + + return API.Get>(SpotifyUrls.LibraryShows(), request.BuildQueryParams()); + } + + public Task> GetTracks() + { + return API.Get>(SpotifyUrls.LibraryTracks()); + } + + public Task> GetTracks(LibraryTracksRequest request) + { + Ensure.ArgumentNotNull(request, nameof(request)); + + return API.Get>(SpotifyUrls.LibraryTracks(), request.BuildQueryParams()); + } + + public async Task 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 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 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 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 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 SaveTracks(LibrarySaveTracksRequest request) + { + Ensure.ArgumentNotNull(request, nameof(request)); + + var statusCode = await API.Put(SpotifyUrls.LibraryTracks(), request.BuildQueryParams(), null).ConfigureAwait(false); + return statusCode == HttpStatusCode.Created; + } + } +} diff --git a/SpotifyAPI.Web/Clients/SpotifyClient.cs b/SpotifyAPI.Web/Clients/SpotifyClient.cs index 9c5c92af..7fcc5c66 100644 --- a/SpotifyAPI.Web/Clients/SpotifyClient.cs +++ b/SpotifyAPI.Web/Clients/SpotifyClient.cs @@ -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> Paginate(Paging firstPage) { return DefaultPaginator.Paginate(firstPage, _apiConnector); diff --git a/SpotifyAPI.Web/Models/Request/LibraryAlbumsRequest.cs b/SpotifyAPI.Web/Models/Request/LibraryAlbumsRequest.cs new file mode 100644 index 00000000..0aaba0bd --- /dev/null +++ b/SpotifyAPI.Web/Models/Request/LibraryAlbumsRequest.cs @@ -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; } + } +} diff --git a/SpotifyAPI.Web/Models/Request/LibraryCheckAlbumsRequest.cs b/SpotifyAPI.Web/Models/Request/LibraryCheckAlbumsRequest.cs new file mode 100644 index 00000000..a7b25c58 --- /dev/null +++ b/SpotifyAPI.Web/Models/Request/LibraryCheckAlbumsRequest.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; + +namespace SpotifyAPI.Web +{ + public class LibraryCheckAlbumsRequest : RequestParams + { + public LibraryCheckAlbumsRequest(IList ids) + { + Ensure.ArgumentNotNull(ids, nameof(ids)); + + Ids = ids; + } + + + [QueryParam("ids")] + public IList Ids { get; } + } +} diff --git a/SpotifyAPI.Web/Models/Request/LibraryCheckShowsRequest.cs b/SpotifyAPI.Web/Models/Request/LibraryCheckShowsRequest.cs new file mode 100644 index 00000000..66ba2aab --- /dev/null +++ b/SpotifyAPI.Web/Models/Request/LibraryCheckShowsRequest.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; + +namespace SpotifyAPI.Web +{ + public class LibraryCheckShowsRequest : RequestParams + { + public LibraryCheckShowsRequest(IList ids) + { + Ensure.ArgumentNotNull(ids, nameof(ids)); + + Ids = ids; + } + + [QueryParam("ids")] + public IList Ids { get; } + } +} diff --git a/SpotifyAPI.Web/Models/Request/LibraryCheckTracksRequest.cs b/SpotifyAPI.Web/Models/Request/LibraryCheckTracksRequest.cs new file mode 100644 index 00000000..ee2d291f --- /dev/null +++ b/SpotifyAPI.Web/Models/Request/LibraryCheckTracksRequest.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; + +namespace SpotifyAPI.Web +{ + public class LibraryCheckTracksRequest : RequestParams + { + public LibraryCheckTracksRequest(IList ids) + { + Ensure.ArgumentNotNull(ids, nameof(ids)); + + Ids = ids; + } + + [QueryParam("ids")] + public IList Ids { get; } + } +} diff --git a/SpotifyAPI.Web/Models/Request/LibraryRemoveAlbumsRequest.cs b/SpotifyAPI.Web/Models/Request/LibraryRemoveAlbumsRequest.cs new file mode 100644 index 00000000..fc69474a --- /dev/null +++ b/SpotifyAPI.Web/Models/Request/LibraryRemoveAlbumsRequest.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; + +namespace SpotifyAPI.Web +{ + public class LibraryRemoveAlbumsRequest : RequestParams + { + public LibraryRemoveAlbumsRequest(IList ids) + { + Ensure.ArgumentNotNullOrEmptyList(ids, nameof(ids)); + + Ids = ids; + } + + [BodyParam("ids")] + public IList Ids { get; } + } +} diff --git a/SpotifyAPI.Web/Models/Request/LibraryRemoveShowsRequest.cs b/SpotifyAPI.Web/Models/Request/LibraryRemoveShowsRequest.cs new file mode 100644 index 00000000..ac2fd390 --- /dev/null +++ b/SpotifyAPI.Web/Models/Request/LibraryRemoveShowsRequest.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; + +namespace SpotifyAPI.Web +{ + public class LibraryRemoveShowsRequest : RequestParams + { + public LibraryRemoveShowsRequest(IList ids) + { + Ensure.ArgumentNotNullOrEmptyList(ids, nameof(ids)); + + Ids = ids; + } + + [BodyParam("ids")] + public IList Ids { get; } + } +} diff --git a/SpotifyAPI.Web/Models/Request/LibraryRemoveTracksRequest.cs b/SpotifyAPI.Web/Models/Request/LibraryRemoveTracksRequest.cs new file mode 100644 index 00000000..661922d4 --- /dev/null +++ b/SpotifyAPI.Web/Models/Request/LibraryRemoveTracksRequest.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; + +namespace SpotifyAPI.Web +{ + public class LibraryRemoveTracksRequest : RequestParams + { + public LibraryRemoveTracksRequest(IList ids) + { + Ensure.ArgumentNotNullOrEmptyList(ids, nameof(ids)); + + Ids = ids; + } + + [BodyParam("ids")] + public IList Ids { get; } + } +} diff --git a/SpotifyAPI.Web/Models/Request/LibrarySaveAlbumsRequest.cs b/SpotifyAPI.Web/Models/Request/LibrarySaveAlbumsRequest.cs new file mode 100644 index 00000000..ea442c72 --- /dev/null +++ b/SpotifyAPI.Web/Models/Request/LibrarySaveAlbumsRequest.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; + +namespace SpotifyAPI.Web +{ + public class LibrarySaveAlbumsRequest : RequestParams + { + public LibrarySaveAlbumsRequest(IList ids) + { + Ensure.ArgumentNotNullOrEmptyList(ids, nameof(ids)); + + Ids = ids; + } + + [QueryParam("ids")] + public IList Ids { get; } + } +} diff --git a/SpotifyAPI.Web/Models/Request/LibrarySaveShowsRequest.cs b/SpotifyAPI.Web/Models/Request/LibrarySaveShowsRequest.cs new file mode 100644 index 00000000..84adb029 --- /dev/null +++ b/SpotifyAPI.Web/Models/Request/LibrarySaveShowsRequest.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; + +namespace SpotifyAPI.Web +{ + public class LibrarySaveShowsRequest : RequestParams + { + public LibrarySaveShowsRequest(IList ids) + { + Ensure.ArgumentNotNullOrEmptyList(ids, nameof(ids)); + + Ids = ids; + } + + [QueryParam("ids")] + public IList Ids { get; } + } +} diff --git a/SpotifyAPI.Web/Models/Request/LibrarySaveTracksRequest.cs b/SpotifyAPI.Web/Models/Request/LibrarySaveTracksRequest.cs new file mode 100644 index 00000000..93d3842b --- /dev/null +++ b/SpotifyAPI.Web/Models/Request/LibrarySaveTracksRequest.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; + +namespace SpotifyAPI.Web +{ + public class LibrarySaveTracksRequest : RequestParams + { + public LibrarySaveTracksRequest(IList ids) + { + Ensure.ArgumentNotNullOrEmptyList(ids, nameof(ids)); + + Ids = ids; + } + + [QueryParam("ids")] + public IList Ids { get; } + } +} diff --git a/SpotifyAPI.Web/Models/Request/LibraryShowsRequest.cs b/SpotifyAPI.Web/Models/Request/LibraryShowsRequest.cs new file mode 100644 index 00000000..356ada6e --- /dev/null +++ b/SpotifyAPI.Web/Models/Request/LibraryShowsRequest.cs @@ -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; } + } +} diff --git a/SpotifyAPI.Web/Models/Request/LibraryTracksRequest.cs b/SpotifyAPI.Web/Models/Request/LibraryTracksRequest.cs new file mode 100644 index 00000000..da2468f4 --- /dev/null +++ b/SpotifyAPI.Web/Models/Request/LibraryTracksRequest.cs @@ -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; } + } +} diff --git a/SpotifyAPI.Web/Models/Response/SavedAlbum.cs b/SpotifyAPI.Web/Models/Response/SavedAlbum.cs new file mode 100644 index 00000000..12bac1a3 --- /dev/null +++ b/SpotifyAPI.Web/Models/Response/SavedAlbum.cs @@ -0,0 +1,10 @@ +using System; + +namespace SpotifyAPI.Web +{ + public class SavedAlbum + { + public DateTime AddedAt { get; set; } + public FullAlbum Album { get; set; } + } +} diff --git a/SpotifyAPI.Web/Models/Response/SavedShow.cs b/SpotifyAPI.Web/Models/Response/SavedShow.cs new file mode 100644 index 00000000..97c5c4d0 --- /dev/null +++ b/SpotifyAPI.Web/Models/Response/SavedShow.cs @@ -0,0 +1,10 @@ +using System; + +namespace SpotifyAPI.Web +{ + public class SavedShow + { + public DateTime AddedAt { get; set; } + public FullShow Show { get; set; } + } +} diff --git a/SpotifyAPI.Web/Models/Response/SavedTrack.cs b/SpotifyAPI.Web/Models/Response/SavedTrack.cs new file mode 100644 index 00000000..e7a7b61e --- /dev/null +++ b/SpotifyAPI.Web/Models/Response/SavedTrack.cs @@ -0,0 +1,10 @@ +using System; + +namespace SpotifyAPI.Web +{ + public class SavedTrack + { + public DateTime AddedAt { get; set; } + public FullTrack Track { get; set; } + } +} diff --git a/SpotifyAPI.Web/SpotifyUrls.cs b/SpotifyAPI.Web/SpotifyUrls.cs index 5beedeff..f0950000 100644 --- a/SpotifyAPI.Web/SpotifyUrls.cs +++ b/SpotifyAPI.Web/SpotifyUrls.cs @@ -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); } }