public FlightResponsePinger(string apiKey, Uri sessionUri, FlightResponseSettings flightResponseSettings) : base(apiKey) { _location = sessionUri; _querySettings = GetQueryString(flightResponseSettings); }
private static async Task SearchDetailed() { //Initialize Scanner var scanner = new Scanner( ConfigurationManager.AppSettings["apiKey"], RetryExecutionStrategy.Default); //Query locales var locales = await scanner.QueryLocale(); var currentLocale = locales.FirstOrDefault(locale => locale.Name.StartsWith("English")); if (currentLocale == null) { WriteLine(ErrorColor, "Couldn't find locale, using default instead"); currentLocale = Locale.Default; } //Query markets var markets = await scanner.QueryMarket(currentLocale); var currentMarket = markets.FirstOrDefault(market => market.Name == "Switzerland"); if (currentMarket == null) { WriteLine(ErrorColor, "Couldn't find market, using default instead"); currentMarket = Market.Default; } //Query currencies var currencies = await scanner.QueryCurrency(); var currentCurrency = currencies.FirstOrDefault(currency => currency.Code == "CHF"); if (currentCurrency == null) { WriteLine(ErrorColor, "Couldn't find currency, using default instead"); currentCurrency = Currency.Default; } //Query location const string fromPlaceName = "London"; var from = (await scanner.QueryLocation(new LocationAutosuggestSettings(fromPlaceName, LocationAutosuggestQueryType.Query, currentMarket, currentCurrency, currentLocale))).First(); if (from == null) { WriteLine(ErrorColor, "Couldn't find '{0}'", fromPlaceName); return; } //Query destination location const string toPlaceName = "New York"; var to = (await scanner.QueryLocation(new LocationAutosuggestSettings(toPlaceName, LocationAutosuggestQueryType.Query, currentMarket, currentCurrency, currentLocale))).FirstOrDefault(); if (to == null) { WriteLine(ErrorColor, "Couldn't find '{0}'", toPlaceName); return; } //Setup flight search settings var flightResponseSettings = new FlightResponseSettings( sortOrder: SortOrder.Ascending, sortType: SortType.Price, maxStops: 2, maxDuration: 14 * 60, outboundDepartureStartTime: new LocalTime(08, 0, 0), outboundDepartureEndTime: new LocalTime(12, 0, 0), inboundDepartureStartTime: new LocalTime(08, 0, 0), inboundDepartureEndTime: new LocalTime(18, 30, 0) ); var now = new LocalDate(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); var outboundDate = now.PlusWeeks(1); var inboundDate = now.PlusWeeks(2); Write("Flights from "); Write(ImportantColor, from.PlaceName); Write(" to "); WriteLine(ImportantColor, to.PlaceName); Write(" on "); Write(ImportantColor, outboundDate.ToString("d", CultureInfo.InvariantCulture)); Write(" and back on "); WriteLine(ImportantColor, inboundDate.ToString("d", CultureInfo.InvariantCulture)); //Query flights var itineraries = await scanner.QueryFlight( new FlightQuerySettings( new FlightRequestSettings(from, to, outboundDate, inboundDate, 1, currency: currentCurrency, marketCountry: currentMarket, locale: currentLocale), flightResponseSettings), WriteToDebug()); itineraries = itineraries .Take(5) .ToList(); if (!itineraries.Any()) { WriteLine("No flights"); return; } foreach (var itinerary in itineraries) { WriteItinerary(itinerary, currentCurrency); } WriteLine("----------------------------------------------"); //Query bookings (note, this is forbidden by SkyScanner, should only query exact booking details if a user requests them) var bookingQueryTasks = itineraries.Select(i => scanner.QueryBooking(i)); var bookingResults = (await Task.WhenAll(bookingQueryTasks)) .OrderBy(response => response.BookingOptions .Select(option => option.BookingItems.Sum(item => item.Price)) .Min()); foreach (var response in bookingResults) { WriteBookingResult(response, currentCurrency); } }