Add NPS client class
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -30,3 +30,5 @@
|
|||||||
|
|
||||||
# Ignore master key for decrypting credentials and more.
|
# Ignore master key for decrypting credentials and more.
|
||||||
/config/master.key
|
/config/master.key
|
||||||
|
|
||||||
|
.mise.toml
|
||||||
|
|||||||
2
Gemfile
2
Gemfile
@@ -18,3 +18,5 @@ group :development, :test do
|
|||||||
gem "debug", platforms: %i[ mri windows ], require: "debug/prelude"
|
gem "debug", platforms: %i[ mri windows ], require: "debug/prelude"
|
||||||
gem "rspec-rails", "~> 8.0"
|
gem "rspec-rails", "~> 8.0"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
gem "faraday", "~> 2.14"
|
||||||
|
|||||||
10
Gemfile.lock
10
Gemfile.lock
@@ -87,6 +87,12 @@ GEM
|
|||||||
drb (2.2.3)
|
drb (2.2.3)
|
||||||
erb (5.0.3)
|
erb (5.0.3)
|
||||||
erubi (1.13.1)
|
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)
|
globalid (1.3.0)
|
||||||
activesupport (>= 6.1)
|
activesupport (>= 6.1)
|
||||||
i18n (1.14.7)
|
i18n (1.14.7)
|
||||||
@@ -96,6 +102,7 @@ GEM
|
|||||||
pp (>= 0.6.0)
|
pp (>= 0.6.0)
|
||||||
rdoc (>= 4.0.0)
|
rdoc (>= 4.0.0)
|
||||||
reline (>= 0.4.2)
|
reline (>= 0.4.2)
|
||||||
|
json (2.15.1)
|
||||||
logger (1.7.0)
|
logger (1.7.0)
|
||||||
loofah (2.24.1)
|
loofah (2.24.1)
|
||||||
crass (~> 1.0.2)
|
crass (~> 1.0.2)
|
||||||
@@ -108,6 +115,8 @@ GEM
|
|||||||
marcel (1.1.0)
|
marcel (1.1.0)
|
||||||
mini_mime (1.1.5)
|
mini_mime (1.1.5)
|
||||||
minitest (5.26.0)
|
minitest (5.26.0)
|
||||||
|
net-http (0.6.0)
|
||||||
|
uri
|
||||||
net-imap (0.5.12)
|
net-imap (0.5.12)
|
||||||
date
|
date
|
||||||
net-protocol
|
net-protocol
|
||||||
@@ -242,6 +251,7 @@ PLATFORMS
|
|||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
debug
|
debug
|
||||||
|
faraday (~> 2.14)
|
||||||
puma (>= 5.0)
|
puma (>= 5.0)
|
||||||
rails (~> 8.0.3)
|
rails (~> 8.0.3)
|
||||||
rspec-rails (~> 8.0)
|
rspec-rails (~> 8.0)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
- Ruby 3.4.7
|
- Ruby 3.4.7
|
||||||
- Bundler
|
- Bundler
|
||||||
|
- Set `NPS_API_KEY` env var
|
||||||
|
|
||||||
### Deps
|
### Deps
|
||||||
|
|
||||||
|
|||||||
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