You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
521 B
25 lines
521 B
require 'faraday'
|
|
require 'json'
|
|
|
|
class CPIFetcher
|
|
DEFAULT_CPI_SERIES_URL = 'http://api.bls.gov/publicAPI/v2/timeseries/data/CUUSA210SA0'
|
|
attr_reader :cpi_series_url
|
|
|
|
def initialize
|
|
@cpi_series_url = (ENV['CPI_SERIES_URL'] || DEFAULT_CPI_SERIES_URL)
|
|
end
|
|
|
|
def cpi
|
|
resp = JSON.parse(Faraday.get(cpi_series_url).body)
|
|
|
|
return nil unless resp['Results']['series']
|
|
|
|
resp['Results']['series'].first['data'].first['value']
|
|
end
|
|
end
|
|
|
|
if $PROGRAM_NAME == __FILE__
|
|
puts CPIFetcher.new.cpi
|
|
exit 0
|
|
end
|