Remove faraday depedency

so that the fetcher may be used as a script without bundling things
This commit is contained in:
Dan Buch 2015-09-06 12:54:45 -04:00
parent 8f56f32d73
commit e7cd0c2979
3 changed files with 10 additions and 8 deletions

View File

@ -2,6 +2,5 @@ source 'https://rubygems.org'
ruby '2.2.2' if ENV.key?('DYNO')
gem 'faraday'
gem 'puma'
gem 'sinatra'

View File

@ -1,9 +1,6 @@
GEM
remote: https://rubygems.org/
specs:
faraday (0.9.1)
multipart-post (>= 1.2, < 3)
multipart-post (2.0.0)
puma (2.13.4)
rack (1.6.4)
rack-protection (1.5.3)
@ -18,7 +15,6 @@ PLATFORMS
ruby
DEPENDENCIES
faraday
puma
sinatra

View File

@ -1,4 +1,5 @@
require 'faraday'
require 'uri'
require 'net/http'
require 'json'
class CPIFetcher
@ -6,16 +7,22 @@ class CPIFetcher
attr_reader :cpi_series_url
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
def cpi
resp = JSON.parse(Faraday.get(cpi_series_url).body)
resp = fetch_raw_response
return nil unless resp['Results']['series']
resp['Results']['series'].first['data'].first['value']
end
private
def fetch_raw_response
JSON.parse(Net::HTTP.get_response(cpi_series_url).body)
end
end
if $PROGRAM_NAME == __FILE__