/// <summary> /// Returns pet inventories by status Returns a map of status codes to quantities /// </summary> /// <exception cref="ApiException">Thrown when fails to make API call</exception> /// <param name="cancellationToken">Cancellation Token to cancel the request.</param> /// <returns><see cref="Task"/><<see cref="ApiResponse{T}"/>> where T : <see cref="Dictionary<string, int>"/></returns> public async Task <ApiResponse <Dictionary <string, int> > > GetInventoryWithHttpInfoAsync(System.Threading.CancellationToken?cancellationToken = null) { try { using (HttpRequestMessage request = new HttpRequestMessage()) { UriBuilder uriBuilder = new UriBuilder(); uriBuilder.Host = HttpClient.BaseAddress.Host; uriBuilder.Scheme = ClientUtils.SCHEME; uriBuilder.Path = ClientUtils.CONTEXT_PATH + "/store/inventory"; List <TokenBase> tokens = new List <TokenBase>(); ApiKeyToken apiKey = (ApiKeyToken)await ApiKeyProvider.GetAsync(cancellationToken).ConfigureAwait(false); tokens.Add(apiKey); apiKey.UseInHeader(request, "api_key"); request.RequestUri = uriBuilder.Uri; string[] accepts = new string[] { "application/json" }; string accept = ClientUtils.SelectHeaderAccept(accepts); if (accept != null) { request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(accept)); } request.Method = new HttpMethod("GET"); using (HttpResponseMessage responseMessage = await HttpClient.SendAsync(request, cancellationToken.GetValueOrDefault()).ConfigureAwait(false)) { DateTime requestedAt = DateTime.UtcNow; string responseContent = await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(false); if (ApiResponded != null) { try { ApiResponded.Invoke(this, new ApiResponseEventArgs(requestedAt, DateTime.UtcNow, responseMessage.StatusCode, "/store/inventory")); } catch (Exception e) { Logger.LogError(e, "An error occured while invoking ApiResponded."); } } ApiResponse <Dictionary <string, int> > apiResponse = new ApiResponse <Dictionary <string, int> >(responseMessage, responseContent); if (apiResponse.IsSuccessStatusCode) { apiResponse.Content = JsonSerializer.Deserialize <Dictionary <string, int> >(apiResponse.RawContent, _jsonSerializerOptions); } else if (apiResponse.StatusCode == (HttpStatusCode)429) { foreach (TokenBase token in tokens) { token.BeginRateLimit(); } } return(apiResponse); } } } catch (Exception e) { Logger.LogError(e, "An error occured while sending the request to the server."); throw; } }
/// <summary> /// To test class name in snake case To test class name in snake case /// </summary> /// <exception cref="ApiException">Thrown when fails to make API call</exception> /// <param name="modelClient">client model</param> /// <param name="cancellationToken">Cancellation Token to cancel the request.</param> /// <returns><see cref="Task"/><<see cref="ApiResponse{T}"/>> where T : <see cref="ModelClient"/></returns> public async Task <ApiResponse <ModelClient> > TestClassnameWithHttpInfoAsync(ModelClient modelClient, System.Threading.CancellationToken?cancellationToken = null) { try { #pragma warning disable CS0472 // The result of the expression is always the same since a value of this type is never equal to 'null' if (modelClient == null) { throw new ArgumentNullException(nameof(modelClient)); } #pragma warning disable CS0472 // The result of the expression is always the same since a value of this type is never equal to 'null' using (HttpRequestMessage request = new HttpRequestMessage()) { UriBuilder uriBuilder = new UriBuilder(); uriBuilder.Host = HttpClient.BaseAddress.Host; uriBuilder.Scheme = ClientUtils.SCHEME; uriBuilder.Path = ClientUtils.CONTEXT_PATH + "/fake_classname_test"; System.Collections.Specialized.NameValueCollection parseQueryString = System.Web.HttpUtility.ParseQueryString(string.Empty); if ((modelClient as object) is System.IO.Stream stream) { request.Content = new StreamContent(stream); } else { // request.Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(modelClient, ClientUtils.JsonSerializerSettings)); request.Content = new StringContent(System.Text.Json.JsonSerializer.Serialize(modelClient, ClientUtils.JsonSerializerOptions)); } List <TokenBase> tokens = new List <TokenBase>(); ApiKeyToken apiKey = (ApiKeyToken)await ApiKeyProvider.GetAsync(cancellationToken).ConfigureAwait(false); tokens.Add(apiKey); apiKey.UseInQuery(request, uriBuilder, parseQueryString, "api_key_query"); uriBuilder.Query = parseQueryString.ToString(); request.RequestUri = uriBuilder.Uri; string[] contentTypes = new string[] { "application/json" }; string contentType = ClientUtils.SelectHeaderContentType(contentTypes); if (contentType != null) { request.Content.Headers.Add("ContentType", contentType); } string[] accepts = new string[] { "application/json" }; string accept = ClientUtils.SelectHeaderAccept(accepts); if (accept != null) { request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(accept)); } request.Method = new HttpMethod("PATCH"); using (HttpResponseMessage responseMessage = await HttpClient.SendAsync(request, cancellationToken.GetValueOrDefault()).ConfigureAwait(false)) { DateTime requestedAt = DateTime.UtcNow; string responseContent = await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(false); if (ApiResponded != null) { try { ApiResponded.Invoke(this, new ApiResponseEventArgs(requestedAt, DateTime.UtcNow, responseMessage.StatusCode, "/fake_classname_test")); } catch (Exception e) { Logger.LogError(e, "An error occured while invoking ApiResponded."); } } ApiResponse <ModelClient> apiResponse = new ApiResponse <ModelClient>(responseMessage, responseContent); if (apiResponse.IsSuccessStatusCode) { apiResponse.Content = System.Text.Json.JsonSerializer.Deserialize <ModelClient>(apiResponse.RawContent, ClientUtils.JsonSerializerOptions); } else if (apiResponse.StatusCode == (HttpStatusCode)429) { foreach (TokenBase token in tokens) { token.BeginRateLimit(); } } return(apiResponse); } } } catch (Exception e) { Logger.LogError(e, "An error occured while sending the request to the server."); throw; } }