-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ab6344
commit a335d1d
Showing
8 changed files
with
96 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'aws/s3' | ||
|
||
class Uploader | ||
attr_accessor :bucket_name | ||
|
||
def initialize(bucket_name) | ||
self.bucket_name = bucket_name | ||
|
||
AWS::S3::Base.establish_connection!( | ||
access_key_id: ENV['AMAZON_ACCESS_KEY_ID'], | ||
secret_access_key: ENV['AMAZON_SECRET_ACCESS_KEY'] | ||
) | ||
end | ||
|
||
def upload(file_path) | ||
AWS::S3::S3Object.store( | ||
File.basename(file_path), | ||
open(file_path), | ||
bucket_name, | ||
access: :public_read | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class AWS::S3::S3Object | ||
cattr_accessor :store_call_args | ||
|
||
def self.store(*args) | ||
self.store_call_args = args | ||
end | ||
end | ||
|
||
class AWS::S3::Base | ||
cattr_accessor :establish_connection_call_args | ||
|
||
def self.establish_connection!(*args) | ||
self.establish_connection_call_args = args | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require_relative './spec_setup' | ||
require_relative '../lib/podcast_press' | ||
require_relative './s3_mocks' | ||
|
||
describe PodcastPress do | ||
before do | ||
@file = File.new(FILENAME, 'w') | ||
end | ||
|
||
after do | ||
File.delete(@file.path) | ||
end | ||
|
||
describe "calling #press! with s3 upload" do | ||
before do | ||
ENV['AMAZON_ACCESS_KEY_ID'] = 'abc' | ||
ENV['AMAZON_SECRET_ACCESS_KEY'] = '123' | ||
PodcastPress.press!(@file.path, s3_bucket: 'test_bucket') | ||
end | ||
|
||
it "makes a connection to s3" do | ||
AWS::S3::S3Object.establish_connection_call_args.must_equal([{ | ||
access_key_id: 'abc', | ||
secret_access_key: '123', | ||
}]) | ||
end | ||
|
||
it "uploads a file to S3" do | ||
args = AWS::S3::S3Object.store_call_args | ||
args[0].must_equal 'test_file.mp3' | ||
args[1].must_be_kind_of File | ||
args[2].must_equal 'test_bucket' | ||
args[3].must_equal({ access: :public_read }) | ||
end | ||
end | ||
end | ||
|