Class: Buckets::Bucket

Inherits:
Utils
  • Object
show all
Defined in:
lib/buckets.rb

Overview

Bucket

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Utils

#connection

Constructor Details

#initialize(*args) ⇒ Bucket

Returns a new instance of Bucket.



97
98
99
100
101
102
# File 'lib/buckets.rb', line 97

def initialize(*args)
  options = {}
  options.merge!(args.pop) if args.last.is_a? Hash
  @name       = options[:name]
  @created_at = options[:created_at]
end

Instance Attribute Details

#created_atObject

Returns the value of attribute created_at.



95
96
97
# File 'lib/buckets.rb', line 95

def created_at
  @created_at
end

#nameObject

Returns the value of attribute name.



95
96
97
# File 'lib/buckets.rb', line 95

def name
  @name
end

Instance Method Details

#add_object(name, data, content_type = 'binary/octet-stream', *args) ⇒ Object

add an object to this bucket pass in a name, a File or IO object, it’s content type and a hash containing additional headers (keys and values)



117
118
119
120
121
122
123
124
125
# File 'lib/buckets.rb', line 117

def add_object(name, data, content_type='binary/octet-stream', *args)
  data.rewind
  additional_headers = {
      'Content-MD5' => Base64.encode64(Digest::MD5.digest(data.read)).strip,
      'Content-Type' => content_type
  }
  additional_headers.merge!(args.pop) if args.last.is_a? Hash
  connection.put("/#{URI.escape(name)}", @name, data, additional_headers)
end

#delete(options = {}) ⇒ Object

Delete this bucket if it’s empty



105
106
107
# File 'lib/buckets.rb', line 105

def delete(options={})
  connection.delete("/", @name)
end