Class: S3Utils
- Inherits:
-
Object
- Object
- S3Utils
- Defined in:
- lib/s3utils.rb
Overview
wrapper for S3 operations
Instance Method Summary collapse
- #delete(file_path) ⇒ Object
-
#initialize(access_key_id, secret_access_key, bucket_name, server = nil) ⇒ S3Utils
constructor
A new instance of S3Utils.
- #list ⇒ Object
- #store(file_path) ⇒ Object
Constructor Details
#initialize(access_key_id, secret_access_key, bucket_name, server = nil) ⇒ S3Utils
Returns a new instance of S3Utils.
7 8 9 10 11 12 |
# File 'lib/s3utils.rb', line 7 def initialize(access_key_id, secret_access_key, bucket_name, server=nil) @bucket_name = bucket_name @s3_connection = connect(access_key_id, secret_access_key, server) @s3_bucket = get_or_create_bucket self end |
Instance Method Details
#delete(file_path) ⇒ Object
18 19 20 |
# File 'lib/s3utils.rb', line 18 def delete(file_path) @s3_bucket.objects[File.basename(file_path)].delete end |
#list ⇒ Object
22 23 24 25 26 |
# File 'lib/s3utils.rb', line 22 def list @s3_bucket.objects.each do |obj| puts "#{obj.bucket.name}/#{obj.key}" end end |
#store(file_path) ⇒ Object
14 15 16 |
# File 'lib/s3utils.rb', line 14 def store(file_path) @s3_bucket.objects.create(File.basename(file_path), open(file_path)) end |