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.
22 lines
510 B
22 lines
510 B
require 'sinatra/base'
|
|
require 'faraday'
|
|
require 'json'
|
|
|
|
class CPIFeed < Sinatra::Base
|
|
DEFAULT_CPI_SERIES_URL = 'http://api.bls.gov/publicAPI/v2/timeseries/data/CUUSA210SA0'
|
|
|
|
get '/' do
|
|
resp = JSON.parse(Faraday.get(cpi_series_url).body)
|
|
|
|
expires 300, :public, :must_revalidate
|
|
content_type :csv
|
|
"cpi\n#{resp['Results']['series'].first['data'].first['value']}\n"
|
|
end
|
|
|
|
def cpi_series_url
|
|
ENV['CPI_SERIES_URL'] || DEFAULT_CPI_SERIES_URL
|
|
end
|
|
|
|
run! if app_file == $PROGRAM_FILE
|
|
end
|