26 lines
488 B
Ruby
26 lines
488 B
Ruby
class NpsClient
|
|
def self.current
|
|
@current ||= new
|
|
end
|
|
|
|
def parks(offset: 0)
|
|
conn.get('parks', { start: offset })
|
|
end
|
|
|
|
def alerts(state:, offset: 0)
|
|
conn.get('alerts', { stateCode: state, start: offset })
|
|
end
|
|
|
|
private
|
|
|
|
def conn
|
|
@conn ||= Faraday.new(
|
|
url: 'https://developer.nps.gov/api/v1',
|
|
headers: { 'X-Api-Key': ENV.fetch('NPS_API_KEY') }
|
|
) do |builder|
|
|
builder.response :json
|
|
builder.response :raise_error
|
|
end
|
|
end
|
|
end
|