Class: Happening::S3::Bucket
- Inherits:
-
Object
- Object
- Happening::S3::Bucket
- Includes:
- Utils
- Defined in:
- lib/happening/s3/bucket.rb
Constant Summary collapse
- REQUIRED_FIELDS =
[:server]
- VALID_HEADERS =
['Cache-Control', 'Content-Disposition', 'Content-Encoding', 'Content-Length', 'Content-MD5', 'Content-Type', 'Expect', 'Expires']
Instance Attribute Summary collapse
-
#bucket ⇒ Object
Returns the value of attribute bucket.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #get(request_options = {}, &blk) ⇒ Object
-
#initialize(bucket, options = {}) ⇒ Bucket
constructor
A new instance of Bucket.
- #path(with_bucket = true) ⇒ Object
- #path_with_query(with_bucket = true) ⇒ Object
- #server ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(bucket, options = {}) ⇒ Bucket
Returns a new instance of Bucket.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/happening/s3/bucket.rb', line 14 def initialize(bucket, = {}) @options = { :timeout => 10, :server => 's3.amazonaws.com', :protocol => 'https', :aws_access_key_id => nil, :aws_secret_access_key => nil, :retry_count => 4, :permissions => 'private', :ssl => Happening::S3., :prefix => nil, :delimiter => nil }.update(symbolize_keys()) assert_valid_keys(, :timeout, :server, :protocol, :aws_access_key_id, :aws_secret_access_key, :retry_count, :permissions, :ssl, :prefix, :delimiter) @bucket = bucket.to_s validate end |
Instance Attribute Details
#bucket ⇒ Object
Returns the value of attribute bucket.
12 13 14 |
# File 'lib/happening/s3/bucket.rb', line 12 def bucket @bucket end |
#options ⇒ Object
Returns the value of attribute options.
12 13 14 |
# File 'lib/happening/s3/bucket.rb', line 12 def @options end |
Instance Method Details
#get(request_options = {}, &blk) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/happening/s3/bucket.rb', line 33 def get( = {}, &blk) headers = needs_to_sign? ? aws.sign("GET", path_with_query) : {} [:on_success] = blk if blk .update(:headers => headers) Happening::S3::Request.new(:get, url, {:ssl => [:ssl]}.update()).execute end |
#path(with_bucket = true) ⇒ Object
48 49 50 |
# File 'lib/happening/s3/bucket.rb', line 48 def path(with_bucket=true) with_bucket ? "/#{bucket}/" : "/" end |
#path_with_query(with_bucket = true) ⇒ Object
52 53 54 55 56 |
# File 'lib/happening/s3/bucket.rb', line 52 def path_with_query(with_bucket=true) base = path(with_bucket) query = query_string query ? "#{base}?#{query}" : base end |
#server ⇒ Object
44 45 46 |
# File 'lib/happening/s3/bucket.rb', line 44 def server dns_bucket? ? "#{bucket}.#{[:server]}" : [:server] end |
#url ⇒ Object
40 41 42 |
# File 'lib/happening/s3/bucket.rb', line 40 def url URI::Generic.new([:protocol], nil, server, port, nil, path(!dns_bucket?), nil, query_string, nil).to_s end |