From 2b5a826181fb262aee8e26f6c928532f25973e08 Mon Sep 17 00:00:00 2001 From: Jonas Dellinger Date: Sat, 2 May 2020 14:58:11 +0200 Subject: [PATCH] Added FeaturedPlaylists --- SpotifyAPI.Web.Tests/UtilTests/Test.cs | 5 +---- SpotifyAPI.Web/Clients/BrowseClient.cs | 12 ++++++++++ .../Clients/Interfaces/IBrowseClient.cs | 3 +++ .../Request/FeaturedPlaylistsRequest.cs | 22 +++++++++++++++++++ .../Models/Request/RequestParams.cs | 4 ++-- .../Response/FeaturedPlaylistsResponse.cs | 8 +++++++ SpotifyAPI.Web/SpotifyUrls.cs | 2 ++ SpotifyAPI.Web/Util/URIExtension.cs | 2 +- 8 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 SpotifyAPI.Web/Models/Request/FeaturedPlaylistsRequest.cs create mode 100644 SpotifyAPI.Web/Models/Response/FeaturedPlaylistsResponse.cs diff --git a/SpotifyAPI.Web.Tests/UtilTests/Test.cs b/SpotifyAPI.Web.Tests/UtilTests/Test.cs index 9fbf38b1..7d58d3b9 100644 --- a/SpotifyAPI.Web.Tests/UtilTests/Test.cs +++ b/SpotifyAPI.Web.Tests/UtilTests/Test.cs @@ -11,11 +11,8 @@ namespace SpotifyAPI.Web [Test] public async Task TestingYo() { - var config = SpotifyClientConfig.CreateDefault("BQAODnY4uqYj_KCddlDm10KLPDZSpZhVUtMDjdh1zfG-xd5pAV3htRjnaGfO7ob92HHzNP05a-4mDnts337gdnZlRtjrDPnuWNFx75diY540H0cD1bS9UzI5cfO27N2O6lmzKb_jAYTaRoqPKHoG93KGiXxwg4vblGKSBY1vIloP"); + var config = SpotifyClientConfig.CreateDefault(""); var spotify = new SpotifyClient(config); - - var playlists = await spotify.Browse.GetCategoryPlaylists("toplists", new CategoriesPlaylistsRequest() { Offset = 1 }); - Console.WriteLine(playlists.Playlists.Items[0].Name); } } } diff --git a/SpotifyAPI.Web/Clients/BrowseClient.cs b/SpotifyAPI.Web/Clients/BrowseClient.cs index 646d4eae..72189bea 100644 --- a/SpotifyAPI.Web/Clients/BrowseClient.cs +++ b/SpotifyAPI.Web/Clients/BrowseClient.cs @@ -75,5 +75,17 @@ namespace SpotifyAPI.Web return API.Get(URLs.NewReleases(), request.BuildQueryParams()); } + + public Task GetFeaturedPlaylists() + { + return API.Get(URLs.FeaturedPlaylists()); + } + + public Task GetFeaturedPlaylists(FeaturedPlaylistsRequest request) + { + Ensure.ArgumentNotNull(request, nameof(request)); + + return API.Get(URLs.FeaturedPlaylists(), request.BuildQueryParams()); + } } } diff --git a/SpotifyAPI.Web/Clients/Interfaces/IBrowseClient.cs b/SpotifyAPI.Web/Clients/Interfaces/IBrowseClient.cs index f46d8858..521d6f26 100644 --- a/SpotifyAPI.Web/Clients/Interfaces/IBrowseClient.cs +++ b/SpotifyAPI.Web/Clients/Interfaces/IBrowseClient.cs @@ -18,5 +18,8 @@ namespace SpotifyAPI.Web Task GetNewReleases(); Task GetNewReleases(NewReleasesRequest request); + + Task GetFeaturedPlaylists(); + Task GetFeaturedPlaylists(FeaturedPlaylistsRequest request); } } diff --git a/SpotifyAPI.Web/Models/Request/FeaturedPlaylistsRequest.cs b/SpotifyAPI.Web/Models/Request/FeaturedPlaylistsRequest.cs new file mode 100644 index 00000000..59a70c8d --- /dev/null +++ b/SpotifyAPI.Web/Models/Request/FeaturedPlaylistsRequest.cs @@ -0,0 +1,22 @@ +using System; +namespace SpotifyAPI.Web +{ + public class FeaturedPlaylistsRequest : RequestParams + { + [QueryParam("country")] + public string Country { get; set; } + [QueryParam("locale")] + public string Locale { get; set; } + [QueryParam("limit")] + public int? Limit { get; set; } + [QueryParam("offset")] + public int? Offset { get; set; } + public DateTime? Timestamp { get; set; } + + [QueryParam("timestamp")] + protected string _Timestamp + { + get => Timestamp?.ToString("o"); + } + } +} diff --git a/SpotifyAPI.Web/Models/Request/RequestParams.cs b/SpotifyAPI.Web/Models/Request/RequestParams.cs index 510db396..c6d65421 100644 --- a/SpotifyAPI.Web/Models/Request/RequestParams.cs +++ b/SpotifyAPI.Web/Models/Request/RequestParams.cs @@ -11,7 +11,7 @@ namespace SpotifyAPI.Web // Make sure everything is okay before building query params Ensure(); - var queryProps = GetType().GetProperties() + var queryProps = GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public) .Where(prop => prop.GetCustomAttributes(typeof(QueryParamAttribute), true).Length > 0); var queryParams = new Dictionary(); @@ -36,7 +36,7 @@ namespace SpotifyAPI.Web public class QueryParamAttribute : Attribute { - public string Key { get; set; } + public string Key { get; } public QueryParamAttribute() { } public QueryParamAttribute(string key) diff --git a/SpotifyAPI.Web/Models/Response/FeaturedPlaylistsResponse.cs b/SpotifyAPI.Web/Models/Response/FeaturedPlaylistsResponse.cs new file mode 100644 index 00000000..28cc5472 --- /dev/null +++ b/SpotifyAPI.Web/Models/Response/FeaturedPlaylistsResponse.cs @@ -0,0 +1,8 @@ +namespace SpotifyAPI.Web +{ + public class FeaturedPlaylistsResponse + { + public string Message { get; set; } + public Paging Playlists { get; set; } + } +} diff --git a/SpotifyAPI.Web/SpotifyUrls.cs b/SpotifyAPI.Web/SpotifyUrls.cs index 58c52741..57b11819 100644 --- a/SpotifyAPI.Web/SpotifyUrls.cs +++ b/SpotifyAPI.Web/SpotifyUrls.cs @@ -23,6 +23,8 @@ namespace SpotifyAPI.Web public static Uri NewReleases() => EUri($"browse/new-releases"); + public static Uri FeaturedPlaylists() => EUri($"browse/featured-playlists"); + private static Uri EUri(FormattableString path) => new Uri(path.ToString(_provider), UriKind.Relative); } } diff --git a/SpotifyAPI.Web/Util/URIExtension.cs b/SpotifyAPI.Web/Util/URIExtension.cs index 57c26366..daebba5b 100644 --- a/SpotifyAPI.Web/Util/URIExtension.cs +++ b/SpotifyAPI.Web/Util/URIExtension.cs @@ -28,7 +28,7 @@ namespace SpotifyAPI.Web newParameters.Add(parameter.Key, HttpUtility.UrlEncode(parameter.Value)); } - var queryString = String.Join("&", newParameters.Select((parameter) => $"{parameter.Key}={parameter.Value}")); + var queryString = string.Join("&", newParameters.Select((parameter) => $"{parameter.Key}={parameter.Value}")); var query = string.IsNullOrEmpty(queryString) ? null : $"?{queryString}"; var uriBuilder = new UriBuilder(uri)