Skip to content

Commit

Permalink
Output the S3 url if there is one.
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchlloyd committed Feb 10, 2013
1 parent b248c0d commit b7ae42a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
4 changes: 3 additions & 1 deletion bin/ppress
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ command :press do |c|
episode_title = ask 'Episode Title: '
say "Shipping episode #{episode_number}, #{episode_title}..."

PodcastPress.press!(args[0], {
episode = PodcastPress.press!(args[0], {
episode_number: episode_number,
title: episode_title
})

say "Your episode URL is:\n #{episode.url}\n" if episode.url
end
end
4 changes: 2 additions & 2 deletions lib/podcast_press/audio_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

module PodcastPress
class AudioFile
attr_reader :filename
attr_accessor :filename, :url
extend Forwardable

def_delegators :@params, :title, :podcast_title, :date
Expand Down Expand Up @@ -42,7 +42,7 @@ def rename!(new_filename)

def upload!(s3_bucket)
return unless s3_bucket
Uploader.new(s3_bucket).upload(@filename)
self.url = Uploader.new(s3_bucket).upload(@filename)
end

def episode_number
Expand Down
8 changes: 7 additions & 1 deletion lib/podcast_press/uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ def initialize(bucket_name)
end

def upload(file_path)
file_name = File.basename(file_path)
AWS::S3::S3Object.store(
File.basename(file_path),
file_name,
open(file_path),
bucket_name,
access: :public_read
)
url(file_name)
end

def url(file_name)
"https://s3.amazonaws.com/#{bucket_name}/#{file_name}"
end
end
8 changes: 7 additions & 1 deletion specs/uploading_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
before do
ENV['AMAZON_ACCESS_KEY_ID'] = 'abc'
ENV['AMAZON_SECRET_ACCESS_KEY'] = '123'
PodcastPress.press!(@file.path, s3_bucket: 'test_bucket')
@episode = PodcastPress.press!(@file.path, s3_bucket: 'test_bucket')
end

it "makes a connection to s3" do
Expand All @@ -32,6 +32,12 @@
args[2].must_equal 'test_bucket'
args[3].must_equal({ access: :public_read })
end

it "returns an episode with a URL" do
@episode.url.must_equal(
"https://s3.amazonaws.com/test_bucket/test_file.mp3"
)
end
end
end

0 comments on commit b7ae42a

Please sign in to comment.