Ejemplo n.º 1
0
        /// <summary>
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        private static void ParseAdults(TripAdvisorRequest request, TripAdvisorResponse response)
        {
            if (HttpContext.Current.Request.Form["num_adults"] == null)
            {
                response.errors.Add("num_adults required");
                return;
            }

            int testInt;
            if (int.TryParse(HttpContext.Current.Request.Form["num_adults"], out testInt))
            {
                request.Adults = testInt;
            }
            else
                response.errors.Add("num_adults must be of type int");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Work out the api version they are using
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        private static void ParseApiVersion(TripAdvisorRequest request, TripAdvisorResponse response)
        {
            if (HttpContext.Current.Request.Form["api_version"] == null)
            {
                response.errors.Add("api_version required");
                return;
            }

            int testInt;
            if (int.TryParse(HttpContext.Current.Request.Form["api_version"], out testInt))
            {
                request.ApiVersion = testInt;
            }
            else
                response.errors.Add("api_version must be of type int");
        }
Ejemplo n.º 3
0
        protected override void OnPreLoad(EventArgs e)
        {
            var response = new TripAdvisorResponse();
            var request = new TripAdvisorRequest();
            ParseRequest(request, response);

            if (response.errors.Count == 0)
            {
                var aggResponce = SendSearchRequest(request);
                ParseResultSet(request, response, aggResponce);
            }

            var parser = new JavaScriptSerializer();
            var json = parser.Serialize(response);

            Response.Clear();
            Response.ContentType = "text/json";
            Response.Write(json);

            base.OnPreLoad(e);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// </summary>
        /// <param name="request"></param>
        private static void ParseCurrency(TripAdvisorRequest request)
        {
            if (HttpContext.Current.Request.Form["currency"] == null)
            {
                return;
            }

            request.currency = HttpContext.Current.Request.Form["currency"];
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Parses the <c>request</c> and turns into the <c>object</c> we need
 /// </summary>
 /// <param name="request"></param>
 /// <param name="response"></param>
 private void ParseRequest(TripAdvisorRequest request, TripAdvisorResponse response)
 {
     ParseApiVersion(request, response);
     ParseHotelIds(request, response);
     ParseStartDate(request, response);
     ParseEndDate(request, response);
     ParseAdults(request, response);
     ParseRooms(request, response);
     ParseQueryKey(request, response);
     ParseCurrency(request);
     ParseUserCountry(request);
     ParseDeviceType(request);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        private void ParseHotelIds(TripAdvisorRequest request, TripAdvisorResponse response)
        {
            if (HttpContext.Current.Request.Form["hotels"] == null)
            {
                response.errors.Add("hotel_ids required");
                return;
            }

            var parser = new JavaScriptSerializer();
            var dataToParse = HttpContext.Current.Request.Form["hotels"];

            // ReSharper disable AssignNullToNotNullAttribute
            var hotels = parser.Deserialize<List<TripAdvisorRequestHotels>>(Server.UrlDecode(dataToParse));
            // ReSharper restore AssignNullToNotNullAttribute
            request.Hotels = hotels;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private static AccommodationSearchResponse SendSearchRequest(TripAdvisorRequest request)
        {
            var myUri = new Uri(request.Hotels[0].partner_url);

            var superIds = new List<string>();
            foreach (var hotel in request.Hotels)
                superIds.Add(hotel.partner_id);

            var aggResponce = HotelSearch.Search(new AccommodationSearchRequest
                {
                    Authentication = new Authentication
                        {
                            UserName = "******",
                            Password = "******"
                        },
                    CheckIn = request.StartDate,
                    CheckOut = request.EndDate,
                    ChildAge = new List<int>(),
                    CityCode = long.Parse(HttpUtility.ParseQueryString(myUri.Query).Get("city")),
                    CountryCode = long.Parse(HttpUtility.ParseQueryString(myUri.Query).Get("country")),
                    MinStarRating = null,
                    NumberOfAdults = request.Adults,
                    NumberOfInfants = null,
                    NumberOfRooms = request.Rooms,
                    ResortCode = null,
                    SuperIds = superIds

                }, InitializeService.Settings);

            return aggResponce;
        }
Ejemplo n.º 8
0
 /// <summary>
 /// </summary>
 /// <param name="request"></param>
 private static void ParseUserCountry(TripAdvisorRequest request)
 {
     if (HttpContext.Current.Request.Form["user_country"] == null)
     {
         return;
     }
     request.user_country = HttpContext.Current.Request.Form["user_country"];
 }
Ejemplo n.º 9
0
        /// <summary>
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        private static void ParseStartDate(TripAdvisorRequest request, TripAdvisorResponse response)
        {
            if (HttpContext.Current.Request.Form["start_date"] == null)
            {
                response.errors.Add("start_date required");
                return;
            }

            DateTime testDate;
            if (DateTime.TryParse(HttpContext.Current.Request.Form["start_date"], out testDate))
            {
                request.StartDate = testDate;
            }
            else
                response.errors.Add("start_date must be of type date");
        }
Ejemplo n.º 10
0
        /// <summary>
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        /// <param name="accommodation"></param>
        private static void ParseResultSet(TripAdvisorRequest request, TripAdvisorResponse response, AccommodationSearchResponse accommodation)
        {
            try
            {

                // pass any errors over
                response.errors = accommodation.Message.Errors;

                response.api_version = 4;

                response.hotel_ids = new List<int>();
                foreach (var hotels in request.Hotels)
                {
                    response.hotel_ids.Add(hotels.ta_id);
                }

                response.start_date = request.StartDate.ToString("yyyy-MM-dd");
                response.end_date = request.EndDate.ToString("yyyy-MM-dd");
                response.num_adults = request.Adults;
                response.num_rooms = request.Rooms;
                response.currency = request.currency;
                response.user_country = request.user_country;
                response.device_type = request.device_type;
                response.query_key = request.QueryKey;
                response.lang = "en_GB";
                response.hotels = new List<TripAdvisorResponseHotel>();
                response.num_hotels = 0;

                if (accommodation.Results == null)
                    return;

                response.num_hotels = accommodation.Results.Count;

                // hotels here
                foreach (var hotel in accommodation.Results)
                {
                    var returnHotel = new TripAdvisorResponseHotel();

                    foreach (var tripAdvisorRequestHotelse in request.Hotels)
                    {
                        if (tripAdvisorRequestHotelse.partner_id == hotel.SuperId)
                        {
                            returnHotel.hotel_id = tripAdvisorRequestHotelse.ta_id;
                            break;
                        }
                    }

                    returnHotel.room_types = new Dictionary<string, TripAdvisorResponseRoomTypes>();

                    hotel.Rooms = (from rooms in hotel.Rooms
                                   orderby rooms.Price
                                   select rooms).ToList();
                    foreach (var room in hotel.Rooms)
                    {
                        var returnRoom = new TripAdvisorResponseRoomTypes
                            {
                                url = room.DeepLink,
                                price = room.Price,
                                taxes = 0,
                                taxes_at_checkout = 0,
                                fees = 0,
                                fees_at_checkout = 0,
                                final_price = room.Price,
                                currency = "GBP",
                                num_rooms = request.Rooms
                            };

                        if (!returnHotel.room_types.ContainsKey(room.RoomTitle))
                            returnHotel.room_types.Add(room.RoomTitle, returnRoom);
                    }
                    response.hotels.Add(returnHotel);
                }
            }
            catch (Exception exception)
            {
                ErrorHelper.SendErrorEmail(exception, "Error parsing results into trip advisor object " + Environment.NewLine + request, InitializeService.Settings);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        private static void ParseQueryKey(TripAdvisorRequest request, TripAdvisorResponse response)
        {
            if (HttpContext.Current.Request.Form["query_key"] == null)
            {
                response.errors.Add("query_key required");
                return;
            }

            request.QueryKey = HttpContext.Current.Request.Form["query_key"];
        }
Ejemplo n.º 12
0
 /// <summary>
 /// </summary>
 /// <param name="request"></param>
 private static void ParseDeviceType(TripAdvisorRequest request)
 {
     if (HttpContext.Current.Request.Form["device_type"] == null)
     {
         return;
     }
     request.device_type = HttpContext.Current.Request.Form["device_type"];
 }