Class: S3Link::Main
- Inherits:
-
Object
- Object
- S3Link::Main
- Defined in:
- lib/s3link.rb
Instance Method Summary collapse
- #access_key ⇒ Object
- #bucket_name ⇒ Object
- #establish_connection ⇒ Object
- #expires_hash ⇒ Object
- #generate_url ⇒ Object
-
#initialize ⇒ Main
constructor
A new instance of Main.
- #run_from_cmd_line ⇒ Object
- #secret_key ⇒ Object
- #upload_file ⇒ Object
Constructor Details
#initialize ⇒ Main
Returns a new instance of Main.
11 12 13 |
# File 'lib/s3link.rb', line 11 def initialize @options = {} end |
Instance Method Details
#access_key ⇒ Object
37 38 39 |
# File 'lib/s3link.rb', line 37 def access_key @options[:access_key] || ENV["AMAZON_ACCESS_KEY_ID"] || false end |
#bucket_name ⇒ Object
49 50 51 |
# File 'lib/s3link.rb', line 49 def bucket_name @options[:bucket] || ENV["S3LINK_BUCKET_NAME"] end |
#establish_connection ⇒ Object
33 34 35 |
# File 'lib/s3link.rb', line 33 def establish_connection @aws = AWS::S3::Base.establish_connection!(:access_key_id => access_key, :secret_access_key => secret_key) end |
#expires_hash ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/s3link.rb', line 57 def expires_hash if @options[:never_expire] doomsday = Time.mktime(2038, 1, 18).to_i {:expires => doomsday} elsif @options[:expires_in] # Convert from hours to seconds {:expires_in => @options[:expires_in] * 60 * 60} else # 24 hours default {:expires_in => 24 * 60 * 60} end end |
#generate_url ⇒ Object
53 54 55 |
# File 'lib/s3link.rb', line 53 def generate_url AWS::S3::S3Object.url_for(@options[:filename], bucket_name, expires_hash ) end |
#run_from_cmd_line ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/s3link.rb', line 15 def run_from_cmd_line @options = begin S3Link::CommandLineParser.new($ARGV).parse rescue CmdLineArgsError Usage.new end puts "Establishing Connection" unless @options[:silent] establish_connection puts "Uploading File... please wait" unless @options[:silent] upload_file url = generate_url print "URL: " unless @options[:silent] puts "#{url}" end |
#secret_key ⇒ Object
41 42 43 |
# File 'lib/s3link.rb', line 41 def secret_key @options[:secret_key] || ENV["AMAZON_SECRET_ACCESS_KEY"] || false end |
#upload_file ⇒ Object
45 46 47 |
# File 'lib/s3link.rb', line 45 def upload_file AWS::S3::S3Object.store(@options[:filename], File.open(@options[:filename]), bucket_name) end |