Class: Aws::S3Generator::Bucket

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(s3, name) ⇒ Bucket

Create new S3LinkBucket instance.



226
227
228
# File 'lib/s3/s3.rb', line 226

def initialize(s3, name)
  @s3, @name = s3, name.to_s
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



203
204
205
# File 'lib/s3/s3.rb', line 203

def name
  @name
end

#s3Object (readonly)

Returns the value of attribute s3.



203
204
205
# File 'lib/s3/s3.rb', line 203

def s3
  @s3
end

Class Method Details

.create(s3, name, expires = nil, headers = {}) ⇒ Object

Create new S3LinkBucket instance and generate creation link for it.



221
222
223
# File 'lib/s3/s3.rb', line 221

def self.create(s3, name, expires=nil, headers={})
  new(s3, name.to_s)
end

Instance Method Details

Return a link to create this bucket.



232
233
234
# File 'lib/s3/s3.rb', line 232

def create_link(expires=nil, headers={})
  @s3.interface.create_bucket_link(@name, expires, headers)
end

#delete(expires = nil, headers = {}) ⇒ Object

Generate link to delete bucket.

bucket.delete(2.hour)


275
276
277
# File 'lib/s3/s3.rb', line 275

def delete(expires=nil, headers={})
  @s3.interface.delete_bucket_link(@name, expires, headers)
end

#get(key, expires = nil, headers = {}) ⇒ Object

Generate link to GET key data.

bucket.get('logs/today/1.log', 1.hour)


267
268
269
# File 'lib/s3/s3.rb', line 267

def get(key, expires=nil, headers={})
  @s3.interface.get_link(@name, key.to_s, expires, headers)
end

#key(name) ⇒ Object

Return a S3Generator::Key instance.

bucket.key('my_cool_key').get    #=> https://s3.amazonaws.com:443/my_awesome_bucket/my_cool_key?Signature=B...D&Expires=1180820032&AWSAccessKeyId=1...2
bucket.key('my_cool_key').delete #=> https://s3.amazonaws.com:443/my_awesome_bucket/my_cool_key?Signature=B...D&Expires=1180820098&AWSAccessKeyId=1...2


250
251
252
# File 'lib/s3/s3.rb', line 250

def key(name)
  Key.new(self, name)
end

#keys(options = nil, expires = nil, headers = {}) ⇒ Object

Generate link to list keys.

bucket.keys
bucket.keys('prefix'=>'logs')


241
242
243
# File 'lib/s3/s3.rb', line 241

def keys(options=nil, expires=nil, headers={})
  @s3.interface.list_bucket_link(@name, options, expires, headers)
end

Return a public link to bucket.

bucket.public_link #=> 'https://s3.amazonaws.com:443/my_awesome_bucket'


215
216
217
218
# File 'lib/s3/s3.rb', line 215

def public_link
  params = @s3.interface.params
  "#{params[:protocol]}://#{params[:server]}:#{params[:port]}/#{full_name}"
end

#put(key, meta_headers = {}, expires = nil, headers = {}) ⇒ Object

Generates link to PUT key data.

puts bucket.put('logs/today/1.log', 2.hour)


258
259
260
261
# File 'lib/s3/s3.rb', line 258

def put(key, meta_headers={}, expires=nil, headers={})
  meta = Aws::S3::Key.add_meta_prefix(meta_headers)
  @s3.interface.put_link(@name, key.to_s, nil, expires, meta.merge(headers))
end

#to_sObject Also known as: full_name



205
206
207
# File 'lib/s3/s3.rb', line 205

def to_s
  @name
end