Class: MalaysiaAirlines
- Defined in:
- lib/teecket/malaysia_airlines.rb
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/malaysia_airlines.rb', line 2 def get new_date = DateTime.parse(date) new_date = new_date.strftime('%Y-%m-%d') uri = URI("https://flymh.mobi/TravelAPI/travelapi/shop/1/mh/#{from}/#{to}/1/0/0/Economy/#{new_date}/") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE req = Net::HTTP::Get.new(uri.path, initHeader = { 'X-apiKey' => '52e6d6d613d3a3e825ac02253fe6b5a4'}) res = http.request(req) res.body.gsub!(/^fn\(/, '') res.body.gsub!(/\)/, '') result = JSON.parse(res.body) if result['success'] result['outboundOptions'].each do |rs| depart_at = DateTime.parse(rs['flights'][0]['depScheduled']) arrive_at = DateTime.parse(rs['flights'][0]['arrScheduled']) fare = rs['fareDetails']['totalTripFare'] flight_number = rs['flights'][0]['marketingAirline'] + rs['flights'][0]['flightNumber'] origin = rs['flights'][0]['departureAirport']['code'] destination = rs['flights'][0]['arrivalAirport']['code'] depart_at = depart_at.strftime('%I:%M %p') arrive_at = arrive_at.strftime('%I:%M %p') fare = sprintf("%.2f", fare) fares << { flight_name: 'Malaysia Airlines', flight_number: flight_number, origin: origin, destination: destination, depart_at: depart_at, arrive_at: arrive_at, fare: fare } end end end |