public Success SearchFlightOffers(string x_HTTP_Method_Override, GetFlightOffersQuery getFlightOffersBody) { return(System.Threading.Tasks.Task.Run(async() => await SearchFlightOffersAsync(x_HTTP_Method_Override, getFlightOffersBody, System.Threading.CancellationToken.None)).GetAwaiter().GetResult()); }
public async System.Threading.Tasks.Task <Success> SearchFlightOffersAsync(string x_HTTP_Method_Override, GetFlightOffersQuery getFlightOffersBody, System.Threading.CancellationToken cancellationToken) { if (getFlightOffersBody == null) { throw new System.ArgumentNullException("getFlightOffersBody"); } var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/shopping/flight-offers"); var client_ = _httpClient; var disposeClient_ = false; try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { if (x_HTTP_Method_Override == null) { throw new System.ArgumentNullException("x_HTTP_Method_Override"); } request_.Headers.TryAddWithoutValidation("X-HTTP-Method-Override", ConvertToString(x_HTTP_Method_Override, System.Globalization.CultureInfo.InvariantCulture)); var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(getFlightOffersBody, _settings.Value)); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/vnd.amadeus+json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/vnd.amadeus+json")); PrepareRequest(client_, request_, urlBuilder_); var url_ = urlBuilder_.ToString(); request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); PrepareRequest(client_, request_, url_); var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); var disposeResponse_ = true; try { var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value); if (response_.Content != null && response_.Content.Headers != null) { foreach (var item_ in response_.Content.Headers) { headers_[item_.Key] = item_.Value; } } ProcessResponse(client_, response_); var status_ = (int)response_.StatusCode; if (status_ == 200) { var objectResponse_ = await ReadObjectResponseAsync <Success>(response_, headers_, cancellationToken).ConfigureAwait(false); if (objectResponse_.Object == null) { throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } return(objectResponse_.Object); } else if (status_ == 400) { var objectResponse_ = await ReadObjectResponseAsync <Error_400>(response_, headers_, cancellationToken).ConfigureAwait(false); if (objectResponse_.Object == null) { throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } throw new ApiException <Error_400>("code | title \n------- | ------------------------------------- \n425 | INVALID DATE\n477 | INVALID FORMAT\n2668 | PARAMETER COMBINATION INVALID/RESTRICTED\n4926 | INVALID DATA RECEIVED\n10661 | MAXIMUM NUMBER OF OCCURRENCES EXCEEDED \n32171 | MANDATORY DATA MISSING\n", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else { var objectResponse_ = await ReadObjectResponseAsync <Error_500>(response_, headers_, cancellationToken).ConfigureAwait(false); if (objectResponse_.Object == null) { throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } throw new ApiException <Error_500>("Unexpected error", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } } finally { if (disposeResponse_) { response_.Dispose(); } } } } finally { if (disposeClient_) { client_.Dispose(); } } }
public System.Threading.Tasks.Task <Success> SearchFlightOffersAsync(string x_HTTP_Method_Override, GetFlightOffersQuery getFlightOffersBody) { return(SearchFlightOffersAsync(x_HTTP_Method_Override, getFlightOffersBody, System.Threading.CancellationToken.None)); }