public async Task <ApiResponse <object?> > DeleteOrderWithHttpInfoAsync(string orderId, 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 (orderId == null) { throw new ArgumentNullException(nameof(orderId)); } #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 + "/store/order/{order_id}"; uriBuilder.Path = uriBuilder.Path.Replace("%7Border_id%7D", Uri.EscapeDataString(orderId.ToString())); request.RequestUri = uriBuilder.Uri; request.Method = HttpMethod.Delete; using (HttpResponseMessage responseMessage = await HttpClient.SendAsync(request, cancellationToken.GetValueOrDefault()).ConfigureAwait(false)) { DateTime requestedAt = DateTime.UtcNow; string responseContent = await responseMessage.Content.ReadAsStringAsync(cancellationToken.GetValueOrDefault()).ConfigureAwait(false); if (ApiResponded != null) { try { ApiResponded.Invoke(this, new ApiResponseEventArgs(requestedAt, DateTime.UtcNow, responseMessage.StatusCode, "/store/order/{order_id}")); } catch (Exception e) { Logger.LogError(e, "An error occured while invoking ApiResponded."); } } ApiResponse <object?> apiResponse = new ApiResponse <object?>(responseMessage, responseContent); if (apiResponse.IsSuccessStatusCode) { apiResponse.Content = Newtonsoft.Json.JsonConvert.DeserializeObject <object>(apiResponse.RawContent, ClientUtils.JsonSerializerSettings); } return(apiResponse); } } } catch (Exception e) { Logger.LogError(e, "An error occured while sending the request to the server."); throw; } }
public async Task <ApiResponse <Order?> > PlaceOrderWithHttpInfoAsync(Order order, 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 (order == null) { throw new ArgumentNullException(nameof(order)); } #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 + "/store/order"; if ((order as object) is System.IO.Stream stream) { request.Content = new StreamContent(stream); } else { request.Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(order, ClientUtils.JsonSerializerSettings)); } 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/xml", "application/json" }; string?accept = ClientUtils.SelectHeaderAccept(accepts); if (accept != null) { request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(accept)); } request.Method = HttpMethod.Post; using (HttpResponseMessage responseMessage = await HttpClient.SendAsync(request, cancellationToken.GetValueOrDefault()).ConfigureAwait(false)) { DateTime requestedAt = DateTime.UtcNow; string responseContent = await responseMessage.Content.ReadAsStringAsync(cancellationToken.GetValueOrDefault()).ConfigureAwait(false); if (ApiResponded != null) { try { ApiResponded.Invoke(this, new ApiResponseEventArgs(requestedAt, DateTime.UtcNow, responseMessage.StatusCode, "/store/order")); } catch (Exception e) { Logger.LogError(e, "An error occured while invoking ApiResponded."); } } ApiResponse <Order?> apiResponse = new ApiResponse <Order?>(responseMessage, responseContent); if (apiResponse.IsSuccessStatusCode) { apiResponse.Content = Newtonsoft.Json.JsonConvert.DeserializeObject <Order>(apiResponse.RawContent, ClientUtils.JsonSerializerSettings); } return(apiResponse); } } } catch (Exception e) { Logger.LogError(e, "An error occured while sending the request to the server."); throw; } }
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 = HttpMethod.Get; using (HttpResponseMessage responseMessage = await HttpClient.SendAsync(request, cancellationToken.GetValueOrDefault()).ConfigureAwait(false)) { DateTime requestedAt = DateTime.UtcNow; string responseContent = await responseMessage.Content.ReadAsStringAsync(cancellationToken.GetValueOrDefault()).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 = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, int> >(apiResponse.RawContent, ClientUtils.JsonSerializerSettings); } 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 special tags To test special tags and operation ID starting with number /// </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> > Call123TestSpecialTagsWithHttpInfoAsync(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 + "/another-fake/dummy"; request.Content = (modelClient as object) is System.IO.Stream stream ? request.Content = new StreamContent(stream) : request.Content = new StringContent(JsonSerializer.Serialize(modelClient, _jsonSerializerOptions)); 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, "/another-fake/dummy")); } 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 = JsonSerializer.Deserialize <ModelClient>(apiResponse.RawContent, _jsonSerializerOptions); } return(apiResponse); } } } catch (Exception e) { Logger.LogError(e, "An error occured while sending the request to the server."); throw; } }
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 = HttpMethod.Patch; using (HttpResponseMessage responseMessage = await HttpClient.SendAsync(request, cancellationToken.GetValueOrDefault()).ConfigureAwait(false)) { DateTime requestedAt = DateTime.UtcNow; string responseContent = await responseMessage.Content.ReadAsStringAsync(cancellationToken.GetValueOrDefault()).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; } }
public async Task <ApiResponse <InlineResponseDefault?> > FooGetWithHttpInfoAsync(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 + "/foo"; 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 = HttpMethod.Get; using (HttpResponseMessage responseMessage = await HttpClient.SendAsync(request, cancellationToken.GetValueOrDefault()).ConfigureAwait(false)) { DateTime requestedAt = DateTime.UtcNow; string responseContent = await responseMessage.Content.ReadAsStringAsync(cancellationToken.GetValueOrDefault()).ConfigureAwait(false); if (ApiResponded != null) { try { ApiResponded.Invoke(this, new ApiResponseEventArgs(requestedAt, DateTime.UtcNow, responseMessage.StatusCode, "/foo")); } catch (Exception e) { Logger.LogError(e, "An error occured while invoking ApiResponded."); } } ApiResponse <InlineResponseDefault?> apiResponse = new ApiResponse <InlineResponseDefault?>(responseMessage, responseContent); if (apiResponse.IsSuccessStatusCode) { apiResponse.Content = JsonSerializer.Deserialize <InlineResponseDefault>(apiResponse.RawContent, _jsonSerializerOptions); } return(apiResponse); } } } catch (Exception e) { Logger.LogError(e, "An error occured while sending the request to the server."); throw; } }
/// <summary> /// Find purchase order by ID For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions /// </summary> /// <exception cref="ApiException">Thrown when fails to make API call</exception> /// <param name="orderId">ID of pet that needs to be fetched</param> /// <param name="cancellationToken">Cancellation Token to cancel the request.</param> /// <returns><see cref="Task"/><<see cref="ApiResponse{T}"/>> where T : <see cref="Order"/></returns> public async Task <ApiResponse <Order> > GetOrderByIdWithHttpInfoAsync(long orderId, 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' #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 + "/store/order/{order_id}"; uriBuilder.Path = uriBuilder.Path.Replace("%7Border_id%7D", Uri.EscapeDataString(orderId.ToString())); request.RequestUri = uriBuilder.Uri; string[] accepts = new string[] { "application/xml", "application/json" }; string accept = ClientUtils.SelectHeaderAccept(accepts); if (accept != null) { request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(accept)); } request.Method = HttpMethod.Get; using (HttpResponseMessage responseMessage = await HttpClient.SendAsync(request, cancellationToken.GetValueOrDefault()).ConfigureAwait(false)) { DateTime requestedAt = DateTime.UtcNow; string responseContent = await responseMessage.Content.ReadAsStringAsync(cancellationToken.GetValueOrDefault()).ConfigureAwait(false); if (ApiResponded != null) { try { ApiResponded.Invoke(this, new ApiResponseEventArgs(requestedAt, DateTime.UtcNow, responseMessage.StatusCode, "/store/order/{order_id}")); } catch (Exception e) { Logger.LogError(e, "An error occured while invoking ApiResponded."); } } ApiResponse <Order> apiResponse = new ApiResponse <Order>(responseMessage, responseContent); if (apiResponse.IsSuccessStatusCode) { apiResponse.Content = JsonSerializer.Deserialize <Order>(apiResponse.RawContent, _jsonSerializerOptions); } return(apiResponse); } } } catch (Exception e) { Logger.LogError(e, "An error occured while sending the request to the server."); throw; } }