// This is the main method responsible for getting flight data // It calls the QPX Express API and establishes authentication // It is called by FlightData.cs and also by the Timer that checks // if a price has changed public static List <string> GetFlightPrices(bool save, Dictionary <string, Airport> airports, FlightDetails fd, out string guid, out TripsSearchResponse result) { List <string> p = new List <string>(); guid = string.Empty; // Authentication with the QPX Express API using (QPXExpressService service = new QPXExpressService(new BaseClientService.Initializer() { ApiKey = CloudConfigurationManager.GetSetting(StrConsts.cStrQpxApiKey), ApplicationName = CloudConfigurationManager.GetSetting(StrConsts.cStrBotId) })) { TripsSearchRequest x = null; result = null; // Executes the flight / trip request using the QPX Express API string failed = CreateExecuteRequest(fd, service, out x, out result); if (result != null) { // Process the results obtained from the QPX Express API p = ProcessResult(save, airports, x.Request, result, fd, x.Request.Solutions, fd.InboundDate, out guid); } else { p.Add(failed + StrConsts._NewLine + StrConsts._NewLine + GatherErrors.cStrCouldFetchData); } } return(p); }
private TripsSearchResponse CallGoogleApi() { QPXExpressService service = new QPXExpressService(new BaseClientService.Initializer() { ApiKey = "AIzaSyCpjedj9wpLTgXxKMTquLYWtq0awsASYgQ", ApplicationName = "CodeFlyingKetchup", }); TripsSearchRequest x = new TripsSearchRequest { Request = new TripOptionsRequest { Passengers = new PassengerCounts { AdultCount = 2 }, Slice = new List <SliceInput> { new SliceInput() { Origin = "TPA", Destination = "SEA", Date = "2017-10-29" } }, Solutions = 10 } }; return(service.Trips.Search(x).Execute()); }
// Main submethod that executes the flight request to the QPX Express API private static string CreateExecuteRequest(FlightDetails fd, QPXExpressService service, out TripsSearchRequest x, out TripsSearchResponse result) { string failed = string.Empty; x = new TripsSearchRequest(); result = null; try { x.Request = new TripOptionsRequest(); int nump = Convert.ToInt32(fd.NumPassengers); x.Request.Passengers = new PassengerCounts { AdultCount = nump }; x.Request.Slice = AddTrips(fd); x.Request.Solutions = DetermineSolutions(fd); result = service.Trips.Search(x).Execute(); } catch { failed = GatherQuestions.cStrGatherProcessTryAgain; } return(failed); }
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()); }
//AIzaSyAuHEH2vQFNlS19Y7pBD95BC-4y4Lt8zsw public async Task SearchForFlights(IDialogContext context) { var airports = new List <string>(); var trips = new List <string>(); QPXExpressService service = new QPXExpressService(new BaseClientService.Initializer() { ApiKey = "AIzaSyAuHEH2vQFNlS19Y7pBD95BC-4y4Lt8zsw", ApplicationName = "DontPanicAdventures" }); TripsSearchRequest qpxRequest = new TripsSearchRequest(); qpxRequest.Request = new TripOptionsRequest(); qpxRequest.Request.Passengers = new PassengerCounts { AdultCount = 1 }; qpxRequest.Request.Slice = new List <SliceInput>(); qpxRequest.Request.Slice.Add(new SliceInput() { Origin = departureCity, Destination = arrivalCity, Date = departureDate }); qpxRequest.Request.MaxPrice = maxBudget; qpxRequest.Request.Solutions = 5; var results = service.Trips.Search(qpxRequest).Execute(); foreach (var airport in results.Trips.Data.Airport) { airports.Add(airport.Code + " || " + airport.Name + " || " + airport.City); } foreach (var trip in results.Trips.TripOption) { trips.Add("Flight No.: " + trip.Slice.FirstOrDefault().Segment.FirstOrDefault().Flight.Number + " || Duration: " + trip.Slice.FirstOrDefault().Duration + " || Price: " + trip.Pricing.FirstOrDefault().BaseFareTotal.ToString()); } var flights = airports.Zip(trips, (a, t) => a + " || " + t); foreach (var flight in flights) { await context.PostAsync(flight); } PromptDialog.Text( context, StartNewSearch, "Thanks for using our services! Would you like to start a new search?", "Sorry I didn't catch that. Did you want to start a new search?"); }
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()); }
public Object FetchAllFlights(TripsSearchRequest tripSearchRequest) { try { QPXExpressService service = new QPXExpressService(new BaseClientService.Initializer() { ApiKey = "AIzaSyAJ1NjLJLHj2IyiQa1SYfiRiYiDSw_RBhg", ApplicationName = "API key 1", }); //var result = new TripsSearchResponse(); var result = service.Trips.Search(tripSearchRequest).Execute(); var json = JsonConvert.SerializeObject(result); return(result); } catch (Exception ex) { Exceptions exceptions = new Exceptions(); exceptions.ExceptionMessage = "Error in BookFlight() :" + ex.InnerException; return(exceptions); } }
/// <summary> /// Returns a list of flights. /// Documentation https://developers.google.com/qpxexpress/v1/reference/trips/search /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated QPXExpress service.</param> /// <param name="body">A valid QPXExpress v1 body.</param> /// <returns>TripsSearchResponseResponse</returns> public static TripsSearchResponse Search(QPXExpressService service, TripsSearchRequest body) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (body == null) { throw new ArgumentNullException("body"); } // Make the request. return(service.Trips.Search(body).Execute()); } catch (Exception ex) { throw new Exception("Request Trips.Search failed.", ex); } }