module FlightRadar
FlightRadar
module for sending requests to FlightRadar24 API
Constants
- VERSION
Public Instance Methods
airline_logo(iata, icao)
click to toggle source
# File lib/flight_radar.rb, line 33 def airline_logo(iata, icao) first_logo_url = "#{Core::AIRLINE_LOGO_URL}#{iata}_#{icao}.png" second_logo_url = "#{Core::ALTERNATIVE_AIRLINE_LOGO_URL}#{icao}_logo0.png" # check status codes result = [] first_request = Request.new(first_logo_url, Core::IMAGE_HEADERS) second_request = Request.new(second_logo_url, Core::IMAGE_HEADERS) result << first_logo_url if first_request.status_code[0] != 4 result << second_logo_url if second_request.status_code[0] != 4 [first_logo_url, second_logo_url] end
airlines()
click to toggle source
# File lib/flight_radar.rb, line 28 def airlines request = Request.new(Core::AIRLINES_DATA_URL, Core::JSON_HEADERS) request.content["rows"] end
airport(code)
click to toggle source
# File lib/flight_radar.rb, line 46 def airport(code) HTTParty.get("https://data-live.flightradar24.com/airports/traffic-stats/?airport=#{code}").parsed_response end
airports()
click to toggle source
# File lib/flight_radar.rb, line 50 def airports request = Request.new(Core::AIRPORTS_DATA_URL, Core::JSON_HEADERS) request.content["rows"] end
bounds(zone)
click to toggle source
# File lib/flight_radar.rb, line 55 def bounds(zone) "#{zone["tl_y"]},#{zone["br_y"]},#{zone["tl_x"]},#{zone["br_x"]}" end
country_flag(country)
click to toggle source
# File lib/flight_radar.rb, line 59 def country_flag(country) "#{Core::COUNTRY_FLAG_URL}#{country.downcase.gsub(" ", "-")}.gif" end
flight_details(flight_id)
click to toggle source
# File lib/flight_radar.rb, line 63 def flight_details(flight_id) HTTParty.get("https://data-live.flightradar24.com/clickhandler/?flight=#{flight_id}").parsed_response end
flights(params = {})
click to toggle source
# File lib/flight_radar.rb, line 67 def flights(params = {}) request_params = @config request_params[:airline] = params[:airline] if params[:airline] request_params[:bounds] = params[:bounds].gsub(",", "%2C") if params[:bounds] request = Request.new(Core::REAL_TIME_FLIGHT_TRACKER_DATA_URL, Core::JSON_HEADERS, request_params) response = request.content %w[full_count version stats].each { |k| response.delete(k) } flights = [] response.each do |flight_id, flight_details| flights.append(Flight.new(flight_id, flight_details)) end flights end
zones()
click to toggle source
# File lib/flight_radar.rb, line 82 def zones request = Request.new(Core::ZONES_DATA_URL, Core::JSON_HEADERS) request = request.content request.delete("version") request end