commit 1c530fe20afe9d700439b4f992fcbeda841c9130 Author: Dan Buch Date: Thu Aug 27 00:39:12 2015 -0400 Hey it's like a CPI CSV proxy! diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..275d17c --- /dev/null +++ b/Gemfile @@ -0,0 +1,7 @@ +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 new file mode 100644 index 0000000..3ca43ff --- /dev/null +++ b/Gemfile.lock @@ -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 diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..9861644 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: bundle exec rackup diff --git a/config.ru b/config.ru new file mode 100644 index 0000000..d29d044 --- /dev/null +++ b/config.ru @@ -0,0 +1,3 @@ +require './cpi_feed' + +run CPIFeed diff --git a/cpi_feed.rb b/cpi_feed.rb new file mode 100644 index 0000000..6040501 --- /dev/null +++ b/cpi_feed.rb @@ -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