diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..14fb6ee --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,4 @@ +inherit_from: .rubocop_todo.yml + +Style/Documentation: + Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..4705069 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,7 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2015-10-04 18:16:18 -0400 using RuboCop version 0.34.2. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. diff --git a/Gemfile b/Gemfile index 40a7839..3b1403c 100644 --- a/Gemfile +++ b/Gemfile @@ -1,8 +1,8 @@ source 'https://rubygems.org' -ruby '2.2.2' if ENV.key?('DYNO') +ruby '2.2.3' if ENV.key?('DYNO') gem 'aws-sdk', '~> 2' -gem 'pry', group: [:development, :test] -gem 'puma' +gem 'pry', group: %i(development test) gem 'rack' +gem 'rubocop', group: %i(development test) diff --git a/Gemfile.lock b/Gemfile.lock index 318ce29..ecc0b5c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,9 @@ GEM remote: https://rubygems.org/ specs: + ast (2.1.0) + astrolabe (1.3.1) + parser (~> 2.2) aws-sdk (2.1.20) aws-sdk-resources (= 2.1.20) aws-sdk-core (2.1.20) @@ -12,12 +15,22 @@ GEM multi_json (~> 1.0) method_source (0.8.2) multi_json (1.11.2) + parser (2.2.2.6) + ast (>= 1.1, < 3.0) + powerpack (0.1.1) pry (0.10.1) coderay (~> 1.1.0) method_source (~> 0.8.1) slop (~> 3.4) - puma (2.13.4) rack (1.6.4) + rainbow (2.0.0) + rubocop (0.34.2) + astrolabe (~> 1.3) + parser (>= 2.2.2.5, < 3.0) + powerpack (~> 0.1) + rainbow (>= 1.99.1, < 3.0) + ruby-progressbar (~> 1.4) + ruby-progressbar (1.7.5) slop (3.6.0) PLATFORMS @@ -26,8 +39,8 @@ PLATFORMS DEPENDENCIES aws-sdk (~> 2) pry - puma rack + rubocop BUNDLED WITH 1.10.6 diff --git a/README.md b/README.md index e307d24..8348a07 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,20 @@ Transforms [this](http://api.bls.gov/publicAPI/v2/timeseries/data/CUUSA210SA0) into [this](http://s3.amazonaws.com/meatballhat/cpi/current.csv) :tada:. + +## usage + +This is intended for use with Google Sheets via: + +``` +=IMPORTDATA("http://s3.amazonaws.com/meatballhat/cpi/current.csv") +``` + +## deployment + +A copy of this thing is deployed to Heroku with a Heroku Scheduler addon +configured to run the following once daily: + +``` bash +bundle exec ruby cpi_fetcher.rb | bundle exec ruby mini_s3put.rb +``` diff --git a/config.ru b/config.ru index c191bf4..62bc808 100644 --- a/config.ru +++ b/config.ru @@ -1 +1 @@ -run lambda { |env| [301, { 'Location' => ENV['CPI_FEED_URL'] }, []] } +run ->(*) { [301, { 'Location' => ENV['CPI_FEED_URL'] }, []] } diff --git a/cpi_fetcher.rb b/cpi_fetcher.rb index c255a5a..d0ad966 100644 --- a/cpi_fetcher.rb +++ b/cpi_fetcher.rb @@ -31,3 +31,64 @@ if $PROGRAM_NAME == __FILE__ puts CPIFetcher.new.cpi exit 0 end + +__END__ +{ + "status": "REQUEST_SUCCEEDED", + "responseTime": 36, + "message": [], + "Results": { + "series": [ + { + "seriesID": "CUUSA210SA0", + "data": [ + { + "year": "2015", + "period": "S01", + "periodName": "1st Half", + "value": "220.381", + "footnotes": [ + {} + ] + }, + { + "year": "2014", + "period": "S02", + "periodName": "2nd Half", + "value": "220.891", + "footnotes": [ + {} + ] + }, + { + "year": "2014", + "period": "S01", + "periodName": "1st Half", + "value": "220.352", + "footnotes": [ + {} + ] + }, + { + "year": "2013", + "period": "S02", + "periodName": "2nd Half", + "value": "217.983", + "footnotes": [ + {} + ] + }, + { + "year": "2013", + "period": "S01", + "periodName": "1st Half", + "value": "216.941", + "footnotes": [ + {} + ] + } + ] + } + ] + } +} diff --git a/mini_s3put.rb b/mini_s3put.rb index c74fb2f..6919fe9 100644 --- a/mini_s3put.rb +++ b/mini_s3put.rb @@ -1,12 +1,17 @@ require 'aws-sdk' -bucket = ENV.fetch('CPI_FEED_AWS_BUCKET') -key = ARGV.first || ENV.fetch('CPI_FEED_AWS_KEY') +def main + bucket = ENV.fetch('CPI_FEED_AWS_BUCKET') + key = ARGV.first || ENV.fetch('CPI_FEED_AWS_KEY') -puts Aws::S3::Resource.new.bucket(bucket).object(key).put( - body: $stdin.read -) + puts Aws::S3::Resource.new.bucket(bucket).object(key).put( + body: $stdin.read + ) -puts Aws::S3::Client.new.put_object_acl( - bucket: bucket, key: key, acl: 'public-read' -) + puts Aws::S3::Client.new.put_object_acl( + bucket: bucket, key: key, acl: 'public-read' + ) + 0 +end + +exit(main) if $PROGRAM_NAME == __FILE__