Module: FlightRadar

Defined in:
lib/flight_radar.rb,
lib/flight_radar/version.rb

Overview

FlightRadar module for sending requests to FlightRadar24 API

Constant Summary collapse

VERSION =
'0.3.0'

Class Method Summary collapse

Class Method Details

.aircraft(registration) ⇒ Hash

Retrieves information about a specific aircraft by registration number.

Parameters:

  • registration (String)

    The aircraft registration number (e.g., "N12345").

Returns:

  • (Hash)

    A hash containing search results for the aircraft.



154
155
156
# File 'lib/flight_radar.rb', line 154

def aircraft(registration)
  search(registration)
end

.airline_fleet(airline_code) ⇒ Hash

Retrieves fleet information for a specific airline.

Parameters:

  • airline_code (String)

    The airline code (IATA or ICAO).

Returns:

  • (Hash)

    A hash containing information about the airline's fleet.



162
163
164
# File 'lib/flight_radar.rb', line 162

def airline_fleet(airline_code)
  search(airline_code)
end

.airline_logo(iata, icao) ⇒ Array

Retrieves airline logos based on IATA and ICAO codes.

Parameters:

  • iata (String)

    The IATA code of the airline.

  • icao (String)

    The ICAO code of the airline.

Returns:

  • (Array)

    An array containing URLs of airline logos.



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/flight_radar.rb', line 42

def (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

.airlinesArray

Retrieves a list of airlines.

Returns:

  • (Array)

    An array containing information about airlines.



32
33
34
35
# File 'lib/flight_radar.rb', line 32

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.

Parameters:

  • code (String)

    The code of the airport.

Returns:

  • (Hash)

    A hash containing traffic statistics for the specified airport.



59
60
61
62
63
# File 'lib/flight_radar.rb', line 59

def airport(code)
  url = "#{Core::DATA_LIVE_BASE_URL}/airports/traffic-stats/?airport=#{code}"
  request = Request.new(url, Core::JSON_HEADERS)
  request.content
end

.airportsArray

Retrieves a list of airports.

Returns:

  • (Array)

    An array containing information about airports.



68
69
70
71
# File 'lib/flight_radar.rb', line 68

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.

Parameters:

  • zone (Hash)

    A hash containing zone information.

Returns:

  • (String)

    A string containing bounds information.



77
78
79
# File 'lib/flight_radar.rb', line 77

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.

Parameters:

  • country (String)

    The name of the country.

Returns:

  • (String)

    The URL of the country flag.



85
86
87
# File 'lib/flight_radar.rb', line 85

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.

Parameters:

  • flight_id (String)

    The ID of the flight.

Returns:

  • (Hash)

    A hash containing detailed information about the specified flight.



93
94
95
# File 'lib/flight_radar.rb', line 93

def flight_details(flight_id)
  HTTParty.get("https://data-live.flightradar24.com/clickhandler/?flight=#{flight_id}").parsed_response
end

.flight_playback(flight_id) ⇒ Hash

Retrieves playback data for a specific flight (alias for flight_details with version parameter).

Parameters:

  • flight_id (String)

    The ID of the flight.

Returns:

  • (Hash)

    A hash containing detailed playback information including flight path.



146
147
148
# File 'lib/flight_radar.rb', line 146

def flight_playback(flight_id)
  flight_details(flight_id)
end

.flights(params = {}) ⇒ Array

Retrieves a list of flights based on specified parameters.

Parameters:

  • params (Hash) (defaults to: {})

    (optional) Parameters for filtering flights.

Returns:

  • (Array)

    An array containing Flight objects.



101
102
103
104
105
106
107
108
109
110
111
# File 'lib/flight_radar.rb', line 101

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

.most_trackedHash

Retrieves a list of the most tracked flights.

Returns:

  • (Hash)

    A hash containing information about the most tracked flights.



137
138
139
140
# File 'lib/flight_radar.rb', line 137

def most_tracked
  request = Request.new(Core::MOST_TRACKED_URL, Core::JSON_HEADERS)
  request.content
end

.search(query, limit = 50) ⇒ Hash

Searches for flights, airports, and airlines.

Parameters:

  • query (String)

    The search query (e.g., flight number, airport code, airline name).

  • limit (Integer) (defaults to: 50)

    (optional) Maximum number of results to return (default: 50).

Returns:

  • (Hash)

    A hash containing search results grouped by type.



128
129
130
131
132
# File 'lib/flight_radar.rb', line 128

def search(query, limit = 50)
  url = "#{Core::SEARCH_DATA_URL}?query=#{query}&limit=#{limit}"
  request = Request.new(url, Core::JSON_HEADERS)
  request.content
end

.zonesHash

Retrieves information about flight tracking zones.

Returns:

  • (Hash)

    A hash containing information about flight tracking zones.



116
117
118
119
120
121
# File 'lib/flight_radar.rb', line 116

def zones
  request = Request.new(Core::ZONES_DATA_URL, Core::JSON_HEADERS)
  content = request.content
  content.delete('version')
  content
end