Exemplo n.º 1
0
        public async Task <T> GetContentAsync <T>(string url)
        {
            var retryCount = 0;

            do
            {
                var response = await _httpClient.GetAsync(url);

                if (response.IsSuccessStatusCode)
                {
                    var content = await response.Content.ReadAsStringAsync();

                    return(_jsonDeserializer.DeserializeObject <T>(content));
                }
                else if (response.StatusCode == (HttpStatusCode)HttpStatusCodeReachedRateLimit)
                {
                    retryCount++;
                    await Task.Delay(TimeSpan.FromSeconds(_tvMazeConfiguration.RateLimitSleepTimerSecs));
                }
                else
                {
                    return(default(T));
                }
            }while (retryCount < _tvMazeConfiguration.RateLimitRetryMaxCount);

            return(default(T));
        }