Exemple #1
0
        // Adds the trips that will be part of the flight request
        // that will be sent to the QPX Express API
        private static IList <SliceInput> AddTrips(FlightDetails fd)
        {
            List <SliceInput> trips = new List <SliceInput>();

            string goDate = ToQpxDateFormat(fd.OutboundDate);

            // Outbound trip request details
            SliceInput goTrip = new SliceInput()
            {
                Origin      = fd.OriginIata,
                Destination = fd.DestinationIata,
                Date        = goDate
            };

            trips.Add(goTrip);

            // Inbound trip request details
            // (if the flight request is not 'one way'
            if (fd.InboundDate.ToLower() != GatherQuestions.cStrGatherProcessOneWay.ToLower())
            {
                string returnDate = ToQpxDateFormat(fd.InboundDate);

                SliceInput returnTrip = new SliceInput()
                {
                    Origin      = fd.DestinationIata,
                    Destination = fd.OriginIata,
                    Date        = returnDate
                };

                trips.Add(returnTrip);
            }

            return(trips);
        }
        public static string[] GetFlightPrice()
        {
            List <string> p = new List <string>();

            using (QPXExpressService service = new QPXExpressService(new BaseClientService.Initializer()
            {
                ApiKey = cStrApiKey,
                ApplicationName = cStrAppName
            }))
            {
                TripsSearchRequest x = new TripsSearchRequest();
                x.Request            = new TripOptionsRequest();
                x.Request.Passengers = new PassengerCounts {
                    AdultCount = 2
                };
                x.Request.Slice = new List <SliceInput>();

                var s = new SliceInput()
                {
                    Origin = "JFK", Destination = "BOS", Date = "2016-12-09"
                };

                x.Request.Slice.Add(s);
                x.Request.Solutions = 10;

                var result = service.Trips.Search(x).Execute();

                foreach (var trip in result.Trips.TripOption)
                {
                    p.Add(trip.Pricing.FirstOrDefault().BaseFareTotal.ToString());
                }
            }

            return(p.ToArray());
        }
Exemple #3
0
        public TripsSearchResponse Get(string origin = "", string destination = "", DateTime?departureTime = null, int?adultCount = null)
        {
            if (string.IsNullOrEmpty(origin))
            {
                origin = "ORD";
            }
            if (string.IsNullOrEmpty(destination))
            {
                destination = "SFO";
            }

            if (departureTime == null)
            {
                departureTime = DateTime.Now.AddDays(30);
            }
            if (adultCount == null)
            {
                adultCount = 1;
            }


            BaseClientService.Initializer initializer = new BaseClientService.Initializer();
            initializer.ApiKey          = ConfigurationManager.AppSettings["QPX.Key"];
            initializer.ApplicationName = "JinFlightSearch";
            QPXExpressService service = new QPXExpressService(initializer);
            SliceInput        slice   = new SliceInput
            {
                Date        = departureTime.Value.ToString("yyyy-MM-dd"),
                Origin      = origin,
                Destination = destination,
            };
            List <SliceInput> slices = new List <SliceInput>();

            slices.Add(slice);
            TripsSearchRequest request = new TripsSearchRequest
            {
                Request = new TripOptionsRequest
                {
                    Passengers = new PassengerCounts
                    {
                        AdultCount = adultCount,
                    },
                    Slice = slices
                }
            };

            TripsResource.SearchRequest r = new TripsResource.SearchRequest(service, request);
            return(r.Execute());
        }