Add NPS client class
This commit is contained in:
21
app/lib/nps_client.rb
Normal file
21
app/lib/nps_client.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
class NpsClient
|
||||
def self.current
|
||||
@current ||= new
|
||||
end
|
||||
|
||||
def parks(offset: 0)
|
||||
conn.get('parks', { 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
|
||||
Reference in New Issue
Block a user