Class: S3restful::S3::Item
- Inherits:
-
Object
- Object
- S3restful::S3::Item
- Includes:
- Utils
- Defined in:
- lib/s3restful/s3/item.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
-
#aws_id ⇒ Object
Returns the value of attribute aws_id.
-
#bucket ⇒ Object
Returns the value of attribute bucket.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #aget(request_options = {}, &blk) ⇒ Object
- #delete(request_options = {}, &blk) ⇒ Object
- #get(request_options = {}, &blk) ⇒ Object
- #head(request_options = {}, &blk) ⇒ Object
-
#initialize(bucket, aws_id, options = {}) ⇒ Item
constructor
A new instance of Item.
- #path(with_bucket = true) ⇒ Object
- #put(data, request_options = {}, &blk) ⇒ Object
- #server ⇒ Object
- #store(file_path, request_options = {}, &blk) ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(bucket, aws_id, options = {}) ⇒ Item
Returns a new instance of Item.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/s3restful/s3/item.rb', line 14 def initialize(bucket, aws_id, = {}) @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 => S3restful::S3. }.update(symbolize_keys()) assert_valid_keys(, :timeout, :server, :port, :protocol, :aws_access_key_id, :aws_secret_access_key, :retry_count, :permissions, :ssl) @aws_id = aws_id.to_s @bucket = bucket.to_s validate end |
Instance Attribute Details
#aws_id ⇒ Object
Returns the value of attribute aws_id.
12 13 14 |
# File 'lib/s3restful/s3/item.rb', line 12 def aws_id @aws_id end |
#bucket ⇒ Object
Returns the value of attribute bucket.
12 13 14 |
# File 'lib/s3restful/s3/item.rb', line 12 def bucket @bucket end |
#options ⇒ Object
Returns the value of attribute options.
12 13 14 |
# File 'lib/s3restful/s3/item.rb', line 12 def @options end |
Instance Method Details
#aget(request_options = {}, &blk) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/s3restful/s3/item.rb', line 46 def aget( = {}, &blk) headers = needs_to_sign? ? aws.sign("GET", path) : {} [:on_success] = blk if blk .update(:headers => headers) S3restful::S3::Request.new(:aget, url, {:ssl => [:ssl]}.update()).execute end |
#delete(request_options = {}, &blk) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/s3restful/s3/item.rb', line 67 def delete( = {}, &blk) headers = needs_to_sign? ? aws.sign("DELETE", path, {'url' => path}) : {} [:on_success] = blk if blk .update(:headers => headers) S3restful::S3::Request.new(:delete, url, {:ssl => [:ssl]}.update()).execute end |
#get(request_options = {}, &blk) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/s3restful/s3/item.rb', line 39 def get( = {}, &blk) headers = needs_to_sign? ? aws.sign("GET", path) : {} [:on_success] = blk if blk .update(:headers => headers) S3restful::S3::Request.new(:get, url, {:ssl => [:ssl]}.update()).execute end |
#head(request_options = {}, &blk) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/s3restful/s3/item.rb', line 32 def head( = {}, &blk) headers = needs_to_sign? ? aws.sign("HEAD", path) : {} [:on_success] = blk if blk .update(:headers => headers) S3restful::S3::Request.new(:head, url, {:ssl => [:ssl]}.update()).execute end |
#path(with_bucket = true) ⇒ Object
84 85 86 |
# File 'lib/s3restful/s3/item.rb', line 84 def path(with_bucket=true) with_bucket ? "/#{bucket}/#{CGI::escape(aws_id)}" : "/#{CGI::escape(aws_id)}" end |
#put(data, request_options = {}, &blk) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/s3restful/s3/item.rb', line 53 def put(data, = {}, &blk) headers = construct_aws_headers('PUT', .delete(:headers) || {}) [:on_success] = blk if blk .update(:headers => headers, :data => data) S3restful::S3::Request.new(:put, url, {:ssl => [:ssl]}.update()).execute end |
#server ⇒ Object
79 80 81 82 |
# File 'lib/s3restful/s3/item.rb', line 79 def server return [:server] if [:port] dns_bucket? ? "#{bucket}.#{[:server]}" : [:server] end |
#store(file_path, request_options = {}, &blk) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/s3restful/s3/item.rb', line 60 def store(file_path, = {}, &blk) headers = construct_aws_headers('PUT', .delete(:headers) || {}) [:on_success] = blk if blk .update(:headers => headers, :file => file_path) S3restful::S3::Request.new(:put, url, {:ssl => [:ssl]}.update()).execute end |
#url ⇒ Object
74 75 76 77 |
# File 'lib/s3restful/s3/item.rb', line 74 def url uri = [:port] ? path : path(!dns_bucket?) URI::Generic.new([:protocol], nil, server, port, nil, uri, nil, nil, nil).to_s end |