Class: Suitcase::Flight
- Inherits:
-
Object
- Object
- Suitcase::Flight
- Defined in:
- lib/suitcase/air/air.rb
Instance Attribute Summary collapse
-
#adults ⇒ Object
Returns the value of attribute adults.
-
#airline ⇒ Object
Returns the value of attribute airline.
-
#airline_code ⇒ Object
Returns the value of attribute airline_code.
-
#arrival ⇒ Object
Returns the value of attribute arrival.
-
#children ⇒ Object
Returns the value of attribute children.
-
#currency ⇒ Object
Returns the value of attribute currency.
-
#departure ⇒ Object
Returns the value of attribute departure.
-
#destination ⇒ Object
Returns the value of attribute destination.
-
#direct ⇒ Object
Returns the value of attribute direct.
-
#fare ⇒ Object
Returns the value of attribute fare.
-
#flights ⇒ Object
Returns the value of attribute flights.
-
#key ⇒ Object
Returns the value of attribute key.
-
#origin ⇒ Object
Returns the value of attribute origin.
-
#outgoing ⇒ Object
Returns the value of attribute outgoing.
-
#price ⇒ Object
Returns the value of attribute price.
-
#results ⇒ Object
Returns the value of attribute results.
-
#round_trip ⇒ Object
Returns the value of attribute round_trip.
-
#search_window ⇒ Object
Returns the value of attribute search_window.
-
#segments ⇒ Object
Returns the value of attribute segments.
-
#seniors ⇒ Object
Returns the value of attribute seniors.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#adults ⇒ Object
Returns the value of attribute adults.
8 9 10 |
# File 'lib/suitcase/air/air.rb', line 8 def adults @adults end |
#airline ⇒ Object
Returns the value of attribute airline.
8 9 10 |
# File 'lib/suitcase/air/air.rb', line 8 def airline @airline end |
#airline_code ⇒ Object
Returns the value of attribute airline_code.
8 9 10 |
# File 'lib/suitcase/air/air.rb', line 8 def airline_code @airline_code end |
#arrival ⇒ Object
Returns the value of attribute arrival.
8 9 10 |
# File 'lib/suitcase/air/air.rb', line 8 def arrival @arrival end |
#children ⇒ Object
Returns the value of attribute children.
8 9 10 |
# File 'lib/suitcase/air/air.rb', line 8 def children @children end |
#currency ⇒ Object
Returns the value of attribute currency.
8 9 10 |
# File 'lib/suitcase/air/air.rb', line 8 def currency @currency end |
#departure ⇒ Object
Returns the value of attribute departure.
8 9 10 |
# File 'lib/suitcase/air/air.rb', line 8 def departure @departure end |
#destination ⇒ Object
Returns the value of attribute destination.
8 9 10 |
# File 'lib/suitcase/air/air.rb', line 8 def destination @destination end |
#direct ⇒ Object
Returns the value of attribute direct.
8 9 10 |
# File 'lib/suitcase/air/air.rb', line 8 def direct @direct end |
#fare ⇒ Object
Returns the value of attribute fare.
8 9 10 |
# File 'lib/suitcase/air/air.rb', line 8 def fare @fare end |
#flights ⇒ Object
Returns the value of attribute flights.
8 9 10 |
# File 'lib/suitcase/air/air.rb', line 8 def flights @flights end |
#key ⇒ Object
Returns the value of attribute key.
8 9 10 |
# File 'lib/suitcase/air/air.rb', line 8 def key @key end |
#origin ⇒ Object
Returns the value of attribute origin.
8 9 10 |
# File 'lib/suitcase/air/air.rb', line 8 def origin @origin end |
#outgoing ⇒ Object
Returns the value of attribute outgoing.
8 9 10 |
# File 'lib/suitcase/air/air.rb', line 8 def outgoing @outgoing end |
#price ⇒ Object
Returns the value of attribute price.
8 9 10 |
# File 'lib/suitcase/air/air.rb', line 8 def price @price end |
#results ⇒ Object
Returns the value of attribute results.
8 9 10 |
# File 'lib/suitcase/air/air.rb', line 8 def results @results end |
#round_trip ⇒ Object
Returns the value of attribute round_trip.
8 9 10 |
# File 'lib/suitcase/air/air.rb', line 8 def round_trip @round_trip end |
#search_window ⇒ Object
Returns the value of attribute search_window.
8 9 10 |
# File 'lib/suitcase/air/air.rb', line 8 def search_window @search_window end |
#segments ⇒ Object
Returns the value of attribute segments.
8 9 10 |
# File 'lib/suitcase/air/air.rb', line 8 def segments @segments end |
#seniors ⇒ Object
Returns the value of attribute seniors.
8 9 10 |
# File 'lib/suitcase/air/air.rb', line 8 def seniors @seniors end |
Class Method Details
.available(data) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/suitcase/air/air.rb', line 25 def self.available(data) origin_city = data[:from] destination_city = data[:to] departure_date_time = data[:departs] arrival_date_time = data[:arrives] adult_passengers = data[:adults] ? data[:adults] : 0 child_passengers = data[:children] ? data[:children].inject("") { |result, element| result + "C" + (element < 10 ? "0" : "") + element.to_s + (data[:children].last == element ? "" : ",") } : "" # :children => [2, 9, 11] (ages of children) should yield "C02,C09,C11" senior_passengers = data[:seniors] ? data[:seniors] : 0 fare_class = data[:fare] ? data[:fare] : "Y" # F: first class; Y: coach; B: business direct_flight = data[:direct_only] ? data[:direct_only] : false round_trip = data[:round_trip] ? data[:round_trip] : "O" currency = data[:currency] ? data[:currency] : "USD" search_window = data[:search_window] ? data[:search_window] : 2 number_of_results = data[:results] ? data[:results] : 50 xml_format = <<EOS <AirSessionRequest method="getAirAvailability"> <AirAvailabilityQuery> <originCityCode>#{origin_city}</originCityCode> <destinationCityCode>#{destination_city}</destinationCityCode> <departureDateTime>#{departure_date_time}</departureDateTime> <returnDateTime>#{arrival_date_time}</returnDateTime> <fareClass>#{fare_class}</fareClass> <tripType>#{round_trip}</tripType> <Passengers> <adultPassengers>#{adult_passengers}</adultPassengers> <seniorPassengers>#{senior_passengers}</seniorPassengers> <childCodes>#{child_passengers}</childCodes> </Passengers> </AirAvailabilityQuery> </AirSessionRequest> EOS uri = URI.escape("http://api.ean.com/ean-services/rs/air/200919/xmlinterface.jsp?cid=#{CID}&resType=air&intfc=ws&apiKey=#{API_KEY}&xml=#{xml_format}") xml = Nokogiri::XML(open(uri)) segments = [] xml.xpath('//Segment').each do |segment| f = Flight.new f.key = segment.xpath("@key") f.origin = segment.xpath("//originCity") + segment.xpath("//originStateProvince") + segment.xpath("//originCountry") f.destination = segment.xpath("//destinationCity") f.airline = segment.xpath("//airline") f.airline_code = segment.xpath("//airlineCode") f.departure = segment.xpath("//departureDateTime") f.arrival = segment.xpath("//arrivalDateTime") segments.push(f) end flights = [] xml.xpath("//AirAvailabilityReply").each do |aar| f = Flight.new f.segments = [] f.price = aar.xpath("//nativeTotalPrice") f.currency = aar.xpath("//displayCurrencyCode") aar.xpath("//FlightSegment").each do |subseg| fn = segments.find { |x| x.key == subseg.xpath("//segmentKey") } f.segments.push(fn) f.segments.compact! end flights.push(f) end flights end |
Instance Method Details
#to_s ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/suitcase/air/air.rb', line 10 def to_s puts <<EOS ---------- FLIGHT: airline: #{airline} (#{airline_code}) origin: #{origin} destination: #{destination} departure: #{departure} arrival: #{arrival} price: #{price} (#{currency}) key: #{key} ---------- EOS end |