From c9a374080b49823f5a274e3c33423e011bc301dd Mon Sep 17 00:00:00 2001 From: Jonas Dellinger Date: Sun, 3 May 2020 13:11:53 +0200 Subject: [PATCH] Added another endpoint and made sure the logger works for bodys <50 chars --- .../Clients/Interfaces/IPlaylistsClient.cs | 2 ++ SpotifyAPI.Web/Clients/PlaylistsClient.cs | 9 +++++++++ SpotifyAPI.Web/Http/SimpleHTTPLogger.cs | 3 ++- .../Request/PlaylistChangeDetailsRequest.cs | 17 +++++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 SpotifyAPI.Web/Models/Request/PlaylistChangeDetailsRequest.cs diff --git a/SpotifyAPI.Web/Clients/Interfaces/IPlaylistsClient.cs b/SpotifyAPI.Web/Clients/Interfaces/IPlaylistsClient.cs index 1d27920f..721d9c76 100644 --- a/SpotifyAPI.Web/Clients/Interfaces/IPlaylistsClient.cs +++ b/SpotifyAPI.Web/Clients/Interfaces/IPlaylistsClient.cs @@ -27,5 +27,7 @@ namespace SpotifyAPI.Web Task> CurrentUsers(); Task> CurrentUsers(PlaylistCurrentUsersRequest request); + + Task ChangeDetails(string playlistId, PlaylistChangeDetailsRequest request); } } diff --git a/SpotifyAPI.Web/Clients/PlaylistsClient.cs b/SpotifyAPI.Web/Clients/PlaylistsClient.cs index d26cfb4d..80204d0e 100644 --- a/SpotifyAPI.Web/Clients/PlaylistsClient.cs +++ b/SpotifyAPI.Web/Clients/PlaylistsClient.cs @@ -117,5 +117,14 @@ namespace SpotifyAPI.Web return API.Get>(URLs.CurrentUserPlaylists(), request.BuildQueryParams()); } + + public async Task 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()); + return statusCode == HttpStatusCode.OK; + } } } diff --git a/SpotifyAPI.Web/Http/SimpleHTTPLogger.cs b/SpotifyAPI.Web/Http/SimpleHTTPLogger.cs index bf3a79be..8fb83cf9 100644 --- a/SpotifyAPI.Web/Http/SimpleHTTPLogger.cs +++ b/SpotifyAPI.Web/Http/SimpleHTTPLogger.cs @@ -17,7 +17,8 @@ namespace SpotifyAPI.Web.Http public void OnResponse(IResponse response) { - string body = response.Body?.ToString().Substring(0, 50).Replace("\n", ""); + string body = response.Body?.ToString().Replace("\n", ""); + body = body?.Substring(0, Math.Min(50, body?.Length ?? 0)); Console.WriteLine("--> {0} {1} {2}\n", response.StatusCode, response.ContentType, body); } } diff --git a/SpotifyAPI.Web/Models/Request/PlaylistChangeDetailsRequest.cs b/SpotifyAPI.Web/Models/Request/PlaylistChangeDetailsRequest.cs new file mode 100644 index 00000000..82ec1062 --- /dev/null +++ b/SpotifyAPI.Web/Models/Request/PlaylistChangeDetailsRequest.cs @@ -0,0 +1,17 @@ +namespace SpotifyAPI.Web +{ + public class PlaylistChangeDetailsRequest : RequestParams + { + [BodyParam("name")] + public string Name { get; set; } + + [BodyParam("public")] + public bool? Public { get; set; } + + [BodyParam("collaborative")] + public bool? Collaborative { get; set; } + + [BodyParam("description")] + public string Description { get; set; } + } +}