示例#1
0
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
        /// <summary>BOOK ROOMS</summary>
        /// <param name="requestBody">`offerId`, `guests`, `payments` and optional `rooms` for the repartition (when used the `rooms` array items must match the shopping offer `roomQuantity`)</param>
        /// <param name="ama_Client_Ref">Client Reference to track Request/Response</param>
        /// <param name="accept_Encoding">Compress the Response</param>
        /// <returns>Booked</returns>
        /// <exception cref="ApiException">A server side error occurred.</exception>
        public async System.Threading.Tasks.Task <HotelBookedResponse> CreateBookingAsync(BookingSchema requestBody, string ama_Client_Ref, AcceptEncoding?accept_Encoding, System.Threading.CancellationToken cancellationToken)
        {
            if (requestBody == null)
            {
                throw new System.ArgumentNullException("requestBody");
            }

            var urlBuilder_ = new System.Text.StringBuilder();

            urlBuilder_.Append("booking/hotel-bookings");

            var client_ = _httpClient;

            try
            {
                using (var request_ = new System.Net.Http.HttpRequestMessage())
                {
                    if (ama_Client_Ref != null)
                    {
                        request_.Headers.TryAddWithoutValidation("Ama-Client-Ref", ConvertToString(ama_Client_Ref, System.Globalization.CultureInfo.InvariantCulture));
                    }
                    if (accept_Encoding != null)
                    {
                        request_.Headers.TryAddWithoutValidation("Accept-Encoding", ConvertToString(accept_Encoding, System.Globalization.CultureInfo.InvariantCulture));
                    }
                    var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(requestBody, _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);

                    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).ToString();
                        if (status_ == "201")
                        {
                            var objectResponse_ = await ReadObjectResponseAsync <HotelBookedResponse>(response_, headers_).ConfigureAwait(false);

                            return(objectResponse_.Object);
                        }
                        else
                        if (status_ == "400")
                        {
                            var objectResponse_ = await ReadObjectResponseAsync <ErrorResponse>(response_, headers_).ConfigureAwait(false);

                            throw new ApiException <ErrorResponse>("Bad Request\n\ncode    | title                                                          | owner    | pointer\n------- | -------------------------------------------------------------- | -------- | -------\n  477   | INVALID FORMAT                                                 | Amadeus  | \n 4725   | INVALID PASSENGER ASSOCIATION                                  | Amadeus  | data/rooms/guestIds\n33555   | NUMBER OF ROOMS MISMATCH BETWEEN SHOPPING AND BOOKING          | Amadeus  | data/rooms\n33554   | PRICE HAS CHANGED. PLEASE GET A NEW OFFERID AND TRY AGAIN      | Amadeus  | data/offerId\n36803   | OFFERID HAS EXPIRED. PLEASE GET A NEW OFFERID AND TRY AGAIN    | Amadeus  | data/offerId\n 1205   | INVALID CREDIT CARD TYPE                                       | Amadeus  | data/payments/card/vendorCode\n 8517   | INVALID CREDIT CARD NUMBER                                     | Provider | data/payments/card/cardNumber\n 1427   | GUARANTEE REQUIRED                                             | Provider | data/payments/card\n 1146   | DEPOSIT REQUIRED                                               | Provider | data/payments/card\n 3659   | CREDIT CARD DEPOSIT REQUIRED                                   | Provider | data/payments/card\n 3682   | CREDIT CARD NOT ACCEPTED AT HOTEL PROPERTY                     | Provider | data/payments/card/vendorCode\n 3871   | CREDIT CARD EXPIRATION DATE INVALID FOR CHECK IN DATE          | Provider | data/payments/card/expiryDate\n \n", (int)response_.StatusCode, objectResponse_.Text, headers_, objectResponse_.Object, null);
                        }
                        else
                        if (status_ == "500")
                        {
                            var objectResponse_ = await ReadObjectResponseAsync <ErrorResponse>(response_, headers_).ConfigureAwait(false);

                            throw new ApiException <ErrorResponse>("Internal Server Error\n\ncode    | title                                                          | owner                                \n------- | -------------------------------------------------------------- | -------\n00011   | UNABLE TO PROCESS                                              | Provider\n04070   | UNABLE TO PROCESS - CONTACT HELP DESK                          | Amadeus\n", (int)response_.StatusCode, objectResponse_.Text, headers_, objectResponse_.Object, null);
                        }
                        else
                        if (status_ != "200" && status_ != "204")
                        {
                            var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);

                            throw new ApiException("The HTTP status code of the response was not expected (" + (int)response_.StatusCode + ").", (int)response_.StatusCode, responseData_, headers_, null);
                        }

                        return(default(HotelBookedResponse));
                    }
                    finally
                    {
                        if (response_ != null)
                        {
                            response_.Dispose();
                        }
                    }
                }
            }
            finally
            {
            }
        }
示例#2
0
 /// <summary>BOOK ROOMS</summary>
 /// <param name="requestBody">`offerId`, `guests`, `payments` and optional `rooms` for the repartition (when used the `rooms` array items must match the shopping offer `roomQuantity`)</param>
 /// <param name="ama_Client_Ref">Client Reference to track Request/Response</param>
 /// <param name="accept_Encoding">Compress the Response</param>
 /// <returns>Booked</returns>
 /// <exception cref="ApiException">A server side error occurred.</exception>
 public System.Threading.Tasks.Task <HotelBookedResponse> CreateBookingAsync(BookingSchema requestBody, string ama_Client_Ref, AcceptEncoding?accept_Encoding)
 {
     return(CreateBookingAsync(requestBody, ama_Client_Ref, accept_Encoding, System.Threading.CancellationToken.None));
 }