diff --git a/src/SpotifyApi.NetCore.Tests/BrowseApiTests.cs b/src/SpotifyApi.NetCore.Tests/BrowseApiTests.cs index 5a1a974..6f3b5f5 100644 --- a/src/SpotifyApi.NetCore.Tests/BrowseApiTests.cs +++ b/src/SpotifyApi.NetCore.Tests/BrowseApiTests.cs @@ -12,6 +12,71 @@ namespace SpotifyApi.NetCore.Tests [TestClass] public class BrowseApiTests { + [TestMethod] + [TestCategory("Integration")] + public async Task GetCategories_Limit2_ItemsLength2() + { + // arrange + var http = new HttpClient(); + var accounts = new AccountsService(http, TestsHelper.GetLocalConfig()); + + var api = new BrowseApi(http, accounts); + + // act + var response = await api.GetCategories(limit:2); + Assert.AreEqual(2, response.Items.Length); + } + + [TestMethod] + [TestCategory("Integration")] + public async Task GetCategory_FromNZCategories_SameCategoryHref() + { + // arrange + var http = new HttpClient(); + var accounts = new AccountsService(http, TestsHelper.GetLocalConfig()); + + var api = new BrowseApi(http, accounts); + var category = (await api.GetCategories(limit: 1, country:SpotifyCountryCodes.New_Zealand)).Items[0]; + + // act + var response = await api.GetCategory(category.Id, country:SpotifyCountryCodes.New_Zealand); + + Assert.AreEqual(category.Href, response.Href); + } + + [TestMethod] + [TestCategory("Integration")] + public async Task GetCategoryPlaylists_FromFirstNZCategoryLimit2_ItemsLength2() + { + // arrange + var http = new HttpClient(); + var accounts = new AccountsService(http, TestsHelper.GetLocalConfig()); + + var api = new BrowseApi(http, accounts); + var category = (await api.GetCategories(limit: 1, country: SpotifyCountryCodes.New_Zealand)).Items[0]; + + // act + var response = await api.GetCategoryPlaylists(category.Id, country: SpotifyCountryCodes.New_Zealand, limit: 2); + + Assert.AreEqual(2, response.Items.Length); + } + + [TestMethod] + [TestCategory("Integration")] + public async Task GetFeaturedPlaylists_Limit2_ItemsLength2() + { + // arrange + var http = new HttpClient(); + var accounts = new AccountsService(http, TestsHelper.GetLocalConfig()); + + var api = new BrowseApi(http, accounts); + + // act + var response = await api.GetFeaturedPlaylists(country: SpotifyCountryCodes.New_Zealand, limit: 2); + + Assert.AreEqual(2, response.Items.Length); + } + [TestMethod] [TestCategory("Integration")] public async Task GetNewReleases_NoParams_NoError() diff --git a/src/SpotifyApi.NetCore.Tests/Extensions/UriBuilderExtensionTests.cs b/src/SpotifyApi.NetCore.Tests/Extensions/UriBuilderExtensionTests.cs index ea8a77e..ef7ef0f 100644 --- a/src/SpotifyApi.NetCore.Tests/Extensions/UriBuilderExtensionTests.cs +++ b/src/SpotifyApi.NetCore.Tests/Extensions/UriBuilderExtensionTests.cs @@ -144,5 +144,18 @@ public void AppendToQueryAsCsv_ThreeValues_WellFormed() Assert.AreEqual("?numbers=1,2,3", builder.Uri.Query); } + [TestMethod] + public void AppendToQueryAsTimestampIso8601_DateTime_ExpectedFormat() + { + // arrange + var builder = new UriBuilder("https://api.spotify.com/v1/browse/featured-playlists"); + + // act + builder.AppendToQueryAsTimestampIso8601("timestamp", new DateTime(2014, 10, 23, 9, 0, 0)); + + // assert + Assert.AreEqual("?timestamp=2014-10-23T09:00:00", builder.Uri.Query); + } + } } diff --git a/src/SpotifyApi.NetCore/BrowseApi.cs b/src/SpotifyApi.NetCore/BrowseApi.cs index 13e414a..1913a49 100644 --- a/src/SpotifyApi.NetCore/BrowseApi.cs +++ b/src/SpotifyApi.NetCore/BrowseApi.cs @@ -232,12 +232,10 @@ public async Task GetCategoryPlaylists( /// in a particular language. Note that, if locale is not supplied, or if the specified language /// is not available, the category strings returned will be in the Spotify default language /// (American English). - /// Optional. A timestamp in ISO 8601 format: yyyy-MM-ddTHH:mm:ss. - /// Use this parameter to specify the user’s local time to get results tailored for that specific - /// date and time in the day. If not provided, the response defaults to the current UTC time. - /// Example: “2014-10-23T09:00:00” for a user whose local time is 9AM. If there were no featured - /// playlists (or there is no data) at the specified time, the response will revert to the - /// current UTC time. + /// Optional. Use this parameter to specify the user’s local time to + /// get results tailored for that specific date and time in the day. If not provided, the response + /// defaults to the current UTC time. If there were no featured playlists (or there is no data) + /// at the specified time, the response will revert to the current UTC time. /// Optional. Maximum number of results to return. Default: 20, Minimum: 1, /// Maximum: 50. /// Optional. The index of the first result to return. Default: 0 (the @@ -249,7 +247,7 @@ public async Task GetCategoryPlaylists( public Task GetFeaturedPlaylists( string country = null, string locale = null, - string timestamp = null, + DateTime? timestamp = null, int? limit = null, int offset = 0, string accessToken = null) => GetFeaturedPlaylists( @@ -272,12 +270,10 @@ public Task GetFeaturedPlaylists( /// in a particular language. Note that, if locale is not supplied, or if the specified language /// is not available, the category strings returned will be in the Spotify default language /// (American English). - /// Optional. A timestamp in ISO 8601 format: yyyy-MM-ddTHH:mm:ss. - /// Use this parameter to specify the user’s local time to get results tailored for that specific - /// date and time in the day. If not provided, the response defaults to the current UTC time. - /// Example: “2014-10-23T09:00:00” for a user whose local time is 9AM. If there were no featured - /// playlists (or there is no data) at the specified time, the response will revert to the - /// current UTC time. + /// Optional. Use this parameter to specify the user’s local time to + /// get results tailored for that specific date and time in the day. If not provided, the response + /// defaults to the current UTC time. If there were no featured playlists (or there is no data) + /// at the specified time, the response will revert to the current UTC time. /// Optional. Maximum number of results to return. Default: 20, Minimum: 1, /// Maximum: 50. /// Optional. The index of the first result to return. Default: 0 (the @@ -288,8 +284,8 @@ public Task GetFeaturedPlaylists( /// https://developer.spotify.com/documentation/web-api/reference/browse/get-list-featured-playlists/ public async Task GetFeaturedPlaylists( string country = null, - string locale = null, - string timestamp = null, + string locale = null, + DateTime? timestamp = null, int? limit = null, int offset = 0, string accessToken = null) @@ -297,7 +293,7 @@ public async Task GetFeaturedPlaylists( var builder = new UriBuilder($"{BaseUrl}/browse/featured-playlists"); builder.AppendToQueryIfValueNotNullOrWhiteSpace("country", country); builder.AppendToQueryIfValueNotNullOrWhiteSpace("locale", locale); - builder.AppendToQueryIfValueNotNullOrWhiteSpace("timestamp", timestamp); + builder.AppendToQueryAsTimestampIso8601("timestamp", timestamp); builder.AppendToQueryIfValueGreaterThan0("limit", limit); builder.AppendToQueryIfValueGreaterThan0("offset", offset); return await GetModelFromProperty(builder.Uri, "playlists", accessToken: accessToken); diff --git a/src/SpotifyApi.NetCore/Extensions/UriBuilderExtensions.cs b/src/SpotifyApi.NetCore/Extensions/UriBuilderExtensions.cs index 3cd1b29..0b8cb68 100644 --- a/src/SpotifyApi.NetCore/Extensions/UriBuilderExtensions.cs +++ b/src/SpotifyApi.NetCore/Extensions/UriBuilderExtensions.cs @@ -1,4 +1,5 @@ using System; +using System.Globalization; namespace SpotifyApi.NetCore { @@ -42,5 +43,10 @@ public static void AppendToQueryIfValueNotNullOrWhiteSpace( { if (!string.IsNullOrWhiteSpace(value)) AppendToQuery(builder, name, value); } + + public static void AppendToQueryAsTimestampIso8601(this UriBuilder builder, string name, DateTime? timestamp) + { + if (timestamp.HasValue) AppendToQuery(builder, name, timestamp.Value.ToString("s", CultureInfo.InvariantCulture)); + } } } diff --git a/src/SpotifyApi.NetCore/IBrowseApi.cs b/src/SpotifyApi.NetCore/IBrowseApi.cs index 6cbd5aa..691867b 100644 --- a/src/SpotifyApi.NetCore/IBrowseApi.cs +++ b/src/SpotifyApi.NetCore/IBrowseApi.cs @@ -1,3 +1,4 @@ +using System; using System.Threading.Tasks; namespace SpotifyApi.NetCore @@ -157,12 +158,10 @@ Task GetCategoryPlaylists( /// in a particular language. Note that, if locale is not supplied, or if the specified language /// is not available, the category strings returned will be in the Spotify default language /// (American English). - /// Optional. A timestamp in ISO 8601 format: yyyy-MM-ddTHH:mm:ss. - /// Use this parameter to specify the user’s local time to get results tailored for that specific - /// date and time in the day. If not provided, the response defaults to the current UTC time. - /// Example: “2014-10-23T09:00:00” for a user whose local time is 9AM. If there were no featured - /// playlists (or there is no data) at the specified time, the response will revert to the - /// current UTC time. + /// Optional. Use this parameter to specify the user’s local time to + /// get results tailored for that specific date and time in the day. If not provided, the response + /// defaults to the current UTC time. If there were no featured playlists (or there is no data) + /// at the specified time, the response will revert to the current UTC time. /// Optional. Maximum number of results to return. Default: 20, Minimum: 1, /// Maximum: 50. /// Optional. The index of the first result to return. Default: 0 (the @@ -174,7 +173,7 @@ Task GetCategoryPlaylists( Task GetFeaturedPlaylists( string country = null, string locale = null, - string timestamp = null, + DateTime? timestamp = null, int? limit = null, int offset = 0, string accessToken = null); @@ -191,12 +190,10 @@ Task GetFeaturedPlaylists( /// in a particular language. Note that, if locale is not supplied, or if the specified language /// is not available, the category strings returned will be in the Spotify default language /// (American English). - /// Optional. A timestamp in ISO 8601 format: yyyy-MM-ddTHH:mm:ss. - /// Use this parameter to specify the user’s local time to get results tailored for that specific - /// date and time in the day. If not provided, the response defaults to the current UTC time. - /// Example: “2014-10-23T09:00:00” for a user whose local time is 9AM. If there were no featured - /// playlists (or there is no data) at the specified time, the response will revert to the - /// current UTC time. + /// Optional. Use this parameter to specify the user’s local time to + /// get results tailored for that specific date and time in the day. If not provided, the response + /// defaults to the current UTC time. If there were no featured playlists (or there is no data) + /// at the specified time, the response will revert to the current UTC time. /// Optional. Maximum number of results to return. Default: 20, Minimum: 1, /// Maximum: 50. /// Optional. The index of the first result to return. Default: 0 (the @@ -208,7 +205,7 @@ Task GetFeaturedPlaylists( Task GetFeaturedPlaylists( string country = null, string locale = null, - string timestamp = null, + DateTime? timestamp = null, int? limit = null, int offset = 0, string accessToken = null); diff --git a/src/SpotifyApi.NetCore/Models/PagedPlaylists.cs b/src/SpotifyApi.NetCore/Models/PagedPlaylists.cs index 7e4fefa..2c10337 100644 --- a/src/SpotifyApi.NetCore/Models/PagedPlaylists.cs +++ b/src/SpotifyApi.NetCore/Models/PagedPlaylists.cs @@ -2,7 +2,7 @@ namespace SpotifyApi.NetCore { - public class PagedPlaylists : Paged + public class PagedPlaylists : Paged { } } diff --git a/src/SpotifyApi.NetCore/SpotifyApi.NetCore.csproj b/src/SpotifyApi.NetCore/SpotifyApi.NetCore.csproj index 2c09272..c7068f5 100644 --- a/src/SpotifyApi.NetCore/SpotifyApi.NetCore.csproj +++ b/src/SpotifyApi.NetCore/SpotifyApi.NetCore.csproj @@ -4,7 +4,7 @@ SpotifyApi.NetCore Spotify Web API .NET Core Lightweight .NET Core client wrapper for the Spotify Web API - 3.1.0-preview + 3.1.0 Daniel Larsen and contributors Ringobot Copyright 2020 Daniel Larsen and contributors