diff --git a/SpotifyAPI/Web/SpotifyWebAPI.cs b/SpotifyAPI/Web/SpotifyWebAPI.cs index ac04dd0f..b785b55d 100644 --- a/SpotifyAPI/Web/SpotifyWebAPI.cs +++ b/SpotifyAPI/Web/SpotifyWebAPI.cs @@ -715,21 +715,7 @@ namespace SpotifyAPI.Web if (!UseAuth) throw new InvalidOperationException("Auth is required for IsFollowing"); Tuple res = DownloadDataAlt(_builder.IsFollowing(followType, ids)); - ListResponse ret; - if (res.Item2 is JArray) - ret = new ListResponse - { - List = res.Item2.ToObject>(), - Error = null - }; - else - ret = new ListResponse - { - List = null, - Error = res.Item2["error"].ToObject() - }; - ret.AddResponseInfo(res.Item1); - return ret; + return ExtractDataFromAltDownload(res); } /// @@ -744,21 +730,7 @@ namespace SpotifyAPI.Web if (!UseAuth) throw new InvalidOperationException("Auth is required for IsFollowing"); Tuple res = await DownloadDataAltAsync(_builder.IsFollowing(followType, ids)); - ListResponse ret = null; - if (res.Item2 is JArray) - ret = new ListResponse - { - List = res.Item2.ToObject>(), - Error = null - }; - else - ret = new ListResponse - { - List = null, - Error = res.Item2["error"].ToObject() - }; - ret.AddResponseInfo(res.Item1); - return ret; + return ExtractDataFromAltDownload(res); } /// @@ -868,21 +840,7 @@ namespace SpotifyAPI.Web if (!UseAuth) throw new InvalidOperationException("Auth is required for IsFollowingPlaylist"); Tuple res = DownloadDataAlt(_builder.IsFollowingPlaylist(ownerId, playlistId, ids)); - ListResponse ret = null; - if (res.Item2 is JArray) - ret = new ListResponse - { - List = res.Item2.ToObject>(), - Error = null - }; - else - ret = new ListResponse - { - List = null, - Error = res.Item2["error"].ToObject() - }; - ret.AddResponseInfo(res.Item1); - return ret; + return ExtractDataFromAltDownload(res); } /// @@ -898,21 +856,7 @@ namespace SpotifyAPI.Web if (!UseAuth) throw new InvalidOperationException("Auth is required for IsFollowingPlaylist"); Tuple res = await DownloadDataAltAsync(_builder.IsFollowingPlaylist(ownerId, playlistId, ids)); - ListResponse ret = null; - if (res.Item2 is JArray) - ret = new ListResponse - { - List = res.Item2.ToObject>(), - Error = null - }; - else - ret = new ListResponse - { - List = null, - Error = res.Item2["error"].ToObject() - }; - ret.AddResponseInfo(res.Item1); - return ret; + return ExtractDataFromAltDownload(res); } /// @@ -1056,21 +1000,7 @@ namespace SpotifyAPI.Web if (!UseAuth) throw new InvalidOperationException("Auth is required for CheckSavedTracks"); Tuple res = DownloadDataAlt(_builder.CheckSavedTracks(ids)); - ListResponse ret = null; - if (res.Item2 is JArray) - ret = new ListResponse - { - List = res.Item2.ToObject>(), - Error = null - }; - else - ret = new ListResponse - { - List = null, - Error = res.Item2["error"].ToObject() - }; - ret.AddResponseInfo(res.Item1); - return ret; + return ExtractDataFromAltDownload(res); } /// @@ -1084,21 +1014,7 @@ namespace SpotifyAPI.Web if (!UseAuth) throw new InvalidOperationException("Auth is required for CheckSavedTracks"); Tuple res = await DownloadDataAltAsync(_builder.CheckSavedTracks(ids)); - ListResponse ret = null; - if (res.Item2 is JArray) - ret = new ListResponse - { - List = res.Item2.ToObject>(), - Error = null - }; - else - ret = new ListResponse - { - List = null, - Error = res.Item2["error"].ToObject() - }; - ret.AddResponseInfo(res.Item1); - return ret; + return ExtractDataFromAltDownload(res); } /// @@ -1212,21 +1128,7 @@ namespace SpotifyAPI.Web if (!UseAuth) throw new InvalidOperationException("Auth is required for CheckSavedTracks"); Tuple res = DownloadDataAlt(_builder.CheckSavedAlbums(ids)); - ListResponse ret = null; - if (res.Item2 is JArray) - ret = new ListResponse - { - List = res.Item2.ToObject>(), - Error = null - }; - else - ret = new ListResponse - { - List = null, - Error = res.Item2["error"].ToObject() - }; - ret.AddResponseInfo(res.Item1); - return ret; + return ExtractDataFromAltDownload(res); } /// @@ -1240,21 +1142,7 @@ namespace SpotifyAPI.Web if (!UseAuth) throw new InvalidOperationException("Auth is required for CheckSavedAlbumsAsync"); Tuple res = await DownloadDataAltAsync(_builder.CheckSavedAlbums(ids)); - ListResponse ret = null; - if (res.Item2 is JArray) - ret = new ListResponse - { - List = res.Item2.ToObject>(), - Error = null - }; - else - ret = new ListResponse - { - List = null, - Error = res.Item2["error"].ToObject() - }; - ret.AddResponseInfo(res.Item1); - return ret; + return ExtractDataFromAltDownload(res); } #endregion Library @@ -1928,6 +1816,25 @@ namespace SpotifyAPI.Web return await GetPreviousPageAsync, T>(paging); } + private static ListResponse ExtractDataFromAltDownload(Tuple res) + { + ListResponse ret = null; + if (res.Item2 is JArray) + ret = new ListResponse + { + List = res.Item2.ToObject>(), + Error = null + }; + else + ret = new ListResponse + { + List = null, + Error = res.Item2["error"].ToObject() + }; + ret.AddResponseInfo(res.Item1); + return ret; + } + public T UploadData(string url, string uploadData, string method = "POST") where T : BasicModel { if (!UseAuth)