diff --git a/SpotifyAPI/Web/SpotifyWebAPI.cs b/SpotifyAPI/Web/SpotifyWebAPI.cs index 79763111..56dcc025 100644 --- a/SpotifyAPI/Web/SpotifyWebAPI.cs +++ b/SpotifyAPI/Web/SpotifyWebAPI.cs @@ -5,6 +5,7 @@ using SpotifyAPI.Web.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.InteropServices; using System.Threading.Tasks; namespace SpotifyAPI.Web @@ -67,9 +68,9 @@ namespace SpotifyAPI.Web /// The index of the first result to return. Default: 0 /// An ISO 3166-1 alpha-2 country code or the string from_token. /// - public Task SearchItemsAsync(String q, SearchType type, int limit = 20, int offset = 0, String market = "") + public async Task SearchItemsAsync(String q, SearchType type, int limit = 20, int offset = 0, String market = "") { - return DownloadDataAsync(_builder.SearchItems(q, type, limit, offset, market)); + return await DownloadDataAsync(_builder.SearchItems(q, type, limit, offset, market)); } #endregion Search @@ -99,9 +100,9 @@ namespace SpotifyAPI.Web /// 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 Task> GetAlbumTracksAsync(String id, int limit = 20, int offset = 0, String market = "") + public async Task> GetAlbumTracksAsync(String id, int limit = 20, int offset = 0, String market = "") { - return DownloadDataAsync>(_builder.GetAlbumTracks(id, limit, offset, market)); + return await DownloadDataAsync>(_builder.GetAlbumTracks(id, limit, offset, market)); } /// @@ -121,9 +122,9 @@ namespace SpotifyAPI.Web /// 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 Task GetAlbumAsync(String id, String market = "") + public async Task GetAlbumAsync(String id, String market = "") { - return DownloadDataAsync(_builder.GetAlbum(id, market)); + return await DownloadDataAsync(_builder.GetAlbum(id, market)); } /// @@ -143,9 +144,9 @@ namespace SpotifyAPI.Web /// 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 Task GetSeveralAlbumsAsync(List ids, String market = "") + public async Task GetSeveralAlbumsAsync(List ids, String market = "") { - return DownloadDataAsync(_builder.GetSeveralAlbums(ids, market)); + return await DownloadDataAsync(_builder.GetSeveralAlbums(ids, market)); } #endregion Albums @@ -167,9 +168,9 @@ namespace SpotifyAPI.Web /// /// The Spotify ID for the artist. /// - public Task GetArtistAsync(String id) + public async Task GetArtistAsync(String id) { - return DownloadDataAsync(_builder.GetArtist(id)); + return await DownloadDataAsync(_builder.GetArtist(id)); } /// @@ -189,9 +190,9 @@ namespace SpotifyAPI.Web /// /// The Spotify ID for the artist. /// - public Task GetRelatedArtistsAsync(String id) + public async Task GetRelatedArtistsAsync(String id) { - return DownloadDataAsync(_builder.GetRelatedArtists(id)); + return await DownloadDataAsync(_builder.GetRelatedArtists(id)); } /// @@ -211,9 +212,9 @@ namespace SpotifyAPI.Web /// The Spotify ID for the artist. /// The country: an ISO 3166-1 alpha-2 country code. /// - public Task GetArtistsTopTracksAsync(String id, String country) + public async Task GetArtistsTopTracksAsync(String id, String country) { - return DownloadDataAsync(_builder.GetArtistsTopTracks(id, country)); + return await DownloadDataAsync(_builder.GetArtistsTopTracks(id, country)); } /// @@ -253,9 +254,9 @@ namespace SpotifyAPI.Web /// geographical market /// /// - public Task> GetArtistsAlbumsAsync(String id, AlbumType type = AlbumType.All, int limit = 20, int offset = 0, String market = "") + public async Task> GetArtistsAlbumsAsync(String id, AlbumType type = AlbumType.All, int limit = 20, int offset = 0, String market = "") { - return DownloadDataAsync>(_builder.GetArtistsAlbums(id, type, limit, offset, market)); + return await DownloadDataAsync>(_builder.GetArtistsAlbums(id, type, limit, offset, market)); } /// @@ -273,9 +274,9 @@ namespace SpotifyAPI.Web /// /// A list of the Spotify IDs for the artists. Maximum: 50 IDs. /// - public Task GetSeveralArtistsAsync(List ids) + public async Task GetSeveralArtistsAsync(List ids) { - return DownloadDataAsync(_builder.GetSeveralArtists(ids)); + return await DownloadDataAsync(_builder.GetSeveralArtists(ids)); } #endregion Artists @@ -313,11 +314,11 @@ namespace SpotifyAPI.Web /// The maximum number of items to return. Default: 20. Minimum: 1. Maximum: 50. /// The index of the first item to return. Default: 0 /// AUTH NEEDED - public Task GetFeaturedPlaylistsAsync(String locale = "", String country = "", DateTime timestamp = default(DateTime), int limit = 20, int offset = 0) + public async Task GetFeaturedPlaylistsAsync(String locale = "", String country = "", DateTime timestamp = default(DateTime), int limit = 20, int offset = 0) { if (!UseAuth) throw new InvalidOperationException("Auth is required for GetFeaturedPlaylists"); - return DownloadDataAsync(_builder.GetFeaturedPlaylists(locale, country, timestamp, limit, offset)); + return await DownloadDataAsync(_builder.GetFeaturedPlaylists(locale, country, timestamp, limit, offset)); } /// @@ -343,11 +344,11 @@ namespace SpotifyAPI.Web /// The index of the first item to return. Default: 0 /// /// AUTH NEEDED - public Task GetNewAlbumReleasesAsync(String country = "", int limit = 20, int offset = 0) + public async Task GetNewAlbumReleasesAsync(String country = "", int limit = 20, int offset = 0) { if (!UseAuth) throw new InvalidOperationException("Auth is required for GetNewAlbumReleases"); - return DownloadDataAsync(_builder.GetNewAlbumReleases(country, limit, offset)); + return await DownloadDataAsync(_builder.GetNewAlbumReleases(country, limit, offset)); } /// @@ -387,11 +388,11 @@ namespace SpotifyAPI.Web /// The index of the first item to return. Default: 0 (the first object). /// /// AUTH NEEDED - public Task GetCategoriesAsync(String country = "", String locale = "", int limit = 20, int offset = 0) + public async Task GetCategoriesAsync(String country = "", String locale = "", int limit = 20, int offset = 0) { if (!UseAuth) throw new InvalidOperationException("Auth is required for GetCategories"); - return DownloadDataAsync(_builder.GetCategories(country, locale, limit, offset)); + return await DownloadDataAsync(_builder.GetCategories(country, locale, limit, offset)); } /// @@ -427,9 +428,9 @@ namespace SpotifyAPI.Web /// /// /// AUTH NEEDED - public Task GetCategoryAsync(String categoryId, String country = "", String locale = "") + public async Task GetCategoryAsync(String categoryId, String country = "", String locale = "") { - return DownloadDataAsync(_builder.GetCategory(categoryId, country, locale)); + return await DownloadDataAsync(_builder.GetCategory(categoryId, country, locale)); } /// @@ -455,9 +456,9 @@ namespace SpotifyAPI.Web /// The index of the first item to return. Default: 0 /// /// AUTH NEEDED - public Task GetCategoryPlaylistsAsync(String categoryId, String country = "", int limit = 20, int offset = 0) + public async Task GetCategoryPlaylistsAsync(String categoryId, String country = "", int limit = 20, int offset = 0) { - return DownloadDataAsync(_builder.GetCategoryPlaylists(categoryId, country, limit, offset)); + return await DownloadDataAsync(_builder.GetCategoryPlaylists(categoryId, country, limit, offset)); } #endregion Browse @@ -476,7 +477,7 @@ namespace SpotifyAPI.Web { if (!UseAuth) throw new InvalidOperationException("Auth is required for GetFollowedArtists"); - return DownloadData(_builder.GetFollowedArtists(followType, limit, after)); + return DownloadData(_builder.GetFollowedArtists(limit, after)); } /// @@ -487,11 +488,11 @@ namespace SpotifyAPI.Web /// The last artist ID retrieved from the previous request. /// /// AUTH NEEDED - public Task GetFollowedArtistsAsync(FollowType followType, int limit = 20, String after = "") + public async Task GetFollowedArtistsAsync(FollowType followType, int limit = 20, String after = "") { if (!UseAuth) throw new InvalidOperationException("Auth is required for GetFollowedArtists"); - return DownloadDataAsync(_builder.GetFollowedArtists(followType, limit, after)); + return await DownloadDataAsync(_builder.GetFollowedArtists(limit, after)); } /// @@ -507,7 +508,7 @@ namespace SpotifyAPI.Web { {"ids", new JArray(ids)} }; - return UploadData(_builder.Follow(followType, ids), ob.ToString(Formatting.None), "PUT") ?? new ErrorResponse(); + return UploadData(_builder.Follow(followType), ob.ToString(Formatting.None), "PUT") ?? new ErrorResponse(); } /// @@ -517,14 +518,14 @@ namespace SpotifyAPI.Web /// A list of the artist or the user Spotify IDs /// /// AUTH NEEDED - public Task FollowAsync(FollowType followType, List ids) + public async Task FollowAsync(FollowType followType, List ids) { JObject ob = new JObject { {"ids", new JArray(ids)} }; - return - UploadDataAsync(_builder.Follow(followType, ids), + return await + UploadDataAsync(_builder.Follow(followType), ob.ToString(Formatting.None), "PUT") ?? new ErrorResponse(); } @@ -547,9 +548,9 @@ namespace SpotifyAPI.Web /// Artists or the Users Spotify ID /// /// AUTH NEEDED - public Task FollowAsync(FollowType followType, String id) + public async Task FollowAsync(FollowType followType, String id) { - return FollowAsync(followType, new List { id }); + return await FollowAsync(followType, new List { id }); } /// @@ -565,7 +566,7 @@ namespace SpotifyAPI.Web { {"ids", new JArray(ids)} }; - return UploadData(_builder.Unfollow(followType, ids), ob.ToString(Formatting.None), "DELETE") ?? new ErrorResponse(); + return UploadData(_builder.Unfollow(followType), ob.ToString(Formatting.None), "DELETE") ?? new ErrorResponse(); } /// @@ -575,13 +576,13 @@ namespace SpotifyAPI.Web /// A list of the artist or the user Spotify IDs /// /// AUTH NEEDED - public Task UnfollowAsync(FollowType followType, List ids) + public async Task UnfollowAsync(FollowType followType, List ids) { JObject ob = new JObject { {"ids", new JArray(ids)} }; - return UploadDataAsync(_builder.Unfollow(followType, ids), ob.ToString(Formatting.None), "DELETE") ?? new ErrorResponse(); + return await UploadDataAsync(_builder.Unfollow(followType), ob.ToString(Formatting.None), "DELETE") ?? new ErrorResponse(); } /// @@ -603,9 +604,9 @@ namespace SpotifyAPI.Web /// Artists or the Users Spotify ID /// /// AUTH NEEDED - public Task UnfollowAsync(FollowType followType, String id) + public async Task UnfollowAsync(FollowType followType, String id) { - return UnfollowAsync(followType, new List { id }); + return await UnfollowAsync(followType, new List { id }); } /// @@ -632,15 +633,14 @@ namespace SpotifyAPI.Web /// A list of the artist or the user Spotify IDs to check /// /// AUTH NEEDED - public Task> IsFollowingAsync(FollowType followType, List ids) + public async Task> IsFollowingAsync(FollowType followType, List ids) { if (!UseAuth) throw new InvalidOperationException("Auth is required for IsFollowing"); - JToken res = DownloadDataAsync(_builder.IsFollowing(followType, ids)); -# Compilebreaker - if (res is JArray) //todo expression is always false - return Task.FromResult(new ListResponse { List = res.ToObject>(), Error = null }); - return Task.FromResult(new ListResponse { List = null, Error = res["error"].ToObject() }); + JToken res = await DownloadDataAsync(_builder.IsFollowing(followType, ids)); + if (res is JArray) + return new ListResponse { List = res.ToObject>(), Error = null }; + return new ListResponse { List = null, Error = res["error"].ToObject() }; } /// @@ -662,9 +662,9 @@ namespace SpotifyAPI.Web /// Artists or the Users Spotify ID /// /// AUTH NEEDED - public Task> IsFollowingAsync(FollowType followType, String id) + public async Task> IsFollowingAsync(FollowType followType, String id) { - return IsFollowingAsync(followType, new List { id }); + return await IsFollowingAsync(followType, new List { id }); } /// @@ -704,13 +704,13 @@ namespace SpotifyAPI.Web /// /// /// AUTH NEEDED - public Task FollowPlaylistAsync(String ownerId, String playlistId, bool showPublic = true) + public async Task FollowPlaylistAsync(String ownerId, String playlistId, bool showPublic = true) { JObject body = new JObject { {"public", showPublic} }; - return UploadDataAsync(_builder.FollowPlaylist(ownerId, playlistId, showPublic), body.ToString(Formatting.None), "PUT"); + return await UploadDataAsync(_builder.FollowPlaylist(ownerId, playlistId, showPublic), body.ToString(Formatting.None), "PUT"); } /// @@ -732,9 +732,9 @@ namespace SpotifyAPI.Web /// The Spotify ID of the playlist that is to be no longer followed. /// /// AUTH NEEDED - public Task UnfollowPlaylistAsync(String ownerId, String playlistId) + public async Task UnfollowPlaylistAsync(String ownerId, String playlistId) { - return UploadDataAsync(_builder.UnfollowPlaylist(ownerId, playlistId), "", "DELETE"); + return await UploadDataAsync(_builder.UnfollowPlaylist(ownerId, playlistId), "", "DELETE"); } /// @@ -763,15 +763,14 @@ namespace SpotifyAPI.Web /// A list of Spotify User IDs /// /// AUTH NEEDED - public Task> IsFollowingPlaylistAsync(String ownerId, String playlistId, List ids) + public async Task> IsFollowingPlaylistAsync(String ownerId, String playlistId, List ids) { if (!UseAuth) throw new InvalidOperationException("Auth is required for IsFollowingPlaylist"); - JToken res = DownloadDataAsync(_builder.IsFollowingPlaylist(ownerId, playlistId, ids)); -# Compilebreaker - if (res is JArray) //todo expression is always false - return Task.FromResult(new ListResponse { List = res.ToObject>(), Error = null }); - return Task.FromResult(new ListResponse { List = null, Error = res["error"].ToObject() }); + JToken res = await DownloadDataAsync(_builder.IsFollowingPlaylist(ownerId, playlistId, ids)); + if (res is JArray) + return new ListResponse { List = res.ToObject>(), Error = null }; + return new ListResponse { List = null, Error = res["error"].ToObject() }; } /// @@ -795,9 +794,9 @@ namespace SpotifyAPI.Web /// A Spotify User ID /// /// AUTH NEEDED - public Task> IsFollowingPlaylistAsync(String ownerId, String playlistId, String id) + public async Task> IsFollowingPlaylistAsync(String ownerId, String playlistId, String id) { - return IsFollowingPlaylistAsync(ownerId, playlistId, new List { id }); + return await IsFollowingPlaylistAsync(ownerId, playlistId, new List { id }); } #endregion Follow @@ -813,7 +812,7 @@ namespace SpotifyAPI.Web public ErrorResponse SaveTracks(List ids) { JArray array = new JArray(ids); - return UploadData(_builder.SaveTracks(array.ToString(Formatting.None), "PUT") ?? new ErrorResponse()); + return UploadData(_builder.SaveTracks(), array.ToString(Formatting.None), "PUT") ?? new ErrorResponse(); } /// @@ -822,10 +821,10 @@ namespace SpotifyAPI.Web /// A list of the Spotify IDs /// /// AUTH NEEDED - public Task SaveTracksAsync(List ids) + public async Task SaveTracksAsync(List ids) { JArray array = new JArray(ids); - return UploadDataAsync(_builder.SaveTracks(array.ToString(Formatting.None), "PUT") ?? new ErrorResponse()); + return await UploadDataAsync(_builder.SaveTracks(), array.ToString(Formatting.None), "PUT") ?? new ErrorResponse(); } /// @@ -845,9 +844,9 @@ namespace SpotifyAPI.Web /// A Spotify ID /// /// AUTH NEEDED - public Task SaveTrackAsync(String id) + public async Task SaveTrackAsync(String id) { - return SaveTracksAsync(new List { id }); + return await SaveTracksAsync(new List { id }); } /// @@ -873,11 +872,11 @@ namespace SpotifyAPI.Web /// An ISO 3166-1 alpha-2 country code. Provide this parameter if you want to apply Track Relinking. /// /// AUTH NEEDED - public Task> GetSavedTracksAsync(int limit = 20, int offset = 0, String market = "") + public async Task> GetSavedTracksAsync(int limit = 20, int offset = 0, String market = "") { if (!UseAuth) throw new InvalidOperationException("Auth is required for GetSavedTracks"); - return DownloadDataAsync>(_builder.GetSavedTracks(limit, offset, market)); + return await DownloadDataAsync>(_builder.GetSavedTracks(limit, offset, market)); } /// @@ -889,7 +888,7 @@ namespace SpotifyAPI.Web public ErrorResponse RemoveSavedTracks(List ids) { JArray array = new JArray(ids); - return UploadData(_builder.RemoveSavedTracks(array.ToString(Formatting.None), "DELETE") ?? new ErrorResponse()); + return UploadData(_builder.RemoveSavedTracks(), array.ToString(Formatting.None), "DELETE") ?? new ErrorResponse(); } /// @@ -898,10 +897,10 @@ namespace SpotifyAPI.Web /// A list of the Spotify IDs. /// /// AUTH NEEDED - public Task RemoveSavedTracksAsync(List ids) + public async Task RemoveSavedTracksAsync(List ids) { JArray array = new JArray(ids); - return UploadDataAsync(_builder.RemoveSavedTracks(array.ToString(Formatting.None), "DELETE") ?? new ErrorResponse()); + return await UploadDataAsync(_builder.RemoveSavedTracks(), array.ToString(Formatting.None), "DELETE") ?? new ErrorResponse(); } /// @@ -926,15 +925,14 @@ namespace SpotifyAPI.Web /// A list of the Spotify IDs. /// /// AUTH NEEDED - public Task> CheckSavedTracksAsync(List ids) + public async Task> CheckSavedTracksAsync(List ids) { if (!UseAuth) throw new InvalidOperationException("Auth is required for CheckSavedTracks"); - JToken res = DownloadDataAsync(_builder.CheckSavedTracks(ids)); -# Compilebreaker - if (res is JArray) //todo expression is always false - return Task.FromResult(new ListResponse { List = res.ToObject>(), Error = null }); - return Task.FromResult(new ListResponse { List = null, Error = res["error"].ToObject() }); + JToken res = await DownloadDataAsync(_builder.CheckSavedTracks(ids)); + if (res is JArray) + return new ListResponse { List = res.ToObject>(), Error = null }; + return new ListResponse { List = null, Error = res["error"].ToObject() }; } #endregion Library @@ -964,11 +962,11 @@ namespace SpotifyAPI.Web /// The index of the first playlist to return. Default: 0 (the first object) /// /// AUTH NEEDED - public Task> GetUserPlaylistsAsync(String userId, int limit = 20, int offset = 0) + public async Task> GetUserPlaylistsAsync(String userId, int limit = 20, int offset = 0) { if (!UseAuth) throw new InvalidOperationException("Auth is required for GetUserPlaylists"); - return DownloadDataAsync>(_builder.GetUserPlaylists(userId, limit, offset)); + return await DownloadDataAsync>(_builder.GetUserPlaylists(userId, limit, offset)); } /// @@ -1002,11 +1000,11 @@ namespace SpotifyAPI.Web /// An ISO 3166-1 alpha-2 country code. Provide this parameter if you want to apply Track Relinking. /// /// AUTH NEEDED - public Task GetPlaylistAsync(String userId, String playlistId, String fields = "", String market = "") + public async Task GetPlaylistAsync(String userId, String playlistId, String fields = "", String market = "") { if (!UseAuth) throw new InvalidOperationException("Auth is required for GetPlaylist"); - return DownloadDataAsync(_builder.GetPlaylist(userId, playlistId, fields, market)); + return await DownloadDataAsync(_builder.GetPlaylist(userId, playlistId, fields, market)); } /// @@ -1044,11 +1042,11 @@ namespace SpotifyAPI.Web /// An ISO 3166-1 alpha-2 country code. Provide this parameter if you want to apply Track Relinking. /// /// AUTH NEEDED - public Task> GetPlaylistTracksAsync(String userId, String playlistId, String fields = "", int limit = 100, int offset = 0, String market = "") + public async Task> GetPlaylistTracksAsync(String userId, String playlistId, String fields = "", int limit = 100, int offset = 0, String market = "") { if (!UseAuth) throw new InvalidOperationException("Auth is required for GetPlaylistTracks"); - return DownloadDataAsync>(_builder.GetPlaylistTracks(userId, playlistId, fields, limit, offset, market)); + return await DownloadDataAsync>(_builder.GetPlaylistTracks(userId, playlistId, fields, limit, offset, market)); } /// @@ -1089,14 +1087,14 @@ namespace SpotifyAPI.Web /// /// /// AUTH NEEDED - public Task CreatePlaylistAsync(String userId, String playlistName, Boolean isPublic = true) + public async Task CreatePlaylistAsync(String userId, String playlistName, Boolean isPublic = true) { JObject body = new JObject { {"name", playlistName}, {"public", isPublic} }; - return UploadDataAsync(_builder.CreatePlaylist(userId, playlistName, isPublic), body.ToString(Formatting.None)); + return await UploadDataAsync(_builder.CreatePlaylist(userId, playlistName, isPublic), body.ToString(Formatting.None)); } /// @@ -1115,7 +1113,7 @@ namespace SpotifyAPI.Web body.Add("name", newName); if (newPublic != null) body.Add("public", newPublic); - return UploadData(_builder.UpdatePlaylist(userId, playlistId, newName, newPublic), body.ToString(Formatting.None), "PUT") ?? new ErrorResponse(); + return UploadData(_builder.UpdatePlaylist(userId, playlistId), body.ToString(Formatting.None), "PUT") ?? new ErrorResponse(); } /// @@ -1127,14 +1125,14 @@ namespace SpotifyAPI.Web /// If true the playlist will be public, if false it will be private. /// /// AUTH NEEDED - public Task UpdatePlaylistAsync(String userId, String playlistId, String newName = null, Boolean? newPublic = null) + public async Task UpdatePlaylistAsync(String userId, String playlistId, String newName = null, Boolean? newPublic = null) { JObject body = new JObject(); if (newName != null) body.Add("name", newName); if (newPublic != null) body.Add("public", newPublic); - return UploadDataAsync(_builder.UpdatePlaylist(userId, playlistId, newName, newPublic), body.ToString(Formatting.None), "PUT") ?? new ErrorResponse(); + return await UploadDataAsync(_builder.UpdatePlaylist(userId, playlistId), body.ToString(Formatting.None), "PUT") ?? new ErrorResponse(); } /// @@ -1152,7 +1150,7 @@ namespace SpotifyAPI.Web { {"uris", new JArray(uris.Take(100))} }; - return UploadData(_builder.ReplacePlaylistTracks(userId, playlistId, uris), body.ToString(Formatting.None), "PUT") ?? new ErrorResponse(); + return UploadData(_builder.ReplacePlaylistTracks(userId, playlistId), body.ToString(Formatting.None), "PUT") ?? new ErrorResponse(); } /// @@ -1164,13 +1162,13 @@ namespace SpotifyAPI.Web /// A list of Spotify track URIs to set. A maximum of 100 tracks can be set in one request. /// /// AUTH NEEDED - public Task ReplacePlaylistTracksAsync(String userId, String playlistId, List uris) + public async Task ReplacePlaylistTracksAsync(String userId, String playlistId, List uris) { JObject body = new JObject { {"uris", new JArray(uris.Take(100))} }; - return UploadDataAsync(_builder.ReplacePlaylistTracks(userId, playlistId, uris), body.ToString(Formatting.None), "PUT") ?? new ErrorResponse(); + return await UploadDataAsync(_builder.ReplacePlaylistTracks(userId, playlistId), body.ToString(Formatting.None), "PUT") ?? new ErrorResponse(); } /// @@ -1204,13 +1202,13 @@ namespace SpotifyAPI.Web /// /// /// AUTH NEEDED - public Task RemovePlaylistTracksAsync(String userId, String playlistId, List uris) + public async Task RemovePlaylistTracksAsync(String userId, String playlistId, List uris) { JObject body = new JObject { {"tracks", JArray.FromObject(uris.Take(100))} }; - return UploadDataAsync(_builder.RemovePlaylistTracks(userId, playlistId, uris), body.ToString(Formatting.None), "DELETE") ?? new ErrorResponse(); + return await UploadDataAsync(_builder.RemovePlaylistTracks(userId, playlistId, uris), body.ToString(Formatting.None), "DELETE") ?? new ErrorResponse(); } /// @@ -1234,9 +1232,9 @@ namespace SpotifyAPI.Web /// Spotify URI /// /// AUTH NEEDED - public Task RemovePlaylistTrackAsync(String userId, String playlistId, DeleteTrackUri uri) + public async Task RemovePlaylistTrackAsync(String userId, String playlistId, DeleteTrackUri uri) { - return RemovePlaylistTracksAsync(userId, playlistId, new List { uri }); + return await RemovePlaylistTracksAsync(userId, playlistId, new List { uri }); } /// @@ -1266,13 +1264,13 @@ namespace SpotifyAPI.Web /// The position to insert the tracks, a zero-based index /// /// AUTH NEEDED - public Task AddPlaylistTracksAsync(String userId, String playlistId, List uris, int? position = null) + public async Task AddPlaylistTracksAsync(String userId, String playlistId, List uris, int? position = null) { JObject body = new JObject { {"uris", JArray.FromObject(uris.Take(100))} }; - return UploadDataAsync(_builder.AddPlaylistTracks(userId, playlistId, uris, position), body.ToString(Formatting.None)) ?? new ErrorResponse(); + return await UploadDataAsync(_builder.AddPlaylistTracks(userId, playlistId, uris, position), body.ToString(Formatting.None)) ?? new ErrorResponse(); } /// @@ -1298,9 +1296,9 @@ namespace SpotifyAPI.Web /// The position to insert the tracks, a zero-based index /// /// AUTH NEEDED - public Task AddPlaylistTrackAsync(String userId, String playlistId, String uri, int? position = null) + public async Task AddPlaylistTrackAsync(String userId, String playlistId, String uri, int? position = null) { - return AddPlaylistTracksAsync(userId, playlistId, new List { uri }, position); + return await AddPlaylistTracksAsync(userId, playlistId, new List { uri }, position); } /// @@ -1324,7 +1322,7 @@ namespace SpotifyAPI.Web }; if (!String.IsNullOrEmpty(snapshotId)) body.Add("snapshot_id", snapshotId); - return UploadData(_builder.ReorderPlaylist(userId, playlistId, rangeStart, insertBefore, rangeLength, snapshotId), body.ToString(Formatting.None), "PUT"); + return UploadData(_builder.ReorderPlaylist(userId, playlistId), body.ToString(Formatting.None), "PUT"); } /// @@ -1338,15 +1336,18 @@ namespace SpotifyAPI.Web /// The playlist's snapshot ID against which you want to make the changes. /// /// AUTH NEEDED - public Task ReorderPlaylistAsync(String userId, String playlistId, int rangeStart, int insertBefore, int rangeLength = 1, String snapshotId = "") + public async Task ReorderPlaylistAsync(String userId, String playlistId, int rangeStart, int insertBefore, int rangeLength = 1, String snapshotId = "") { JObject body = new JObject { {"range_start", rangeStart}, {"range_length", rangeLength}, - {"insert_before", insertBefore} + {"insert_before", insertBefore}, + {"snapshot_id", snapshotId} }; - return UploadDataAsync(_builder.ReorderPlaylist(userId, playlistId, rangeStart, insertBefore, rangeLength, snapshotId), body.ToString(Formatting.None), "PUT"); + if (!String.IsNullOrEmpty(snapshotId)) + body.Add("snapshot_id", snapshotId); + return await UploadDataAsync(_builder.ReorderPlaylist(userId, playlistId), body.ToString(Formatting.None), "PUT"); } #endregion Playlists @@ -1370,11 +1371,11 @@ namespace SpotifyAPI.Web /// /// /// AUTH NEEDED - public Task GetPrivateProfileAsync() + public async Task GetPrivateProfileAsync() { if (!UseAuth) throw new InvalidOperationException("Auth is required for GetPrivateProfile"); - return DownloadDataAsync(_builder.GetPrivateProfile()); + return await DownloadDataAsync(_builder.GetPrivateProfile()); } /// @@ -1392,9 +1393,9 @@ namespace SpotifyAPI.Web /// /// The user's Spotify user ID. /// - public Task GetPublicProfileAsync(String userId) + public async Task GetPublicProfileAsync(String userId) { - return DownloadDataAsync(_builder.GetPublicProfile(userId)); + return await DownloadDataAsync(_builder.GetPublicProfile(userId)); } #endregion Profiles @@ -1418,9 +1419,9 @@ namespace SpotifyAPI.Web /// A list of the Spotify IDs for the tracks. Maximum: 50 IDs. /// An ISO 3166-1 alpha-2 country code. Provide this parameter if you want to apply Track Relinking. /// - public Task GetSeveralTracksAsync(List ids, String market = "") + public async Task GetSeveralTracksAsync(List ids, String market = "") { - return DownloadDataAsync(_builder.GetSeveralTracks(ids, market)); + return await DownloadDataAsync(_builder.GetSeveralTracks(ids, market)); } /// @@ -1440,15 +1441,25 @@ namespace SpotifyAPI.Web /// The Spotify ID for the track. /// An ISO 3166-1 alpha-2 country code. Provide this parameter if you want to apply Track Relinking. /// - public Task GetTrackAsync(String id, String market = "") + public async Task GetTrackAsync(String id, String market = "") { - return DownloadDataAsync(_builder.GetTrack(id, market)); + return await DownloadDataAsync(_builder.GetTrack(id, market)); } #endregion Tracks #region Util + public Paging Next(Paging paging) + { + return DownloadData>(paging.Next); + } + + public Paging Previous(Paging paging) + { + return DownloadData>(paging.Previous); + } + public T UploadData(String url, String uploadData, String method = "POST") { if (!UseAuth) diff --git a/SpotifyAPI/Web/SpotifyWebBuilder.cs b/SpotifyAPI/Web/SpotifyWebBuilder.cs index c925eacb..95b3d101 100644 --- a/SpotifyAPI/Web/SpotifyWebBuilder.cs +++ b/SpotifyAPI/Web/SpotifyWebBuilder.cs @@ -391,10 +391,9 @@ namespace SpotifyAPI.Web /// /// Save one or more tracks to the current user’s “Your Music” library. /// - /// A list of the Spotify IDs /// /// AUTH NEEDED - public string SaveTracks(List ids) + public string SaveTracks() { return APIBase + "/me/tracks/"; } @@ -421,10 +420,9 @@ namespace SpotifyAPI.Web /// /// Remove one or more tracks from the current user’s “Your Music” library. /// - /// A list of the Spotify IDs. /// /// AUTH NEEDED - public string RemoveSavedTracks(List ids) + public string RemoveSavedTracks() { return APIBase + "/me/tracks/"; } @@ -532,11 +530,9 @@ namespace SpotifyAPI.Web /// /// The user's Spotify user ID. /// The Spotify ID for the playlist. - /// The new name for the playlist, for example "My New Playlist Title". - /// If true the playlist will be public, if false it will be private. /// /// AUTH NEEDED - public string UpdatePlaylist(String userId, String playlistId, String newName = null, Boolean? newPublic = null) + public string UpdatePlaylist(String userId, String playlistId) { return $"{APIBase}/users/{userId}/playlists/{playlistId}"; } @@ -547,10 +543,9 @@ namespace SpotifyAPI.Web /// /// The user's Spotify user ID. /// The Spotify ID for the playlist. - /// A list of Spotify track URIs to set. A maximum of 100 tracks can be set in one request. /// /// AUTH NEEDED - public string ReplacePlaylistTracks(String userId, String playlistId, List uris) + public string ReplacePlaylistTracks(String userId, String playlistId) { return $"{APIBase}/users/{userId}/playlists/{playlistId}/tracks"; } @@ -592,15 +587,11 @@ namespace SpotifyAPI.Web /// /// The user's Spotify user ID. /// The Spotify ID for the playlist. - /// The position of the first track to be reordered. - /// The position where the tracks should be inserted. - /// The amount of tracks to be reordered. Defaults to 1 if not set. - /// The playlist's snapshot ID against which you want to make the changes. /// /// AUTH NEEDED - public string ReorderPlaylist(String userId, String playlistId, int rangeStart, int insertBefore, int rangeLength = 1, String snapshotId = "") + public string ReorderPlaylist(String userId, String playlistId) { - return APIBase + "/users/" + userId + "/playlists/" + playlistId + "/tracks"; + return $"{APIBase}/users/{userId}/playlists/{playlistId}/tracks"; } #endregion Playlists