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
|
.*env
|
||||||
*.csv
|
*.csv
|
||||||
|
.ruby-version
|
||||||
|
@ -5,3 +5,9 @@ AllCops:
|
|||||||
|
|
||||||
Style/Documentation:
|
Style/Documentation:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
|
Style/AccessModifierDeclarations:
|
||||||
|
EnforcedStyle: inline
|
||||||
|
|
||||||
|
Layout/MultilineMethodCallIndentation:
|
||||||
|
EnforcedStyle: indented
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# This configuration was generated by
|
# This configuration was generated by
|
||||||
# `rubocop --auto-gen-config`
|
# `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
|
# The point is for the user to remove these configuration records
|
||||||
# one by one as the offenses are removed from the code base.
|
# one by one as the offenses are removed from the code base.
|
||||||
# Note that changes in the inspected code, or installation of new
|
# Note that changes in the inspected code, or installation of new
|
||||||
|
@ -12,6 +12,7 @@ class CPIFetcher
|
|||||||
)
|
)
|
||||||
private_constant :DEFAULT_CPI_SERIES_URL
|
private_constant :DEFAULT_CPI_SERIES_URL
|
||||||
attr_reader :url, :bls_token
|
attr_reader :url, :bls_token
|
||||||
|
private :url, :bls_token
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@url = URI(ENV['CPI_SERIES_URL'] || DEFAULT_CPI_SERIES_URL)
|
@url = URI(ENV['CPI_SERIES_URL'] || DEFAULT_CPI_SERIES_URL)
|
||||||
@ -20,28 +21,27 @@ class CPIFetcher
|
|||||||
|
|
||||||
def cpi
|
def cpi
|
||||||
resp = fetch_raw_response
|
resp = fetch_raw_response
|
||||||
|
|
||||||
return nil unless resp['Results']['series']
|
return nil unless resp['Results']['series']
|
||||||
|
|
||||||
data = resp['Results']['series'].first['data']
|
last_cpi_value(resp['Results']['series'].first['data'])
|
||||||
data.sort! { |a, b| a['year'] <=> b['year'] }
|
|
||||||
data.last['value']
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private def last_cpi_value(data)
|
||||||
|
data
|
||||||
def fetch_raw_response
|
.sort { |a, b| a['year'] <=> b['year'] }
|
||||||
http = Net::HTTP.new(url.hostname, url.port)
|
.then { |d| d.last['value'] }
|
||||||
http.use_ssl = true
|
|
||||||
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
|
||||||
res = http.request(build_request)
|
|
||||||
JSON.parse(res.body)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_request
|
private def fetch_raw_response
|
||||||
req = Net::HTTP::Get.new(url)
|
Net::HTTP.new(url.hostname, url.port)
|
||||||
req['Authorization'] = "token #{bls_token}"
|
.tap { |h| h.use_ssl = true }
|
||||||
req
|
.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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -9,14 +9,16 @@ class MiniS3put
|
|||||||
@instream = instream
|
@instream = instream
|
||||||
end
|
end
|
||||||
|
|
||||||
|
attr_reader :bucket, :key, :instream
|
||||||
|
private :bucket, :key, :instream
|
||||||
|
|
||||||
def put
|
def put
|
||||||
Aws::S3::Resource.new.bucket(bucket).object(key).put(
|
Aws::S3::Resource.new.bucket(bucket).object(key).put(
|
||||||
body: instream.read
|
body: instream.read
|
||||||
).on_success(&method(:on_put_success))
|
).on_success(&method(:on_put_success))
|
||||||
0
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_put_success(response)
|
private def on_put_success(response)
|
||||||
puts response.data
|
puts response.data
|
||||||
|
|
||||||
Aws::S3::Client.new.put_object_acl(
|
Aws::S3::Client.new.put_object_acl(
|
||||||
@ -25,10 +27,9 @@ class MiniS3put
|
|||||||
puts acl_response.data
|
puts acl_response.data
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
attr_reader :bucket, :key, :instream
|
|
||||||
end
|
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