Class: FaaNotams::Service
- Inherits:
-
Object
- Object
- FaaNotams::Service
- Defined in:
- lib/faa_notams/service.rb
Overview
Service to interact with FAA’s Notice to Airmen (NOTAM) API external-api.faa.gov/notamapi
This service provides access to FAA’s NOTAM API, which contains real-time notification of any change in the National Airspace System (NAS).
Constant Summary collapse
- BASE_URL =
"https://external-api.faa.gov/notamapi/v1"
Instance Attribute Summary collapse
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
readonly
Returns the value of attribute client_secret.
Instance Method Summary collapse
-
#initialize(client_id = nil, client_secret = nil) ⇒ Service
constructor
Initialize the service with FAA API credentials.
-
#search(options = {}) ⇒ Hash
Search for NOTAMs based on various criteria.
-
#search_by_airport(airport_code, options = {}) ⇒ Hash
Convenience method to search NOTAMs by airport code (ICAO or domestic).
-
#search_by_feature(feature_type, options = {}) ⇒ Hash
Search for NOTAMs affecting a specific feature type.
-
#search_by_location(latitude, longitude, radius = 50, options = {}) ⇒ Hash
Search NOTAMs by geographic location (latitude/longitude and radius).
Constructor Details
#initialize(client_id = nil, client_secret = nil) ⇒ Service
Initialize the service with FAA API credentials
21 22 23 24 25 26 27 |
# File 'lib/faa_notams/service.rb', line 21 def initialize(client_id = nil, client_secret = nil) @client_id = client_id || ENV['FAA_NOTAM_CLIENT_ID'] @client_secret = client_secret || ENV['FAA_NOTAM_CLIENT_SECRET'] raise ArgumentError, "FAA NOTAM client_id is required" unless @client_id raise ArgumentError, "FAA NOTAM client_secret is required" unless @client_secret end |
Instance Attribute Details
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
16 17 18 |
# File 'lib/faa_notams/service.rb', line 16 def client_id @client_id end |
#client_secret ⇒ Object (readonly)
Returns the value of attribute client_secret.
16 17 18 |
# File 'lib/faa_notams/service.rb', line 16 def client_secret @client_secret end |
Instance Method Details
#search(options = {}) ⇒ Hash
Search for NOTAMs based on various criteria
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/faa_notams/service.rb', line 53 def search( = {}) # Convert snake_case option keys to camelCase for the API params = {} # Handle response format separately (API expects 'responseFormat') if [:response_format] params[:responseFormat] = validate_response_format([:response_format]) end # Map option keys to API parameter names param_mapping = { icao_location: :icaoLocation, domestic_location: :domesticLocation, notam_type: :notamType, classification: :classification, notam_number: :notamNumber, effective_start_date: :effectiveStartDate, effective_end_date: :effectiveEndDate, feature_type: :featureType, location_longitude: :locationLongitude, location_latitude: :locationLatitude, location_radius: :locationRadius, last_updated_date: :lastUpdatedDate, sort_by: :sortBy, sort_order: :sortOrder, page_size: :pageSize, page_num: :pageNum } # Process each key and transform to camelCase for API param_mapping.each do |option_key, param_key| if .key?(option_key) # Special validation for some parameters value = case option_key when :feature_type validate_feature_type([option_key]) when :location_radius validate_range([option_key], 0.1, 100, 'location_radius') when :page_size validate_range([option_key], 1, 1000, 'page_size') when :page_num validate_range([option_key], 1, nil, 'page_num') when :sort_order validate_enum([option_key], %w[Asc Desc], 'sort_order') else [option_key] end params[param_key] = value end end get("/search", params) end |
#search_by_airport(airport_code, options = {}) ⇒ Hash
Convenience method to search NOTAMs by airport code (ICAO or domestic)
112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/faa_notams/service.rb', line 112 def search_by_airport(airport_code, = {}) airport_code = airport_code.to_s.upcase if airport_code.length == 3 [:domestic_location] = airport_code else [:icao_location] = airport_code end search() end |
#search_by_feature(feature_type, options = {}) ⇒ Hash
Search for NOTAMs affecting a specific feature type
142 143 144 145 |
# File 'lib/faa_notams/service.rb', line 142 def search_by_feature(feature_type, = {}) [:feature_type] = validate_feature_type(feature_type) search() end |
#search_by_location(latitude, longitude, radius = 50, options = {}) ⇒ Hash
Search NOTAMs by geographic location (latitude/longitude and radius)
130 131 132 133 134 135 136 |
# File 'lib/faa_notams/service.rb', line 130 def search_by_location(latitude, longitude, radius = 50, = {}) [:location_latitude] = latitude [:location_longitude] = longitude [:location_radius] = radius search() end |