Class: S3Interface

Inherits:
Object
  • Object
show all
Includes:
EM::Deferrable
Defined in:
lib/s3_interface.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @public_key = public_key
  @private_key = private_key
  @options = 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_keyObject



11
12
13
# File 'lib/s3_interface.rb', line 11

def private_key
  @private_key
end

#public_keyObject



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

Parameters:

  • bucket (String)

    The name of the bucket

  • object (String)

    The name of the object’s key

Returns:

  • (self)


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

Parameters:

  • bucket (String)

    The name of the bucket

  • object (String)

    The name of the object’s key

  • value (String)

    The object’s value

  • content_type (String)

    The value’s MIME type

Returns:

  • (self)


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