From e7cd0c2979684d219c2b157d6016506ea99178c7 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Sun, 6 Sep 2015 12:54:45 -0400 Subject: [PATCH] Remove faraday depedency so that the fetcher may be used as a script without bundling things --- Gemfile | 1 - Gemfile.lock | 4 ---- cpi_fetcher.rb | 13 ++++++++++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Gemfile b/Gemfile index 275d17c..6251230 100644 --- a/Gemfile +++ b/Gemfile @@ -2,6 +2,5 @@ source 'https://rubygems.org' ruby '2.2.2' if ENV.key?('DYNO') -gem 'faraday' gem 'puma' gem 'sinatra' diff --git a/Gemfile.lock b/Gemfile.lock index 3ca43ff..f75a438 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/cpi_fetcher.rb b/cpi_fetcher.rb index c32d551..832a2c6 100644 --- a/cpi_fetcher.rb +++ b/cpi_fetcher.rb @@ -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__