Class: Firefly
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
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 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 |
# File 'lib/teecket/firefly.rb', line 4 def get uri = URI('https://m.fireflyz.com.my/') 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) res = http.request(req) = res['Set-Cookie'] uri = URI('https://m.fireflyz.com.my/Search') 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 = { 'Cookie' => }) = res['Set-Cookie'] uri = URI('https://m.fireflyz.com.my/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, initheader = { 'Cookie' => }) req.body = "type=2&departure_station=#{from}&arrival_station=#{to}&departure_date=#{date}&return_date=30%2F06%2F2015&adult=1&infant=0" res = http.request(req) if res['location'] uri = URI(res['location']) 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 = { 'Cookie' => }) res = http.request(req) doc = Nokogiri::HTML(res.body) doc.css('div.market1').each_with_index do |elem, i| depart_at = doc.css('div.market1')[i].css('div.visible-xs').css('table')[1].css('td')[0].text.strip arrive_at = doc.css('div.market1')[i].css('div.visible-xs').css('table')[1].css('td')[1].text.strip fare = doc.css('div.market1')[i].css('div.visible-xs > div').text.strip flight_number = doc.css('div.market1')[i].css('div.visible-xs').css('table')[0].text.strip origin = doc.css('div.market1')[i]['onclick'].scan(/~[A-Z]{3}~/)[0].gsub('~', '') destination = doc.css('div.market1')[i]['onclick'].scan(/~[A-Z]{3}~/)[1].gsub('~', '') depart_at = DateTime.parse("#{date} #{depart_at.gsub(/\t/, '').match(/^(.*?)(AM|PM)/).to_s}").strftime('%I:%M %p') arrive_at = DateTime.parse("#{date} #{arrive_at.gsub(/\t/, '').match(/^(.*?)(AM|PM)/).to_s}").strftime('%I:%M %p') fare = fare.gsub(/ MYR/, '') flight_number = flight_number.gsub(/ /, '').gsub(/FLIGHTNO\./, '') fares << { flight_name: 'Firefly', flight_number: flight_number, origin: origin, destination: destination, depart_at: depart_at, arrive_at: arrive_at, fare: fare } end end end |