public HotelSearchResponse Search(HotelSearchRequest hotelSearchRequest)
        {
            var url  = "http://api.hotelbeds.com/hotel-api/1.0/availability";
            var json = getJson(hotelSearchRequest);

            var hotelSearchResponse = new HotelSearchResponse();

            hotelSearchResponse.HotelStays = new List <HotelStay>();

            using (var client = new WebClient())
            {
                client.Headers.Add("Content-Type", "application/json");
                client.Headers.Add("Api-Key", "6262k3bddqe67jsbahb9wqnx");

                byte[] responsebytes = client.UploadData(url, "POST",
                                                         System.Text.Encoding.ASCII.GetBytes(json));
                string jsonresponse = Encoding.UTF8.GetString(responsebytes);

                var data = JsonConvert.DeserializeObject <dynamic>(jsonresponse);

                foreach (var hotel in data.hotels.hotels)
                {
                    hotelSearchResponse.HotelStays.Add(new HotelStay()
                    {
                        HotelId      = Convert.ToInt32(hotel.code),
                        Latitude     = hotel.latitude,
                        Longitude    = hotel.longitude,
                        Price        = hotel.minPrice,
                        LocationName = hotel.destination
                    });
                }
            }

            return(hotelSearchResponse);
        }
        public async Task <HotelSearchResponse> Search(HotelSearchRequest hotelSearchRequest)
        {
            var url  = "http://api.hotelbeds.com/hotel-api/1.0/availability";
            var json = System.IO.File.ReadAllText(@"C:\code\thack2015\JSONSamples\HotelBedsRequest.json");

            using (var httpClient = new HttpClient())
            {
                httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, url);
                // Add our custom user agent
                request.Headers.Add("Api-Key", "6262k3bddqe67jsbahb9wqnx");
                // Send the request to the server
                // Send the request to the server
                HttpResponseMessage response = await httpClient.SendAsync(request);
            }

            return(new HotelSearchResponse());
        }
        private string getJson(HotelSearchRequest hotelSearchRequest)
        {
            var json = @"
                {
                ""stay"": {
                    ""checkIn"": """ + hotelSearchRequest.StartDate.ToString("yyyy-MM-dd ") + @""",
                    ""checkOut"": """ + hotelSearchRequest.StartDate.AddDays(1).ToString("yyyy-MM-dd").ToString() + @"""
                },
                ""occupancies"": [
                    {
                        ""rooms"": 1,
                        ""adults"": 2,
                        ""children"": 0,
                        ""paxes"": [
                            {
                                ""type"": ""AD"",
                                ""age"": 30
                            },
                            {
                                ""type"": ""AD"",
                                ""age"": 30
                            }
                        ]
                    }
                ],
                ""geolocation"": {
                    ""latitude"": """ + hotelSearchRequest.Latitude + @""",
                    ""longitude"": """ + hotelSearchRequest.Longitude + @""",
                    ""radius"": " + hotelSearchRequest.Radius + @",
                    ""unit"": ""km""
                },
                ""limit"": {
                    ""maxHotels"": 100
                }
            }";

            return(json);
        }
Esempio n. 4
0
        public HotelSearchResponse Search(HotelSearchRequest hotelSearchRequest)
        {
            var hotelSearchResponse = new HotelSearchResponse();

            hotelSearchResponse.HotelStays = new List <HotelStay>();
            hotelSearchResponse.HotelStays.Add(new HotelStay()
            {
                HotelId      = 12345,
                Latitude     = "Munich City Center",
                Longitude    = "-5.10000000",
                LocationName = "64.10000000",
                Price        = 99.99M
            });
            hotelSearchResponse.HotelStays.Add(new HotelStay()
            {
                HotelId      = 545354,
                Latitude     = "Manchester Palace",
                Longitude    = "-6.10000000",
                LocationName = "66.10000000",
                Price        = 20.00M
            });

            return(hotelSearchResponse);
        }
 public HotelSearchResponse Search(HotelSearchRequest hotelSearchRequest)
 {
     throw new NotImplementedException();
 }