diff --git a/SpotifyAPI/Web/SpotifyWebAPI.cs b/SpotifyAPI/Web/SpotifyWebAPI.cs index 76cf6b1e..b275bdbb 100644 --- a/SpotifyAPI/Web/SpotifyWebAPI.cs +++ b/SpotifyAPI/Web/SpotifyWebAPI.cs @@ -718,7 +718,7 @@ namespace SpotifyAPI.Web throw new InvalidOperationException("Auth is required for IsFollowing"); var url = _builder.IsFollowing(followType, ids); - return DownloadDataAltAndExtract(url); + return DownloadList(url); } @@ -736,7 +736,7 @@ namespace SpotifyAPI.Web throw new InvalidOperationException("Auth is required for IsFollowing"); var url = _builder.IsFollowing(followType, ids); - return await DownloadDataAltAndExtractAsync(url); + return await DownloadListAsync(url); } /// @@ -847,7 +847,7 @@ namespace SpotifyAPI.Web throw new InvalidOperationException("Auth is required for IsFollowingPlaylist"); var url = _builder.IsFollowingPlaylist(ownerId, playlistId, ids); - return DownloadDataAltAndExtract(url); + return DownloadList(url); } /// @@ -864,7 +864,7 @@ namespace SpotifyAPI.Web throw new InvalidOperationException("Auth is required for IsFollowingPlaylist"); var url = _builder.IsFollowingPlaylist(ownerId, playlistId, ids); - return await DownloadDataAltAndExtractAsync(url); + return await DownloadListAsync(url); } /// @@ -1009,7 +1009,7 @@ namespace SpotifyAPI.Web throw new InvalidOperationException("Auth is required for CheckSavedTracks"); var url = _builder.CheckSavedTracks(ids); - return DownloadDataAltAndExtract(url); + return DownloadList(url); } /// @@ -1023,7 +1023,7 @@ namespace SpotifyAPI.Web if (!UseAuth) throw new InvalidOperationException("Auth is required for CheckSavedTracks"); var url = _builder.CheckSavedTracks(ids); - return await DownloadDataAltAndExtractAsync(url); + return await DownloadListAsync(url); } /// @@ -1138,7 +1138,7 @@ namespace SpotifyAPI.Web throw new InvalidOperationException("Auth is required for CheckSavedTracks"); var url = _builder.CheckSavedAlbums(ids); - return DownloadDataAltAndExtract(url); + return DownloadList(url); } /// @@ -1152,7 +1152,7 @@ namespace SpotifyAPI.Web if (!UseAuth) throw new InvalidOperationException("Auth is required for CheckSavedAlbumsAsync"); var url = _builder.CheckSavedAlbums(ids); - return await DownloadDataAltAndExtractAsync(url); + return await DownloadListAsync(url); } #endregion Library @@ -1826,17 +1826,17 @@ namespace SpotifyAPI.Web return await GetPreviousPageAsync, T>(paging); } - private ListResponse DownloadDataAltAndExtract(string url) + private ListResponse DownloadList(string url) { int triesLeft = RetryTimes + 1; Error lastError = null; - ListResponse data = null; + ListResponse data = null; do { if (data != null) { System.Threading.Thread.Sleep(RetryAfter); } Tuple res = DownloadDataAlt(url); - data = ExtractDataFromAltDownload(res); + data = ExtractDataToListResponse(res); lastError = data.Error; @@ -1847,17 +1847,17 @@ namespace SpotifyAPI.Web return data; } - private async Task> DownloadDataAltAndExtractAsync(string url) + private async Task> DownloadListAsync(string url) { int triesLeft = RetryTimes + 1; Error lastError = null; - ListResponse data = null; + ListResponse data = null; do { if (data != null) { await Task.Delay(RetryAfter); } Tuple res = await DownloadDataAltAsync(url); - data = ExtractDataFromAltDownload(res); + data = ExtractDataToListResponse(res); lastError = data.Error; @@ -1868,21 +1868,25 @@ namespace SpotifyAPI.Web return data; } - private static ListResponse ExtractDataFromAltDownload(Tuple res) + private static ListResponse ExtractDataToListResponse(Tuple res) { - ListResponse ret = null; + ListResponse ret = null; if (res.Item2 is JArray) - ret = new ListResponse + { + ret = new ListResponse { - List = res.Item2.ToObject>(), + List = res.Item2.ToObject>(), Error = null }; + } else - ret = new ListResponse + { + ret = new ListResponse { List = null, Error = res.Item2["error"].ToObject() }; + } ret.AddResponseInfo(res.Item1); return ret; }