From 5e95ecd3f569d1e4df31a836315020bf7d795c0a Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Tue, 30 Aug 2016 11:28:59 -0400 Subject: [PATCH] Another li'l round of touchups --- .rubocop_todo.yml | 11 +---------- .travis.yml | 2 ++ LICENSE | 2 +- mini_s3put.rb | 27 ++++++++++++++++++--------- 4 files changed, 22 insertions(+), 20 deletions(-) create mode 100644 .travis.yml diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ab099c4..0fdd562 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,16 +1,7 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2016-08-30 10:56:44 -0400 using RuboCop version 0.42.0. +# on 2016-08-30 11:24:51 -0400 using RuboCop version 0.42.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 # versions of RuboCop, may require this file to be generated again. - -# Offense count: 1 -Metrics/AbcSize: - Max: 17 - -# Offense count: 1 -# Configuration parameters: CountComments. -Metrics/MethodLength: - Max: 14 diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..488b772 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,2 @@ +language: ruby +script: bundle exec rubocop diff --git a/LICENSE b/LICENSE index f6ad8ff..ccd02ea 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015 Dan Buch +Copyright © 2016 Dan Buch Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/mini_s3put.rb b/mini_s3put.rb index 3c7a189..288113d 100644 --- a/mini_s3put.rb +++ b/mini_s3put.rb @@ -1,12 +1,19 @@ require 'aws-sdk' -def main - bucket = ENV.fetch('CPI_FEED_AWS_BUCKET') - key = ARGV.first || ENV.fetch('CPI_FEED_AWS_KEY') +class MiniS3put + def initialize(key: nil, instream: $stdin) + @bucket = ENV.fetch('CPI_FEED_AWS_BUCKET') + @key = key || ENV.fetch('CPI_FEED_AWS_KEY') + @instream = instream + end + + def put + Aws::S3::Resource.new.bucket(bucket).object(key).put( + body: instream.read + ).on_success(&method(:on_put_success)) + end - Aws::S3::Resource.new.bucket(bucket).object(key).put( - body: $stdin.read - ).on_success do |response| + def on_put_success(response) puts response.data Aws::S3::Client.new.put_object_acl( @@ -15,10 +22,12 @@ def main puts acl_response.data end - return 0 + 0 end - 1 + private + + attr_reader :bucket, :key, :instream end -exit(main) if $PROGRAM_NAME == __FILE__ +exit(MiniS3put.new(ARGV.first).put) if $PROGRAM_NAME == __FILE__