Ruby 2.6 or give me 💀

main
Dan Buch 4 years ago
parent 86127d1d69
commit 061f3f4e05
Signed by: meatballhat
GPG Key ID: 9685130D8B763EA7

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
private def last_cpi_value(data)
data
.sort { |a, b| a['year'] <=> b['year'] }
.then { |d| d.last['value'] }
end
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 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
def build_request
req = Net::HTTP::Get.new(url)
req['Authorization'] = "token #{bls_token}"
req
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…
Cancel
Save