Class: Gull::Client
- Inherits:
-
Object
- Object
- Gull::Client
- Defined in:
- lib/gull/client.rb
Overview
Low-level HTTP client for the NWS alerts API. Handles fetching, parsing, and error wrapping. Most callers should use Alert.fetch instead.
Constant Summary collapse
- URL =
'https://api.weather.gov/alerts/active'- USER_AGENT =
"gull/#{VERSION} (Ruby #{RUBY_VERSION})".freeze
Instance Attribute Summary collapse
-
#errors ⇒ Object
Features that could not be parsed are collected here.
Instance Method Summary collapse
-
#fetch ⇒ Object
Fetches active alerts and returns an Array of Alert objects.
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
14 15 16 |
# File 'lib/gull/client.rb', line 14 def initialize( = {}) @options = end |
Instance Attribute Details
#errors ⇒ Object
Features that could not be parsed are collected here.
12 13 14 |
# File 'lib/gull/client.rb', line 12 def errors @errors end |
Instance Method Details
#fetch ⇒ Object
Fetches active alerts and returns an Array of Alert objects.
19 20 21 22 23 24 25 26 |
# File 'lib/gull/client.rb', line 19 def fetch self.errors = [] json = response data = JSON.parse(json) process(data['features'] || []) rescue JSON::ParserError raise HttpError, 'Unexpected response from NWS API' end |