Class: AirAsia
Instance Attribute Summary
Attributes inherited from Flight
Instance Method Summary collapse
Methods inherited from Flight
Constructor Details
This class inherits a constructor from Flight
Instance Method Details
#get ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/teecket/air_asia.rb', line 2 def get uri = URI('https://argon.airasia.com/api/7.0/search') http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE req = Net::HTTP::Post.new(uri.path) req.body = "type=classic&origin=#{from}&destination=#{to}&depart=#{date}&return=&passenger-count=1&child-count=0&infant-count=0¤cy=MYR&days=1" res = http.request(req) result = JSON.parse(res.body) if result['session-id'] begin result['depart'][date]['details']['low-fare'].each do |rs| depart_at = DateTime.parse(rs['segments'][0]['departure-datetime']) arrive_at = DateTime.parse(rs['segments'][0]['arrival-datetime']) fare = rs['total']['adult'] flight_number = rs['segments'][0]['flight-number'] origin = rs['segments'][0]['origincode'] destination = rs['segments'][0]['destinationcode'] depart_at = depart_at.strftime('%I:%M %p') arrive_at = arrive_at.strftime('%I:%M %p') fare = sprintf("%.2f", fare) flight_number = flight_number.gsub(/ /, '') fares << { flight_name: 'AirAsia', flight_number: flight_number, origin: origin, destination: destination, depart_at: depart_at, arrive_at: arrive_at, fare: fare } end rescue StandardError end end end |