public override async Task <ICommentsResponse> ExecuteAsync() { var request = new ClientServiceRequest <JCommentsResponse>(); var url = Build(); var result = await request.ExecuteAsync(url); return(new CommentsResponse(result)); }
public async Task <IEnumerable <ICategoriesResponse> > ExecuteAsync() { var request = new ClientServiceRequest <IEnumerable <JCategoriesResponse> >(); var url = Build(); var result = await request.ExecuteAsync(url); if (result == null) { return(new ICategoriesResponse[0]); } return(result.Select(r => new CategoriesResponse(r))); }
/// <summary>This method throws an exception.</summary> /// <param name="request">The pre-created Google Request object.</param> /// <param name="service">The PodNoms API call service wrapper to handle (and log) this exception.</param> /// <exception cref="ExpiredKeyException"> /// This exception is thrown if the API key has expired /// Can't currently find a way to change the service (and ApiKey) /// /// UPDATE - deprecated for f*****g reasons.... keeping here as I still think I can get this to work /// </exception> private async Task <T> _____executeWrappedRequest <T>(ClientServiceRequest <T> request, ServiceWrapper service) { try { var policy = Policy .Handle <GoogleApiException>() .WaitAndRetryAsync(1, (retryAttempt, exception, context) => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), async(exception, timeSpan, retryCount, context) => { _logger.LogError($"API Key Failure: {exception.Message}"); _logger.LogError($"API Key Failure: {service.RequesterId}"); _logger.LogError($"API Key Failure: {service.ApiKey.Url}"); _logger.LogError($"API Key Failure: {request.Service.ApiKey}"); _logger.LogError($"API Key Failure: {request.Service.ApplicationName}"); var newClient = await _useClient(service.RequesterId); while (newClient.ApiKey.Equals(service.ApiKey)) { newClient = await _useClient(service.RequesterId); } _logger.LogInformation( $"Rotating keys...\n\t" + $"Old key: {service.ApiKey.Key}\n\t" + $"New Key: {newClient.ApiKey}"); var newRequest = request.Copy <ClientServiceRequest <T> >(); _logger.LogInformation($"Service API key changed to {newRequest.Service.ApiKey}"); }); return(await policy.ExecuteAsync(async() => { if (request.Service.ApiKey.Equals("AIzaSyCroKXwyml2OEkWrizMyQmjgwXRtwdfHPA")) { _logger.LogInformation("This is the expired key."); } var result = await request.ExecuteAsync(); return result; })); } catch (Exception e) { _logger.LogError($"API Key Failure: {e.Message}"); _logger.LogError($"API Key Failure: {service.RequesterId}"); _logger.LogError($"API Key Failure: {service.ApiKey.Url}"); _logger.LogError($"API Key Failure: {request.Service.ApiKey}"); _logger.LogError($"API Key Failure: {request.Service.ApplicationName}"); throw; } }
/// <summary>This method throws an exception.</summary> /// <param name="request">The pre-created Google Request object.</param> /// <param name="service">The PodNoms API call service wrapper to handle (and log) this exception.</param> /// <exception cref="ExpiredKeyException"> /// This exception is thrown if the API key has expired /// </exception> private async Task <T> _executeWrappedRequest <T>(ClientServiceRequest <T> request, ServiceWrapper service) { try { var result = await request.ExecuteAsync(); return(result); } catch (GoogleApiException gae) { _logger.LogError($"API Key Failure: {gae.Message}"); _logger.LogError($"API Key Failure: {service.RequesterId}"); _logger.LogError($"API Key Failure: {service.ApiKey.Url}"); _logger.LogError($"API Key Failure: {request.Service.ApiKey}"); _logger.LogError($"API Key Failure: {request.Service.ApplicationName}"); await _keyRepository.TaintKey(service.ApiKey, reason : gae.Message); throw new ExpiredKeyException( $"Expired Key Exception\n" + $"\tRequester: {service.RequesterId}" + $"\tKey: {request.Service.ApiKey}" + $"\tURL: {service.ApiKey.Url}" ); } }