Class: Gull::Client

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



14
15
16
# File 'lib/gull/client.rb', line 14

def initialize(options = {})
  @options = options
end

Instance Attribute Details

#errorsObject

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

#fetchObject

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