Module: FlightRadar
- Defined in:
- lib/flight_radar.rb
Overview
FlightRadar module for sending requests to FlightRadar24 API
Constant Summary collapse
- VERSION =
'0.2.1'
Class Method Summary collapse
-
.airline_logo(iata, icao) ⇒ Array
Retrieves airline logos based on IATA and ICAO codes.
-
.airlines ⇒ Array
Retrieves a list of airlines.
-
.airport(code) ⇒ Hash
Retrieves traffic statistics for a specific airport.
-
.airports ⇒ Array
Retrieves a list of airports.
-
.bounds(zone) ⇒ String
Converts zone information into bounds string.
-
.country_flag(country) ⇒ String
Retrieves the URL of a country flag based on the country name.
-
.flight_details(flight_id) ⇒ Hash
Retrieves detailed information about a specific flight.
-
.flights(params = {}) ⇒ Array
Retrieves a list of flights based on specified parameters.
-
.zones ⇒ Hash
Retrieves information about flight tracking zones.
Class Method Details
.airline_logo(iata, icao) ⇒ Array
Retrieves airline logos based on IATA and ICAO codes.
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/flight_radar.rb', line 43 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 the availability of logos and return URLs. 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.success? result << second_logo_url if second_request.success? result end |
.airlines ⇒ Array
Retrieves a list of airlines.
33 34 35 36 |
# File 'lib/flight_radar.rb', line 33 def airlines request = Request.new(Core::AIRLINES_DATA_URL, Core::JSON_HEADERS) request.content['rows'] end |
.airport(code) ⇒ Hash
Retrieves traffic statistics for a specific airport.
60 61 62 |
# File 'lib/flight_radar.rb', line 60 def airport(code) HTTParty.get("https://data-live.flightradar24.com/airports/traffic-stats/?airport=#{code}").parsed_response end |
.airports ⇒ Array
Retrieves a list of airports.
67 68 69 70 |
# File 'lib/flight_radar.rb', line 67 def airports request = Request.new(Core::AIRPORTS_DATA_URL, Core::JSON_HEADERS) request.content['rows'] end |
.bounds(zone) ⇒ String
Converts zone information into bounds string.
76 77 78 |
# File 'lib/flight_radar.rb', line 76 def bounds(zone) "#{zone['tl_y']},#{zone['br_y']},#{zone['tl_x']},#{zone['br_x']}" end |
.country_flag(country) ⇒ String
Retrieves the URL of a country flag based on the country name.
84 85 86 |
# File 'lib/flight_radar.rb', line 84 def country_flag(country) "#{Core::COUNTRY_FLAG_URL}#{country.downcase.gsub(' ', '-')}.gif" end |
.flight_details(flight_id) ⇒ Hash
Retrieves detailed information about a specific flight.
92 93 94 |
# File 'lib/flight_radar.rb', line 92 def flight_details(flight_id) HTTParty.get("https://data-live.flightradar24.com/clickhandler/?flight=#{flight_id}").parsed_response end |
.flights(params = {}) ⇒ Array
Retrieves a list of flights based on specified parameters.
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/flight_radar.rb', line 100 def flights(params = {}) request_params = @config.dup request_params[:airline] = params[:airline] if params[:airline] request_params[:bounds] = params[:bounds]&.gsub(',', '%2C') response = Request.new(Core::REAL_TIME_FLIGHT_TRACKER_DATA_URL, Core::JSON_HEADERS, request_params).content %w[full_count version stats].each { |k| response.delete(k) } response.map { |flight_id, flight_details| Flight.new(flight_id, flight_details) } end |
.zones ⇒ Hash
Retrieves information about flight tracking zones.
115 116 117 118 119 120 |
# File 'lib/flight_radar.rb', line 115 def zones request = Request.new(Core::ZONES_DATA_URL, Core::JSON_HEADERS) request = request.content request.delete('version') request end |