Class: S3Interface
- Inherits:
-
Object
- Object
- S3Interface
- Includes:
- EM::Deferrable
- Defined in:
- lib/s3_interface.rb
Instance Attribute Summary collapse
-
#private_key ⇒ Object
Credits to forrst.com/posts/Basic_Amazon_S3_Upload_via_PUT_Ruby_Class-4t6 Refer to the following for S3 documentation docs.amazonwebservices.com/AmazonS3/latest/dev/RESTAuthentication.html#RESTAuthenticationConstructingCanonicalizedAmzHeaders docs.amazonwebservices.com/AmazonS3/latest/API/RESTObjectPUT.html docs.amazonwebservices.com/AmazonS3/latest/API/RESTObjectGET.html.
-
#public_key ⇒ Object
Credits to forrst.com/posts/Basic_Amazon_S3_Upload_via_PUT_Ruby_Class-4t6 Refer to the following for S3 documentation docs.amazonwebservices.com/AmazonS3/latest/dev/RESTAuthentication.html#RESTAuthenticationConstructingCanonicalizedAmzHeaders docs.amazonwebservices.com/AmazonS3/latest/API/RESTObjectPUT.html docs.amazonwebservices.com/AmazonS3/latest/API/RESTObjectGET.html.
Instance Method Summary collapse
-
#get(params) ⇒ self
Gets any of the objects from S3 buckets.
-
#initialize(public_key, private_key, options = {}) ⇒ S3Interface
constructor
A new instance of S3Interface.
-
#put(params) ⇒ self
Puts any of the objects into S3 buckets.
Constructor Details
#initialize(public_key, private_key, options = {}) ⇒ S3Interface
Returns a new instance of S3Interface.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/s3_interface.rb', line 13 def initialize(public_key, private_key, = {}) @public_key = public_key @private_key = private_key @options = .merge({:retry_count => 3}) @num_tries = 0 errback{|resp, status| if (@num_tries += 1) < retry_count retry_request else @cb.call resp, status if @cb succeed resp, status end } end |
Instance Attribute Details
#private_key ⇒ Object
Credits to forrst.com/posts/Basic_Amazon_S3_Upload_via_PUT_Ruby_Class-4t6 Refer to the following for S3 documentation docs.amazonwebservices.com/AmazonS3/latest/dev/RESTAuthentication.html#RESTAuthenticationConstructingCanonicalizedAmzHeaders docs.amazonwebservices.com/AmazonS3/latest/API/RESTObjectPUT.html docs.amazonwebservices.com/AmazonS3/latest/API/RESTObjectGET.html
11 12 13 |
# File 'lib/s3_interface.rb', line 11 def private_key @private_key end |
#public_key ⇒ Object
Credits to forrst.com/posts/Basic_Amazon_S3_Upload_via_PUT_Ruby_Class-4t6 Refer to the following for S3 documentation docs.amazonwebservices.com/AmazonS3/latest/dev/RESTAuthentication.html#RESTAuthenticationConstructingCanonicalizedAmzHeaders docs.amazonwebservices.com/AmazonS3/latest/API/RESTObjectPUT.html docs.amazonwebservices.com/AmazonS3/latest/API/RESTObjectGET.html
11 12 13 |
# File 'lib/s3_interface.rb', line 11 def public_key @public_key end |
Instance Method Details
#get(params) ⇒ self
Gets any of the objects from S3 buckets
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/s3_interface.rb', line 64 def get(params) bucket = params[:bucket] object = params[:object] content_type = params[:content_type] cb = params[:cb] date = generate_date sign_string = generate_signed_string('GET', nil, bucket, object, 'text/plain') signature = generate_signature(sign_string) auth = generate_auth(signature) headers = generate_get_headers(date, auth, 'text/plain') path = "/" << object @req_options = {:method => :get, :head => headers, :path => path} @cb = cb if cb @bucket = bucket try_request self end |
#put(params) ⇒ self
Puts any of the objects into S3 buckets
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/s3_interface.rb', line 38 def put(params) bucket = params[:bucket] object = params[:object] value = params[:value] content_type = params[:content_type] cb = params[:cb] date = generate_date sign_string = generate_signed_string('PUT', 'private', bucket, object, content_type) signature = generate_signature(sign_string) auth = generate_auth(signature) headers = generate_put_headers(date, auth, 'private', content_type, value.size) path = "/" << object @req_options = {:method => :put, :head => headers, :path => path, :body => value} @cb = cb if cb @bucket = bucket try_request self end |