Removed some code duplication.

This commit is contained in:
Petr Houška 2016-08-14 03:24:09 +02:00
parent 0f993ceda5
commit 9ccd257f43

View File

@ -44,6 +44,23 @@ namespace SpotifyAPI.Web
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
} }
#region Configuration
/// <summary>
/// Specifies after how many miliseconds should a failed request be retried.
/// </summary>
public int RetryAfter { get; set; } = 50;
/// <summary>
/// Should a failed request (Error 500, 502, or 503) be automatically retried or not.
/// </summary>
public bool UseAutoRetry { get; set; } = false;
/// <summary>
/// Maximum number of tries for one failed request.
/// </summary>
public int RetryTimes { get; set; } = 10;
#endregion Configuration
#region Search #region Search
/// <summary> /// <summary>
@ -1937,24 +1954,15 @@ namespace SpotifyAPI.Web
public T DownloadData<T>(string url) where T : BasicModel public T DownloadData<T>(string url) where T : BasicModel
{ {
if (UseAuth) Tuple<ResponseInfo, T> response = DownloadDataAlt<T>(url);
WebClient.SetHeader("Authorization", TokenType + " " + AccessToken);
else
WebClient.RemoveHeader("Authorization");
Tuple<ResponseInfo, T> response = WebClient.DownloadJson<T>(url);
response.Item2.AddResponseInfo(response.Item1); response.Item2.AddResponseInfo(response.Item1);
return response.Item2; return response.Item2;
} }
public async Task<T> DownloadDataAsync<T>(string url) where T : BasicModel public async Task<T> DownloadDataAsync<T>(string url) where T : BasicModel
{ {
if (UseAuth) Tuple<ResponseInfo, T> response = await DownloadDataAltAsync<T>(url);
WebClient.SetHeader("Authorization", TokenType + " " + AccessToken);
else
WebClient.RemoveHeader("Authorization");
Tuple<ResponseInfo, T> response = await WebClient.DownloadJsonAsync<T>(url);
response.Item2.AddResponseInfo(response.Item1); response.Item2.AddResponseInfo(response.Item1);
return response.Item2; return response.Item2;
} }