示例#1
0
 public HotelApiClient(HotelApiVersion version)
 {
     this.apiKey       = GetHotelApiKeyFromConfig();
     this.sharedSecret = GetHotelSharedSecretFromConfig();
     this.version      = version;
     this.basePath     = GetEnvironment();
     CheckHotelApiClientConfig();
 }
示例#2
0
 public HotelApiClient(HotelApiVersion version, string apiKey, string sharedSecret)
 {
     this.apiKey       = apiKey;
     this.sharedSecret = sharedSecret;
     this.version      = version;
     this.basePath     = GetEnvironment();
     CheckHotelApiClientConfig();
 }
示例#3
0
 public BookingRS confirm(BookingRQ bookingRQ)
 {
     try
     {
         HotelApiPaths.BOOKING_CONFIRM bookingConfirm = new HotelApiPaths.BOOKING_CONFIRM();
         HotelApiVersion version  = this.version;
         string          baseUrl  = (bookingRQ != null && bookingRQ.paymentData != null) ? this.baseSecurePath : this.basePath;
         BookingRS       response = callRemoteApi <BookingRS, BookingRQ>(bookingRQ, bookingConfirm, null, version, baseUrl);
         return(response);
     } catch (HotelSDKException e)
     {
         throw e;
     }
 }
        private HotelApiClient(HotelApiVersion version, string apiKey, string sharedSecret, Boolean validate, TimeSpan timeout, string basePath, string baseSecurePath)
        {
            this.timeout        = timeout;
            this.apiKey         = apiKey;
            this.sharedSecret   = sharedSecret;
            this.version        = version;
            this.basePath       = basePath;
            this.baseSecurePath = baseSecurePath;

            if (validate)
            {
                CheckHotelApiClientConfig();
            }
        }
示例#5
0
 private HotelApiClient(HotelApiVersion version, string apiKey, string sharedSecret, Boolean validate)
 {
     this.timeout      = GetTimeoutFromConfig();
     this.apiKey       = apiKey;
     this.sharedSecret = sharedSecret;
     this.version      = version;
     config.Environment currentEnvironment = GetEnvironment();
     if (currentEnvironment != null)
     {
         this.basePath       = currentEnvironment.BaseUrl;
         this.baseSecurePath = (currentEnvironment.BaseSecureUrl != null) ? currentEnvironment.BaseSecureUrl : currentEnvironment.BaseUrl;
     }
     if (validate)
     {
         CheckHotelApiClientConfig();
     }
 }
示例#6
0
 public HotelApiClient(HotelApiVersion version, string apiKey, string sharedSecret) : this(version, apiKey, sharedSecret, true)
 {
 }
示例#7
0
 public HotelApiClient(HotelApiVersion version) : this(version, null, null, false)
 {
     this.apiKey       = GetHotelApiKeyFromConfig();
     this.sharedSecret = GetHotelSharedSecretFromConfig();
     CheckHotelApiClientConfig();
 }
示例#8
0
        private T callRemoteApi <T, U>(U request, HotelApiPaths.HotelApiPathsBase path, List <Tuple <string, string> > param, HotelApiVersion version, string baseUrl)
        {
            try
            {
                T response = default(T);

                using (var client = new HttpClient(
                           new HttpClientHandler()
                {
                    AutomaticDecompression = System.Net.DecompressionMethods.GZip
                }))
                {
                    if (request == null && (path.GetType() != typeof(HotelApiPaths.STATUS) &&
                                            path.GetType() != typeof(HotelApiPaths.BOOKING_CANCEL) && path.GetType() != typeof(HotelApiPaths.BOOKING_DETAIL) && path.GetType() != typeof(HotelApiPaths.BOOKING_LIST)))
                    {
                        throw new Exception("Object request can't be null");
                    }

                    client.BaseAddress = new Uri(path.getUrl(baseUrl, version));
                    client.DefaultRequestHeaders.Clear();
                    client.Timeout = this.timeout;
                    client.DefaultRequestHeaders.Add("Api-Key", this.apiKey);

                    long   ts         = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds / 1000;
                    SHA256 hashstring = SHA256Managed.Create();
                    byte[] hash       = hashstring.ComputeHash(Encoding.UTF8.GetBytes(this.apiKey + this.sharedSecret + ts));
                    string signature  = BitConverter.ToString(hash).Replace("-", "");
                    client.DefaultRequestHeaders.Add("X-Signature", signature.ToString());
                    client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; charset=utf-8");
                    client.DefaultRequestHeaders.TryAddWithoutValidation("Accept", "application/json; charset=utf-8");
                    client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "hotel-api-sdk-net");


                    // GET Method
                    if (path.getHttpMethod() == HttpMethod.Get)
                    {
                        string Uri = path.getEndPoint();

                        if (param != null)
                        {
                            Uri = path.getEndPoint(param);
                        }

                        HttpResponseMessage resp = client.GetAsync(Uri).Result;
                        response = resp.Content.ReadAsAsync <T>().Result;
                        return(response);
                    }

                    // DELETE Method
                    if (path.getHttpMethod() == HttpMethod.Delete)
                    {
                        string Uri = path.getEndPoint();

                        if (param != null)
                        {
                            Uri = path.getEndPoint(param);
                        }

                        HttpResponseMessage resp = client.DeleteAsync(Uri).Result;
                        response = resp.Content.ReadAsAsync <T>().Result;
                        return(response);
                    }

                    StringContent contentToSend = null;
                    if (request != null)
                    {
                        string objectSerialized = JsonConvert.SerializeObject(request, Formatting.Indented, new JsonSerializerSettings()
                        {
                            DefaultValueHandling = DefaultValueHandling.Ignore
                        });
                        contentToSend = new StringContent(objectSerialized, Encoding.UTF8, "application/json");
                    }

                    if (path.getHttpMethod() == HttpMethod.Post)
                    {
                        HttpResponseMessage resp = null;
                        if (param == null)
                        {
                            resp = client.PostAsync(path.getEndPoint(), contentToSend).Result;
                        }
                        else
                        {
                            resp = client.PostAsync(path.getEndPoint(param), contentToSend).Result;
                        }

                        response = resp.Content.ReadAsAsync <T>().Result;
                    }
                }

                return(response);
            } catch (HotelSDKException e)
            {
                throw e;
            }
        }
示例#9
0
 private T callRemoteApi <T, U>(U request, HotelApiPaths.HotelApiPathsBase path, List <Tuple <string, string> > param, HotelApiVersion version)
 {
     return(callRemoteApi <T, U>(request, path, param, version, this.basePath));
 }