mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2024-12-25 23:46:27 +00:00
137 lines
5.1 KiB
C#
137 lines
5.1 KiB
C#
using System.Collections.Generic;
|
|
using System.Net;
|
|
using System.Threading.Tasks;
|
|
using SpotifyAPI.Web.Http;
|
|
using URLs = SpotifyAPI.Web.SpotifyUrls;
|
|
|
|
namespace SpotifyAPI.Web
|
|
{
|
|
public class PlaylistsClient : APIClient, IPlaylistsClient
|
|
{
|
|
public PlaylistsClient(IAPIConnector connector) : base(connector) { }
|
|
|
|
public Task<SnapshotResponse> RemoveItems(string playlistId, PlaylistRemoveItemsRequest request)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(playlistId, nameof(playlistId));
|
|
Ensure.ArgumentNotNull(request, nameof(request));
|
|
|
|
return API.Delete<SnapshotResponse>(URLs.PlaylistTracks(playlistId), null, request.BuildBodyParams());
|
|
}
|
|
|
|
public Task<SnapshotResponse> AddItems(string playlistId, PlaylistAddItemsRequest request)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(playlistId, nameof(playlistId));
|
|
Ensure.ArgumentNotNull(request, nameof(request));
|
|
|
|
return API.Post<SnapshotResponse>(URLs.PlaylistTracks(playlistId), null, request.BuildBodyParams());
|
|
}
|
|
|
|
public Task<Paging<PlaylistTrack<BasePlayableItem>>> GetItems(string playlistId)
|
|
{
|
|
var request = new PlaylistGetItemsRequest();
|
|
|
|
return GetItems(playlistId, request);
|
|
}
|
|
|
|
public Task<Paging<PlaylistTrack<BasePlayableItem>>> GetItems(string playlistId, PlaylistGetItemsRequest request)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(playlistId, nameof(playlistId));
|
|
Ensure.ArgumentNotNull(request, nameof(request));
|
|
|
|
return API.Get<Paging<PlaylistTrack<BasePlayableItem>>>(URLs.PlaylistTracks(playlistId), request.BuildQueryParams());
|
|
}
|
|
|
|
public Task<FullPlaylist> Create(string userId, PlaylistCreateRequest request)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(userId, nameof(userId));
|
|
Ensure.ArgumentNotNull(request, nameof(request));
|
|
|
|
return API.Post<FullPlaylist>(URLs.UserPlaylists(userId), null, request.BuildBodyParams());
|
|
}
|
|
|
|
public async Task<bool> UploadCover(string playlistId, string base64JpgData)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(playlistId, nameof(playlistId));
|
|
Ensure.ArgumentNotNullOrEmptyString(base64JpgData, nameof(base64JpgData));
|
|
|
|
var statusCode = await API.PutRaw(URLs.PlaylistImages(playlistId), null, base64JpgData).ConfigureAwait(false);
|
|
return statusCode == HttpStatusCode.Accepted;
|
|
}
|
|
|
|
public Task<List<Image>> GetCovers(string playlistId)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(playlistId, nameof(playlistId));
|
|
|
|
return API.Get<List<Image>>(URLs.PlaylistImages(playlistId));
|
|
}
|
|
|
|
public Task<Paging<SimplePlaylist>> GetUsers(string userId)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(userId, nameof(userId));
|
|
|
|
return API.Get<Paging<SimplePlaylist>>(URLs.UserPlaylists(userId));
|
|
}
|
|
|
|
public Task<Paging<SimplePlaylist>> GetUsers(string userId, PlaylistGetUsersRequest request)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(userId, nameof(userId));
|
|
Ensure.ArgumentNotNull(request, nameof(request));
|
|
|
|
return API.Get<Paging<SimplePlaylist>>(URLs.UserPlaylists(userId), request.BuildQueryParams());
|
|
}
|
|
|
|
public Task<FullPlaylist> Get(string playlistId)
|
|
{
|
|
var request = new PlaylistGetRequest(); // We need some defaults
|
|
|
|
return Get(playlistId, request);
|
|
}
|
|
|
|
public Task<FullPlaylist> Get(string playlistId, PlaylistGetRequest request)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(playlistId, nameof(playlistId));
|
|
Ensure.ArgumentNotNull(request, nameof(request));
|
|
|
|
return API.Get<FullPlaylist>(URLs.Playlist(playlistId), request.BuildQueryParams());
|
|
}
|
|
|
|
public async Task<bool> ReplaceItems(string playlistId, PlaylistReplaceItemsRequest request)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(playlistId, nameof(playlistId));
|
|
Ensure.ArgumentNotNull(request, nameof(request));
|
|
|
|
var statusCode = await API.Put(URLs.PlaylistTracks(playlistId), null, request.BuildBodyParams()).ConfigureAwait(false);
|
|
return statusCode == HttpStatusCode.Created;
|
|
}
|
|
|
|
public Task<Paging<SimplePlaylist>> CurrentUsers()
|
|
{
|
|
return API.Get<Paging<SimplePlaylist>>(URLs.CurrentUserPlaylists());
|
|
}
|
|
|
|
public Task<Paging<SimplePlaylist>> CurrentUsers(PlaylistCurrentUsersRequest request)
|
|
{
|
|
Ensure.ArgumentNotNull(request, nameof(request));
|
|
|
|
return API.Get<Paging<SimplePlaylist>>(URLs.CurrentUserPlaylists(), request.BuildQueryParams());
|
|
}
|
|
|
|
public async Task<bool> ChangeDetails(string playlistId, PlaylistChangeDetailsRequest request)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(playlistId, nameof(playlistId));
|
|
Ensure.ArgumentNotNull(request, nameof(request));
|
|
|
|
var statusCode = await API.Put(URLs.Playlist(playlistId), null, request.BuildBodyParams()).ConfigureAwait(false);
|
|
return statusCode == HttpStatusCode.OK;
|
|
}
|
|
|
|
public Task<SnapshotResponse> ReorderItems(string playlistId, PlaylistReorderItemsRequest request)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(playlistId, nameof(playlistId));
|
|
Ensure.ArgumentNotNull(request, nameof(request));
|
|
|
|
return API.Put<SnapshotResponse>(URLs.PlaylistTracks(playlistId), null, request.BuildBodyParams());
|
|
}
|
|
}
|
|
}
|