Class: S3aps::S3Adapter
- Inherits:
-
Object
- Object
- S3aps::S3Adapter
- Defined in:
- lib/s3aps/s3_adapter.rb
Overview
Reads, writes and lists files on S3.
Instance Method Summary collapse
-
#initialize(options) ⇒ S3Adapter
constructor
A new instance of S3Adapter.
-
#list ⇒ Object
List the keys of all files in the bucket.
- #read(key) ⇒ Object
-
#write(s3_name, value) ⇒ Object
Write a value, potentially overwriting what is already there.
Constructor Details
#initialize(options) ⇒ S3Adapter
Returns a new instance of S3Adapter.
9 10 11 12 |
# File 'lib/s3aps/s3_adapter.rb', line 9 def initialize() @s3 = RightAws::S3Interface.new([:key], [:secret], :protocol => 'http', :port => 80) @bucket_name = [:bucket] end |
Instance Method Details
#list ⇒ Object
List the keys of all files in the bucket
15 16 17 18 19 20 21 22 23 |
# File 'lib/s3aps/s3_adapter.rb', line 15 def list keys = [] @s3.incrementally_list_bucket(@bucket_name) {|key_set| keys << key_set[:contents].map {|key| key } } keys.flatten end |
#read(key) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/s3aps/s3_adapter.rb', line 30 def read(key) begin @s3.get_object(@bucket_name, key) rescue raise exc end end |
#write(s3_name, value) ⇒ Object
Write a value, potentially overwriting what is already there.
26 27 28 |
# File 'lib/s3aps/s3_adapter.rb', line 26 def write(s3_name, value) @s3.put(@bucket_name, s3_name, value) end |