Beispiel #1
0
        private async Task <ServiceWrapper> _useClient(string requesterId)
        {
            var key = await _keyRepository.GetApiKey("YouTube", requesterId);

            if (key is null)
            {
                throw new NoKeyAvailableException();
            }

            var client = new ServiceWrapper(requesterId, key);
            await _serviceRequestLogger
            .LogRequest(
                key,
                requesterId,
                Environment.StackTrace);

            return(client);
        }
Beispiel #2
0
        /// <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}"
                          );
            }
        }