Hey it's like a CPI CSV proxy!

This commit is contained in:
Dan Buch 2015-08-27 00:39:12 -04:00
commit 1c530fe20a
5 changed files with 57 additions and 0 deletions

7
Gemfile Normal file
View File

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

26
Gemfile.lock Normal file
View File

@ -0,0 +1,26 @@
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)
rack
sinatra (1.4.6)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (>= 1.3, < 3)
tilt (2.0.1)
PLATFORMS
ruby
DEPENDENCIES
faraday
puma
sinatra
BUNDLED WITH
1.10.6

1
Procfile Normal file
View File

@ -0,0 +1 @@
web: bundle exec rackup

3
config.ru Normal file
View File

@ -0,0 +1,3 @@
require './cpi_feed'
run CPIFeed

20
cpi_feed.rb Normal file
View File

@ -0,0 +1,20 @@
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)
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