예제 #1
0
        public OneWayFareModel GetFareModel(string jsonResponse)
        {
            dynamic json = JsonConvert.DeserializeObject(jsonResponse);

            OneWayFareModel fareModel;

            try
            {
                fareModel = new OneWayFareModel
                {
                    DepartureDate = json.fares[0].outbound.departureDate,
                    ArrivalDate   = json.fares[0].outbound.arrivalDate,
                    Price         = new PriceModel
                    {
                        Value               = json.fares[0].outbound.price.value,
                        ValueMainUnit       = json.fares[0].outbound.price.valueMainUnit,
                        ValueFractionalUnit = json.fares[0].outbound.price.valueFractionalUnit,
                        CurrencyCode        = json.fares[0].outbound.price.currencyCode,
                        CurrencySymbol      = json.fares[0].outbound.price.currencySymbol
                    }
                };
            } catch (Exception ex)
            {
                return(new OneWayFareModel());
            }

            return(fareModel);
        }
        //Returns sorted list (ascending) of one way fares for given filter parameters
        public OneWayFareModel getCheapest(string depIata, string arrivIata, DateTime?depDate1, DateTime?depDate2)
        {
            var client = new RestClient(String.Format("https://services-api.ryanair.com/farfnd/3/oneWayFares", depIata, arrivIata));

            request.AddParameter("departureAirportIataCode", depIata);
            request.AddParameter("arrivalAirportIataCode", arrivIata);
            request.AddParameter("outboundDepartureDateFrom", depDate1?.ToString("yyyy-MM-dd"));
            request.AddParameter("outboundDepartureDateTo", depDate2?.ToString("yyyy-MM-dd"));

            IRestResponse response = client.Execute(request);

            OneWayFareModel fareModel = converter.GetFareModel(response.Content);

            return(fareModel);
        }