Merge pull request #4 from meatballhat/minimodern
Ruby 2.6 or give me 💀
This commit is contained in:
commit
f7e7b89bfb
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
.*env
|
||||
*.csv
|
||||
.ruby-version
|
||||
|
@ -5,3 +5,9 @@ AllCops:
|
||||
|
||||
Style/Documentation:
|
||||
Enabled: false
|
||||
|
||||
Style/AccessModifierDeclarations:
|
||||
EnforcedStyle: inline
|
||||
|
||||
Layout/MultilineMethodCallIndentation:
|
||||
EnforcedStyle: indented
|
||||
|
@ -1,6 +1,6 @@
|
||||
# This configuration was generated by
|
||||
# `rubocop --auto-gen-config`
|
||||
# on 2019-12-31 10:11:37 -0500 using RuboCop version 0.78.0.
|
||||
# on 2020-01-01 01:01:20 -0500 using RuboCop version 0.78.0.
|
||||
# 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
|
||||
|
@ -12,6 +12,7 @@ class CPIFetcher
|
||||
)
|
||||
private_constant :DEFAULT_CPI_SERIES_URL
|
||||
attr_reader :url, :bls_token
|
||||
private :url, :bls_token
|
||||
|
||||
def initialize
|
||||
@url = URI(ENV['CPI_SERIES_URL'] || DEFAULT_CPI_SERIES_URL)
|
||||
@ -20,28 +21,27 @@ class CPIFetcher
|
||||
|
||||
def cpi
|
||||
resp = fetch_raw_response
|
||||
|
||||
return nil unless resp['Results']['series']
|
||||
|
||||
data = resp['Results']['series'].first['data']
|
||||
data.sort! { |a, b| a['year'] <=> b['year'] }
|
||||
data.last['value']
|
||||
last_cpi_value(resp['Results']['series'].first['data'])
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def fetch_raw_response
|
||||
http = Net::HTTP.new(url.hostname, url.port)
|
||||
http.use_ssl = true
|
||||
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
||||
res = http.request(build_request)
|
||||
JSON.parse(res.body)
|
||||
private def last_cpi_value(data)
|
||||
data
|
||||
.sort { |a, b| a['year'] <=> b['year'] }
|
||||
.then { |d| d.last['value'] }
|
||||
end
|
||||
|
||||
def build_request
|
||||
req = Net::HTTP::Get.new(url)
|
||||
req['Authorization'] = "token #{bls_token}"
|
||||
req
|
||||
private def fetch_raw_response
|
||||
Net::HTTP.new(url.hostname, url.port)
|
||||
.tap { |h| h.use_ssl = true }
|
||||
.tap { |h| h.verify_mode = OpenSSL::SSL::VERIFY_PEER }
|
||||
.then { |h| JSON.parse(h.request(build_request).body) }
|
||||
end
|
||||
|
||||
private def build_request
|
||||
Net::HTTP::Get.new(url)
|
||||
.tap { |r| r['Authorization'] = "token #{bls_token}" }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -9,14 +9,16 @@ class MiniS3put
|
||||
@instream = instream
|
||||
end
|
||||
|
||||
attr_reader :bucket, :key, :instream
|
||||
private :bucket, :key, :instream
|
||||
|
||||
def put
|
||||
Aws::S3::Resource.new.bucket(bucket).object(key).put(
|
||||
body: instream.read
|
||||
).on_success(&method(:on_put_success))
|
||||
0
|
||||
end
|
||||
|
||||
def on_put_success(response)
|
||||
private def on_put_success(response)
|
||||
puts response.data
|
||||
|
||||
Aws::S3::Client.new.put_object_acl(
|
||||
@ -25,10 +27,9 @@ class MiniS3put
|
||||
puts acl_response.data
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
attr_reader :bucket, :key, :instream
|
||||
end
|
||||
|
||||
exit(MiniS3put.new(key: ARGV.first).put) if $PROGRAM_NAME == __FILE__
|
||||
if $PROGRAM_NAME == __FILE__
|
||||
MiniS3put.new(key: ARGV.first).put
|
||||
exit 0
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user