Add NPS client class

This commit is contained in:
2025-10-08 01:44:23 -07:00
parent d43483a7ad
commit c0c3a1beb5
5 changed files with 36 additions and 0 deletions

2
.gitignore vendored
View File

@@ -30,3 +30,5 @@
# Ignore master key for decrypting credentials and more.
/config/master.key
.mise.toml

View File

@@ -18,3 +18,5 @@ group :development, :test do
gem "debug", platforms: %i[ mri windows ], require: "debug/prelude"
gem "rspec-rails", "~> 8.0"
end
gem "faraday", "~> 2.14"

View File

@@ -87,6 +87,12 @@ GEM
drb (2.2.3)
erb (5.0.3)
erubi (1.13.1)
faraday (2.14.0)
faraday-net_http (>= 2.0, < 3.5)
json
logger
faraday-net_http (3.4.1)
net-http (>= 0.5.0)
globalid (1.3.0)
activesupport (>= 6.1)
i18n (1.14.7)
@@ -96,6 +102,7 @@ GEM
pp (>= 0.6.0)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
json (2.15.1)
logger (1.7.0)
loofah (2.24.1)
crass (~> 1.0.2)
@@ -108,6 +115,8 @@ GEM
marcel (1.1.0)
mini_mime (1.1.5)
minitest (5.26.0)
net-http (0.6.0)
uri
net-imap (0.5.12)
date
net-protocol
@@ -242,6 +251,7 @@ PLATFORMS
DEPENDENCIES
debug
faraday (~> 2.14)
puma (>= 5.0)
rails (~> 8.0.3)
rspec-rails (~> 8.0)

View File

@@ -4,6 +4,7 @@
- Ruby 3.4.7
- Bundler
- Set `NPS_API_KEY` env var
### Deps

21
app/lib/nps_client.rb Normal file
View 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