public void GetPriceModel(string jsonResponse, MonthScheduleModel monthSchedule) { dynamic json = JsonConvert.DeserializeObject(jsonResponse); if (json.outbound.minFare != null) { monthSchedule.LowestFare = json.outbound.minFare.price.value; } foreach (var fare in json.outbound.fares) { if (fare.unavailable == false) { if (fare.price != null) { monthSchedule.Flights.Find(f => f.Date == fare.day.ToObject <DateTime>()).Price = new PriceModel() { Value = fare.price.value, ValueMainUnit = fare.price.valueMainUnit, ValueFractionalUnit = fare.price.valueFractionalUnit, CurrencyCode = fare.price.currecyCode, CurrencySymbol = fare.price.currencySymbol }; } monthSchedule.Flights.Find(f => f.Date == fare.day.ToObject <DateTime>()).SoldOut = fare.soldOut; } } }
//Returns list of flights scheduled for given route, year, month public MonthScheduleModel getScheduleMonth(string depIata, string arrivIata, string year, string month) { var client = new RestClient(String.Format("https://services-api.ryanair.com/timtbl/3/schedules/{0}/{1}/years/{2}/months/{3}", depIata, arrivIata, year, month)); IRestResponse response = client.Execute(request); MonthScheduleModel monthSchedule = converter.GetMonthScheduleModel(response.Content, year); return(monthSchedule); }
//Returns sorted list (ascending) of one way fares for given filter parameters per day. public string getCheapestPerDay(string depIata, string arrivIata, MonthScheduleModel monthSchedule, DateTime?depDate1) { var client = new RestClient(String.Format("https://services-api.ryanair.com/farfnd/3/oneWayFares/{0}/{1}/cheapestPerDay", depIata, arrivIata)); //request.AddParameter("outboundWeekOfDate", depDate1.ToString("yyyy-MM-dd")); request.AddParameter("outboundMonthOfDate", depDate1?.ToString("yyyy-MM-dd")); IRestResponse response = client.Execute(request); var res = response.Content; return(res); }
public IActionResult GetDirectRoutes(string fromAirport, string toAirport, DateTime?fromDate, DateTime?toDate) { var route = _ryanairRepository.getDirectRoutes(fromAirport, toAirport); //List<DateTime> globalSchedule = _ryanairService.getScheduleAvailability(fromAirport, toAirport); //get schedule days/departure time for month MonthScheduleModel monthSchedule = _ryanairService.getScheduleMonth(fromAirport, toAirport, fromDate?.Year.ToString(), fromDate?.Month.ToString()); //MonthScheduleModel schedule = new MonthScheduleModel(); monthSchedule.AirportFrom = route.AirportFrom; monthSchedule.AirportFromName = route.AirportFromName; monthSchedule.AirportTo = route.AirportTo; monthSchedule.AirportToName = route.AirportToName; // get fares for given route for month var pricesJson = _ryanairService.getCheapestPerDay(fromAirport, toAirport, monthSchedule, fromDate); _converter.GetPriceModel(pricesJson, monthSchedule); return(Ok(monthSchedule)); }
public MonthScheduleModel GetMonthScheduleModel(string jsonResponse, string year) { dynamic json = JsonConvert.DeserializeObject(jsonResponse); MonthScheduleModel monthSchedule; try { monthSchedule = new MonthScheduleModel { Month = json.month, Flights = new List <Flight>() }; foreach (var day in json.days) { foreach (var flight in day.flights) { monthSchedule.Flights.Add(new Flight() { Date = new DateTime(Convert.ToInt32(year), monthSchedule.Month, day.day.ToObject <int>()), CarrierCode = flight.carrierCode, Number = flight.number, DepartureTime = flight.departureTime, ArrivalTime = flight.arrivalTime }); } } } catch (Exception ex) { return(new MonthScheduleModel()); } return(monthSchedule); }