From 9ccd257f43fde84ebe6d414a5cdbfe427c2da2ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Hou=C5=A1ka?= Date: Sun, 14 Aug 2016 03:24:09 +0200 Subject: [PATCH] Removed some code duplication. --- SpotifyAPI/Web/SpotifyWebAPI.cs | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/SpotifyAPI/Web/SpotifyWebAPI.cs b/SpotifyAPI/Web/SpotifyWebAPI.cs index d8795ab2..4eadacda 100644 --- a/SpotifyAPI/Web/SpotifyWebAPI.cs +++ b/SpotifyAPI/Web/SpotifyWebAPI.cs @@ -44,6 +44,23 @@ namespace SpotifyAPI.Web GC.SuppressFinalize(this); } + #region Configuration + /// + /// Specifies after how many miliseconds should a failed request be retried. + /// + public int RetryAfter { get; set; } = 50; + + /// + /// Should a failed request (Error 500, 502, or 503) be automatically retried or not. + /// + public bool UseAutoRetry { get; set; } = false; + + /// + /// Maximum number of tries for one failed request. + /// + public int RetryTimes { get; set; } = 10; + #endregion Configuration + #region Search /// @@ -1937,24 +1954,15 @@ namespace SpotifyAPI.Web public T DownloadData(string url) where T : BasicModel { - if (UseAuth) - WebClient.SetHeader("Authorization", TokenType + " " + AccessToken); - else - WebClient.RemoveHeader("Authorization"); + Tuple response = DownloadDataAlt(url); - Tuple response = WebClient.DownloadJson(url); response.Item2.AddResponseInfo(response.Item1); return response.Item2; } public async Task DownloadDataAsync(string url) where T : BasicModel { - if (UseAuth) - WebClient.SetHeader("Authorization", TokenType + " " + AccessToken); - else - WebClient.RemoveHeader("Authorization"); - - Tuple response = await WebClient.DownloadJsonAsync(url); + Tuple response = await DownloadDataAltAsync(url); response.Item2.AddResponseInfo(response.Item1); return response.Item2; }