Remove faraday depedency
so that the fetcher may be used as a script without bundling things
This commit is contained in:
parent
8f56f32d73
commit
e7cd0c2979
1
Gemfile
1
Gemfile
@ -2,6 +2,5 @@ source 'https://rubygems.org'
|
|||||||
|
|
||||||
ruby '2.2.2' if ENV.key?('DYNO')
|
ruby '2.2.2' if ENV.key?('DYNO')
|
||||||
|
|
||||||
gem 'faraday'
|
|
||||||
gem 'puma'
|
gem 'puma'
|
||||||
gem 'sinatra'
|
gem 'sinatra'
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
GEM
|
GEM
|
||||||
remote: https://rubygems.org/
|
remote: https://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
faraday (0.9.1)
|
|
||||||
multipart-post (>= 1.2, < 3)
|
|
||||||
multipart-post (2.0.0)
|
|
||||||
puma (2.13.4)
|
puma (2.13.4)
|
||||||
rack (1.6.4)
|
rack (1.6.4)
|
||||||
rack-protection (1.5.3)
|
rack-protection (1.5.3)
|
||||||
@ -18,7 +15,6 @@ PLATFORMS
|
|||||||
ruby
|
ruby
|
||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
faraday
|
|
||||||
puma
|
puma
|
||||||
sinatra
|
sinatra
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
require 'faraday'
|
require 'uri'
|
||||||
|
require 'net/http'
|
||||||
require 'json'
|
require 'json'
|
||||||
|
|
||||||
class CPIFetcher
|
class CPIFetcher
|
||||||
@ -6,16 +7,22 @@ class CPIFetcher
|
|||||||
attr_reader :cpi_series_url
|
attr_reader :cpi_series_url
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@cpi_series_url = (ENV['CPI_SERIES_URL'] || DEFAULT_CPI_SERIES_URL)
|
@cpi_series_url = URI(ENV['CPI_SERIES_URL'] || DEFAULT_CPI_SERIES_URL)
|
||||||
end
|
end
|
||||||
|
|
||||||
def cpi
|
def cpi
|
||||||
resp = JSON.parse(Faraday.get(cpi_series_url).body)
|
resp = fetch_raw_response
|
||||||
|
|
||||||
return nil unless resp['Results']['series']
|
return nil unless resp['Results']['series']
|
||||||
|
|
||||||
resp['Results']['series'].first['data'].first['value']
|
resp['Results']['series'].first['data'].first['value']
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def fetch_raw_response
|
||||||
|
JSON.parse(Net::HTTP.get_response(cpi_series_url).body)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if $PROGRAM_NAME == __FILE__
|
if $PROGRAM_NAME == __FILE__
|
||||||
|
Loading…
Reference in New Issue
Block a user