From ede69d6380434bd17bff107bdb7a1e54095fe6b9 Mon Sep 17 00:00:00 2001 From: "Johnny Dellinger @PC" Date: Wed, 15 Jul 2015 17:35:32 +0200 Subject: [PATCH] Rearranged Web-API methods --- SpotifyAPI/Web/SpotifyWebAPI.cs | 600 ++++++++++++++++---------------- 1 file changed, 308 insertions(+), 292 deletions(-) diff --git a/SpotifyAPI/Web/SpotifyWebAPI.cs b/SpotifyAPI/Web/SpotifyWebAPI.cs index 21e6c3c5..ae1c728f 100644 --- a/SpotifyAPI/Web/SpotifyWebAPI.cs +++ b/SpotifyAPI/Web/SpotifyWebAPI.cs @@ -37,30 +37,236 @@ namespace SpotifyAPI.Web WebClient.Dispose(); } - #region User + #region Albums /// - /// Get detailed profile information about the current user (including the current user’s username). + /// Get Spotify catalog information about an album’s tracks. Optional parameters can be used to limit the number of tracks returned. /// + /// The Spotify ID for the album. + /// The maximum number of items to return. Default: 20. Minimum: 1. Maximum: 50. + /// The index of the first track to return. Default: 0 (the first object). + /// An ISO 3166-1 alpha-2 country code. Provide this parameter if you want to apply Track Relinking. /// - /// Needs Authorization - public PrivateProfile GetPrivateProfile() + public Paging GetAlbumTracks(String id, int limit = 20, int offset = 0, String market = "") + { + limit = Math.Min(limit, 50); + StringBuilder builder = new StringBuilder(APIBase + "/albums/" + id + "/tracks"); + builder.Append("?limit=" + limit); + builder.Append("&offset=" + offset); + if (market != "") + builder.Append("&market=" + market); + return DownloadData>(builder.ToString()); + } + + /// + /// Get Spotify catalog information for a single album. + /// + /// The Spotify ID for the album. + /// An ISO 3166-1 alpha-2 country code. Provide this parameter if you want to apply Track Relinking. + /// + public FullAlbum GetAlbum(String id, String market = "") + { + if (market == "") + return DownloadData(APIBase + "/albums/" + id); + return DownloadData(APIBase + "/albums/" + id + "?market=" + market); + } + + /// + /// Get Spotify catalog information for multiple albums identified by their Spotify IDs. + /// + /// A list of the Spotify IDs for the albums. Maximum: 20 IDs. + /// An ISO 3166-1 alpha-2 country code. Provide this parameter if you want to apply Track Relinking. + /// + public SeveralAlbums GetSeveralAlbums(List ids, String market = "") + { + if (market == "") + return DownloadData(APIBase + "/albums?ids=" + string.Join(",", ids.Take(20))); + return DownloadData(APIBase + "/albums?market=" + market + "&ids=" + string.Join(",", ids.Take(20))); + } + + #endregion + + #region Artists + + /// + /// Get Spotify catalog information for a single artist identified by their unique Spotify ID. + /// + /// The Spotify ID for the artist. + /// + public FullArtist GetArtist(String id) + { + return DownloadData(APIBase + "/artists/" + id); + } + + /// + /// Get Spotify catalog information about artists similar to a given artist. Similarity is based on analysis of the + /// Spotify community’s listening history. + /// + /// The Spotify ID for the artist. + /// + public SeveralArtists GetRelatedArtists(String id) + { + return DownloadData(APIBase + "/artists/" + id + "/related-artists"); + } + + /// + /// Get Spotify catalog information about an artist’s top tracks by country. + /// + /// The Spotify ID for the artist. + /// The country: an ISO 3166-1 alpha-2 country code. + /// + public SeveralTracks GetArtistsTopTracks(String id, String country) + { + return DownloadData(APIBase + "/artists/" + id + "/top-tracks?country=" + country); + } + + /// + /// Get Spotify catalog information about an artist’s albums. Optional parameters can be specified in the query string to filter and sort the response. + /// + /// The Spotify ID for the artist. + /// A list of keywords that will be used to filter the response. If not supplied, all album types will be returned + /// The maximum number of items to return. Default: 20. Minimum: 1. Maximum: 50. + /// The index of the first album to return. Default: 0 + /// An ISO 3166-1 alpha-2 country code. Supply this parameter to limit the response to one particular geographical market + /// + public Paging GetArtistsAlbums(String id, AlbumType type = AlbumType.All, int limit = 20, int offset = 0, String market = "") + { + limit = Math.Min(limit, 50); + StringBuilder builder = new StringBuilder(APIBase + "/artists/" + id + "/albums"); + builder.Append("?type=" + type.GetStringAttribute(",")); + builder.Append("&limit=" + limit); + builder.Append("&offset=" + offset); + if (market != "") + builder.Append("&market=" + market); + return DownloadData>(builder.ToString()); + } + + /// + /// Get Spotify catalog information for several artists based on their Spotify IDs. + /// + /// A list of the Spotify IDs for the artists. Maximum: 50 IDs. + /// + public SeveralArtists GetSeveralArtists(List ids) + { + return DownloadData(APIBase + "/artists?ids=" + string.Join(",", ids.Take(50))); + } + + #endregion + + #region Browse + + /// + /// Get a list of Spotify featured playlists (shown, for example, on a Spotify player’s “Browse” tab). + /// + /// + /// The desired language, consisting of a lowercase ISO 639 language code and an uppercase ISO 3166-1 + /// alpha-2 country code, joined by an underscore. + /// + /// A country: an ISO 3166-1 alpha-2 country code. + /// A timestamp in ISO 8601 format + /// The maximum number of items to return. Default: 20. Minimum: 1. Maximum: 50. + /// The index of the first item to return. Default: 0 + /// + public FeaturedPlaylists GetFeaturedPlaylists(String locale = "", String country = "", DateTime timestamp = default(DateTime), int limit = 20, int offset = 0) { if (!UseAuth) - throw new InvalidOperationException("Auth is required for GetPrivateProfile"); - return DownloadData(APIBase + "/me"); + throw new InvalidOperationException("Auth is required for GetFeaturedPlaylists"); + limit = Math.Max(limit, 50); + StringBuilder builder = new StringBuilder(APIBase + "/browse/featured-playlists"); + builder.Append("?limit=" + limit); + builder.Append("&offset=" + offset); + if (locale != "") + builder.Append("&locale=" + locale); + if (country != "") + builder.Append("&country=" + country); + if (timestamp != default(DateTime)) + builder.Append("×tamp=" + timestamp.ToString("yyyy-MM-ddTHH:mm:ss")); + return DownloadData(builder.ToString()); } /// - /// Get public profile information about a Spotify user. + /// Get a list of new album releases featured in Spotify (shown, for example, on a Spotify player’s “Browse” tab). /// - /// The user's Spotify user ID. + /// A country: an ISO 3166-1 alpha-2 country code. + /// The maximum number of items to return. Default: 20. Minimum: 1. Maximum: 50. + /// The index of the first item to return. Default: 0 /// - public PublicProfile GetPublicProfile(String userId) + public NewAlbumReleases GetNewAlbumReleases(String country = "", int limit = 20, int offset = 0) { - return DownloadData(APIBase + "/users/" + userId); + if (!UseAuth) + throw new InvalidOperationException("Auth is required for GetNewAlbumReleases"); + limit = Math.Max(limit, 50); + StringBuilder builder = new StringBuilder(APIBase + "/browse/new-releases"); + builder.Append("?limit=" + limit); + builder.Append("&offset=" + offset); + if (country != "") + builder.Append("&country=" + country); + return DownloadData(builder.ToString()); } + /// + /// Get a list of categories used to tag items in Spotify (on, for example, the Spotify player’s “Browse” tab). + /// + /// A country: an ISO 3166-1 alpha-2 country code. Provide this parameter if you want to narrow the list of returned categories to those relevant to a particular country + /// The desired language, consisting of an ISO 639 language code and an ISO 3166-1 alpha-2 country code, joined by an underscore + /// The maximum number of categories to return. Default: 20. Minimum: 1. Maximum: 50. + /// The index of the first item to return. Default: 0 (the first object). + /// + public CategoryList GetCategories(String country = "", String locale = "", int limit = 20, int offset = 0) + { + if (!UseAuth) + throw new InvalidOperationException("Auth is required for GetCategories"); + limit = Math.Min(50, limit); + StringBuilder builder = new StringBuilder(APIBase + "/browse/categories"); + builder.Append("?limit=" + limit); + builder.Append("&offset=" + offset); + if (country != "") + builder.Append("&country=" + country); + if (locale != "") + builder.Append("&locale=" + locale); + return DownloadData(builder.ToString()); + } + + /// + /// Get a single category used to tag items in Spotify (on, for example, the Spotify player’s “Browse” tab). + /// + /// The Spotify category ID for the category. + /// A country: an ISO 3166-1 alpha-2 country code. Provide this parameter to ensure that the category exists for a particular country. + /// The desired language, consisting of an ISO 639 language code and an ISO 3166-1 alpha-2 country code, joined by an underscore + /// + public Category GetCategory(String categoryId, String country = "", String locale = "") + { + StringBuilder builder = new StringBuilder(APIBase + "/browse/categories/" + categoryId); + if (country != "") + builder.Append("?country=" + country); + if (locale != "") + builder.Append((country == "" ? "?locale=" : "&locale=") + locale); + return DownloadData(builder.ToString()); + } + + /// + /// Get a list of Spotify playlists tagged with a particular category. + /// + /// The Spotify category ID for the category. + /// A country: an ISO 3166-1 alpha-2 country code. + /// The maximum number of items to return. Default: 20. Minimum: 1. Maximum: 50. + /// The index of the first item to return. Default: 0 + /// + public CategoryPlaylist GetCategoryPlaylists(String categoryId, String country = "", int limit = 20, int offset = 0) + { + limit = Math.Min(50, limit); + StringBuilder builder = new StringBuilder(APIBase + "/browse/categories/" + categoryId + "/playlists"); + builder.Append("?limit=" + limit); + builder.Append("&offset=" + offset); + if (country != "") + builder.Append("&country=" + country); + return DownloadData(builder.ToString()); + } + + #endregion + + #region Follow + /// /// Add the current user as a follower of one or more artists or other Spotify users. /// @@ -86,7 +292,7 @@ namespace SpotifyAPI.Web /// Needs Authorization public ErrorResponse Follow(FollowType followType, String id) { - return Follow(followType, new List {id}); + return Follow(followType, new List { id }); } /// @@ -114,7 +320,7 @@ namespace SpotifyAPI.Web /// Needs Authorization public ErrorResponse Unfollow(FollowType followType, String id) { - return Unfollow(followType, new List {id}); + return Unfollow(followType, new List { id }); } /// @@ -130,8 +336,8 @@ namespace SpotifyAPI.Web throw new InvalidOperationException("Auth is required for IsFollowing"); JToken res = DownloadData(APIBase + "/me/following/contains?type=" + followType.GetStringAttribute("") + "&ids=" + string.Join(",", ids)); if (res is JArray) - return new ListResponse {List = res.ToObject>(), Error = null}; - return new ListResponse {List = null, Error = res["error"].ToObject()}; + return new ListResponse { List = res.ToObject>(), Error = null }; + return new ListResponse { List = null, Error = res["error"].ToObject() }; } /// @@ -143,12 +349,74 @@ namespace SpotifyAPI.Web /// Needs Authorization public ListResponse IsFollowing(FollowType followType, String id) { - return IsFollowing(followType, new List {id}); + return IsFollowing(followType, new List { id }); + } + + /// + /// Add the current user as a follower of a playlist. + /// + /// The Spotify user ID of the person who owns the playlist. + /// + /// The Spotify ID of the playlist. Any playlist can be followed, regardless of its public/private + /// status, as long as you know its playlist ID. + /// + /// + /// If true the playlist will be included in user's public playlists, if false it will remain + /// private. + /// + /// + public ErrorResponse FollowPlaylist(String ownerId, String playlistId, bool showPublic = true) + { + JObject body = new JObject + { + {"public", showPublic} + }; + return UploadData(APIBase + "/users/" + ownerId + "/playlists/" + playlistId + "/followers", body.ToString(Formatting.None), "PUT"); + } + + /// + /// Remove the current user as a follower of a playlist. + /// + /// The Spotify user ID of the person who owns the playlist. + /// The Spotify ID of the playlist that is to be no longer followed. + /// + public ErrorResponse UnfollowPlaylist(String ownerId, String playlistId) + { + return UploadData(APIBase + "/users/" + ownerId + "/playlists/" + playlistId + "/followers", "", "DELETE"); + } + + /// + /// Check to see if one or more Spotify users are following a specified playlist. + /// + /// The Spotify user ID of the person who owns the playlist. + /// The Spotify ID of the playlist. + /// A list of Spotify User IDs + /// + public ListResponse IsFollowingPlaylist(String ownerId, String playlistId, List ids) + { + if (!UseAuth) + throw new InvalidOperationException("Auth is required for IsFollowingPlaylist"); + JToken res = DownloadData(APIBase + "/users/" + ownerId + "/playlists/" + playlistId + "/followers/contains?ids=" + string.Join(",", ids)); + if (res is JArray) + return new ListResponse { List = res.ToObject>(), Error = null }; + return new ListResponse { List = null, Error = res["error"].ToObject() }; + } + + /// + /// Check to see if one or more Spotify users are following a specified playlist. + /// + /// The Spotify user ID of the person who owns the playlist. + /// The Spotify ID of the playlist. + /// A Spotify User ID + /// + public ListResponse IsFollowingPlaylist(String ownerId, String playlistId, String id) + { + return IsFollowingPlaylist(ownerId, playlistId, new List { id }); } #endregion - #region User-Library + #region Library /// /// Save one or more tracks to the current user’s “Your Music” library. @@ -170,7 +438,7 @@ namespace SpotifyAPI.Web /// Needs Authorization public ErrorResponse SaveTrack(String id) { - return SaveTracks(new List {id}); + return SaveTracks(new List { id }); } /// @@ -218,13 +486,13 @@ namespace SpotifyAPI.Web throw new InvalidOperationException("Auth is required for CheckSavedTracks"); JToken res = DownloadData(APIBase + "/me/tracks/contains?ids=" + string.Join(",", ids)); if (res is JArray) - return new ListResponse {List = res.ToObject>(), Error = null}; - return new ListResponse {List = null, Error = res["error"].ToObject()}; + return new ListResponse { List = res.ToObject>(), Error = null }; + return new ListResponse { List = null, Error = res["error"].ToObject() }; } #endregion - #region Playlist + #region Playlists /// /// Get a list of the playlists owned or followed by a Spotify user. @@ -378,7 +646,7 @@ namespace SpotifyAPI.Web /// public ErrorResponse RemovePlaylistTrack(String userId, String playlistId, DeleteTrackUri uri) { - return RemovePlaylistTracks(userId, playlistId, new List {uri}); + return RemovePlaylistTracks(userId, playlistId, new List { uri }); } /// @@ -410,7 +678,7 @@ namespace SpotifyAPI.Web /// public ErrorResponse AddPlaylistTrack(String userId, String playlistId, String uri, int? position = null) { - return AddPlaylistTracks(userId, playlistId, new List {uri}, position); + return AddPlaylistTracks(userId, playlistId, new List { uri }, position); } /// @@ -437,120 +705,35 @@ namespace SpotifyAPI.Web return UploadData(APIBase + "/users/" + userId + "/playlists/" + playlistId + "/tracks", body.ToString(Formatting.None), "PUT"); } + #endregion + + #region Profiles + /// - /// Get a list of Spotify featured playlists (shown, for example, on a Spotify player’s “Browse” tab). + /// Get detailed profile information about the current user (including the current user’s username). /// - /// - /// The desired language, consisting of a lowercase ISO 639 language code and an uppercase ISO 3166-1 - /// alpha-2 country code, joined by an underscore. - /// - /// A country: an ISO 3166-1 alpha-2 country code. - /// A timestamp in ISO 8601 format - /// The maximum number of items to return. Default: 20. Minimum: 1. Maximum: 50. - /// The index of the first item to return. Default: 0 /// - public FeaturedPlaylists GetFeaturedPlaylists(String locale = "", String country = "", DateTime timestamp = default(DateTime), int limit = 20, int offset = 0) + /// Needs Authorization + public PrivateProfile GetPrivateProfile() { if (!UseAuth) - throw new InvalidOperationException("Auth is required for GetFeaturedPlaylists"); - limit = Math.Max(limit, 50); - StringBuilder builder = new StringBuilder(APIBase + "/browse/featured-playlists"); - builder.Append("?limit=" + limit); - builder.Append("&offset=" + offset); - if (locale != "") - builder.Append("&locale=" + locale); - if (country != "") - builder.Append("&country=" + country); - if (timestamp != default(DateTime)) - builder.Append("×tamp=" + timestamp.ToString("yyyy-MM-ddTHH:mm:ss")); - return DownloadData(builder.ToString()); + throw new InvalidOperationException("Auth is required for GetPrivateProfile"); + return DownloadData(APIBase + "/me"); } /// - /// Get a list of new album releases featured in Spotify (shown, for example, on a Spotify player’s “Browse” tab). + /// Get public profile information about a Spotify user. /// - /// A country: an ISO 3166-1 alpha-2 country code. - /// The maximum number of items to return. Default: 20. Minimum: 1. Maximum: 50. - /// The index of the first item to return. Default: 0 + /// The user's Spotify user ID. /// - public NewAlbumReleases GetNewAlbumReleases(String country = "", int limit = 20, int offset = 0) + public PublicProfile GetPublicProfile(String userId) { - if (!UseAuth) - throw new InvalidOperationException("Auth is required for GetNewAlbumReleases"); - limit = Math.Max(limit, 50); - StringBuilder builder = new StringBuilder(APIBase + "/browse/new-releases"); - builder.Append("?limit=" + limit); - builder.Append("&offset=" + offset); - if (country != "") - builder.Append("&country=" + country); - return DownloadData(builder.ToString()); - } - - /// - /// Add the current user as a follower of a playlist. - /// - /// The Spotify user ID of the person who owns the playlist. - /// - /// The Spotify ID of the playlist. Any playlist can be followed, regardless of its public/private - /// status, as long as you know its playlist ID. - /// - /// - /// If true the playlist will be included in user's public playlists, if false it will remain - /// private. - /// - /// - public ErrorResponse FollowPlaylist(String ownerId, String playlistId, bool showPublic = true) - { - JObject body = new JObject - { - {"public", showPublic} - }; - return UploadData(APIBase + "/users/" + ownerId + "/playlists/" + playlistId + "/followers", body.ToString(Formatting.None), "PUT"); - } - - /// - /// Remove the current user as a follower of a playlist. - /// - /// The Spotify user ID of the person who owns the playlist. - /// The Spotify ID of the playlist that is to be no longer followed. - /// - public ErrorResponse UnfollowPlaylist(String ownerId, String playlistId) - { - return UploadData(APIBase + "/users/" + ownerId + "/playlists/" + playlistId + "/followers", "", "DELETE"); - } - - /// - /// Check to see if one or more Spotify users are following a specified playlist. - /// - /// The Spotify user ID of the person who owns the playlist. - /// The Spotify ID of the playlist. - /// A list of Spotify User IDs - /// - public ListResponse IsFollowingPlaylist(String ownerId, String playlistId, List ids) - { - if (!UseAuth) - throw new InvalidOperationException("Auth is required for IsFollowingPlaylist"); - JToken res = DownloadData(APIBase + "/users/" + ownerId + "/playlists/" + playlistId + "/followers/contains?ids=" + string.Join(",", ids)); - if (res is JArray) - return new ListResponse {List = res.ToObject>(), Error = null}; - return new ListResponse {List = null, Error = res["error"].ToObject()}; - } - - /// - /// Check to see if one or more Spotify users are following a specified playlist. - /// - /// The Spotify user ID of the person who owns the playlist. - /// The Spotify ID of the playlist. - /// A Spotify User ID - /// - public ListResponse IsFollowingPlaylist(String ownerId, String playlistId, String id) - { - return IsFollowingPlaylist(ownerId, playlistId, new List {id}); + return DownloadData(APIBase + "/users/" + userId); } #endregion - #region Search and Fetch + #region Search /// /// Get Spotify catalog information about artists, albums, tracks or playlists that match a keyword string. @@ -574,6 +757,10 @@ namespace SpotifyAPI.Web return DownloadData(builder.ToString()); } + #endregion + + #region Tracks + /// /// Get Spotify catalog information for multiple tracks based on their Spotify IDs. /// @@ -587,29 +774,6 @@ namespace SpotifyAPI.Web return DownloadData(APIBase + "/tracks?market=" + market + "&ids=" + string.Join(",", ids.Take(50))); } - /// - /// Get Spotify catalog information for multiple albums identified by their Spotify IDs. - /// - /// A list of the Spotify IDs for the albums. Maximum: 20 IDs. - /// An ISO 3166-1 alpha-2 country code. Provide this parameter if you want to apply Track Relinking. - /// - public SeveralAlbums GetSeveralAlbums(List ids, String market = "") - { - if (market == "") - return DownloadData(APIBase + "/albums?ids=" + string.Join(",", ids.Take(20))); - return DownloadData(APIBase + "/albums?market=" + market + "&ids=" + string.Join(",", ids.Take(20))); - } - - /// - /// Get Spotify catalog information for several artists based on their Spotify IDs. - /// - /// A list of the Spotify IDs for the artists. Maximum: 50 IDs. - /// - public SeveralArtists GetSeveralArtists(List ids) - { - return DownloadData(APIBase + "/artists?ids=" + string.Join(",", ids.Take(50))); - } - /// /// Get Spotify catalog information for a single track identified by its unique Spotify ID. /// @@ -623,154 +787,6 @@ namespace SpotifyAPI.Web return DownloadData(APIBase + "/tracks/" + id + "?market=" + market); } - /// - /// Get Spotify catalog information about artists similar to a given artist. Similarity is based on analysis of the - /// Spotify community’s listening history. - /// - /// The Spotify ID for the artist. - /// - public SeveralArtists GetRelatedArtists(String id) - { - return DownloadData(APIBase + "/artists/" + id + "/related-artists"); - } - - /// - /// Get Spotify catalog information about an artist’s top tracks by country. - /// - /// The Spotify ID for the artist. - /// The country: an ISO 3166-1 alpha-2 country code. - /// - public SeveralTracks GetArtistsTopTracks(String id, String country) - { - return DownloadData(APIBase + "/artists/" + id + "/top-tracks?country=" + country); - } - - /// - /// Get Spotify catalog information about an artist’s albums. Optional parameters can be specified in the query string to filter and sort the response. - /// - /// The Spotify ID for the artist. - /// A list of keywords that will be used to filter the response. If not supplied, all album types will be returned - /// The maximum number of items to return. Default: 20. Minimum: 1. Maximum: 50. - /// The index of the first album to return. Default: 0 - /// An ISO 3166-1 alpha-2 country code. Supply this parameter to limit the response to one particular geographical market - /// - public Paging GetArtistsAlbums(String id, AlbumType type = AlbumType.All, int limit = 20, int offset = 0, String market = "") - { - limit = Math.Min(limit, 50); - StringBuilder builder = new StringBuilder(APIBase + "/artists/" + id + "/albums"); - builder.Append("?type=" + type.GetStringAttribute(",")); - builder.Append("&limit=" + limit); - builder.Append("&offset=" + offset); - if (market != "") - builder.Append("&market=" + market); - return DownloadData>(builder.ToString()); - } - - /// - /// Get Spotify catalog information for a single artist identified by their unique Spotify ID. - /// - /// The Spotify ID for the artist. - /// - public FullArtist GetArtist(String id) - { - return DownloadData(APIBase + "/artists/" + id); - } - - /// - /// Get Spotify catalog information about an album’s tracks. Optional parameters can be used to limit the number of tracks returned. - /// - /// The Spotify ID for the album. - /// The maximum number of items to return. Default: 20. Minimum: 1. Maximum: 50. - /// The index of the first track to return. Default: 0 (the first object). - /// An ISO 3166-1 alpha-2 country code. Provide this parameter if you want to apply Track Relinking. - /// - public Paging GetAlbumTracks(String id, int limit = 20, int offset = 0, String market = "") - { - limit = Math.Min(limit, 50); - StringBuilder builder = new StringBuilder(APIBase + "/albums/" + id + "/tracks"); - builder.Append("?limit=" + limit); - builder.Append("&offset=" + offset); - if (market != "") - builder.Append("&market=" + market); - return DownloadData>(builder.ToString()); - } - - /// - /// Get Spotify catalog information for a single album. - /// - /// The Spotify ID for the album. - /// An ISO 3166-1 alpha-2 country code. Provide this parameter if you want to apply Track Relinking. - /// - public FullAlbum GetAlbum(String id, String market = "") - { - if (market == "") - return DownloadData(APIBase + "/albums/" + id); - return DownloadData(APIBase + "/albums/" + id + "?market=" + market); - } - - #endregion - - #region Category - - /// - /// Get a list of categories used to tag items in Spotify (on, for example, the Spotify player’s “Browse” tab). - /// - /// A country: an ISO 3166-1 alpha-2 country code. Provide this parameter if you want to narrow the list of returned categories to those relevant to a particular country - /// The desired language, consisting of an ISO 639 language code and an ISO 3166-1 alpha-2 country code, joined by an underscore - /// The maximum number of categories to return. Default: 20. Minimum: 1. Maximum: 50. - /// The index of the first item to return. Default: 0 (the first object). - /// - public CategoryList GetCategories(String country = "", String locale = "", int limit = 20, int offset = 0) - { - if(!UseAuth) - throw new InvalidOperationException("Auth is required for GetCategories"); - limit = Math.Min(50, limit); - StringBuilder builder = new StringBuilder(APIBase + "/browse/categories"); - builder.Append("?limit=" + limit); - builder.Append("&offset=" + offset); - if (country != "") - builder.Append("&country=" + country); - if (locale != "") - builder.Append("&locale=" + locale); - return DownloadData(builder.ToString()); - } - - /// - /// Get a single category used to tag items in Spotify (on, for example, the Spotify player’s “Browse” tab). - /// - /// The Spotify category ID for the category. - /// A country: an ISO 3166-1 alpha-2 country code. Provide this parameter to ensure that the category exists for a particular country. - /// The desired language, consisting of an ISO 639 language code and an ISO 3166-1 alpha-2 country code, joined by an underscore - /// - public Category GetCategory(String categoryId, String country = "", String locale = "") - { - StringBuilder builder = new StringBuilder(APIBase + "/browse/categories/" + categoryId); - if (country != "") - builder.Append("?country=" + country); - if (locale != "") - builder.Append((country == "" ? "?locale=" : "&locale=") + locale); - return DownloadData(builder.ToString()); - } - - /// - /// Get a list of Spotify playlists tagged with a particular category. - /// - /// The Spotify category ID for the category. - /// A country: an ISO 3166-1 alpha-2 country code. - /// The maximum number of items to return. Default: 20. Minimum: 1. Maximum: 50. - /// The index of the first item to return. Default: 0 - /// - public CategoryPlaylist GetCategoryPlaylists(String categoryId, String country = "", int limit = 20, int offset = 0) - { - limit = Math.Min(50, limit); - StringBuilder builder = new StringBuilder(APIBase + "/browse/categories/" + categoryId + "/playlists"); - builder.Append("?limit=" + limit); - builder.Append("&offset=" + offset); - if (country != "") - builder.Append("&country=" + country); - return DownloadData(builder.ToString()); - } - #endregion #region Util