2009-08-02 19:37:54 -04:00
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
class S3
|
|
|
|
|
|
|
|
class Bucket < Fog::Model
|
|
|
|
|
2009-08-06 01:55:09 -04:00
|
|
|
attr_accessor :creation_date, :location, :name, :objects, :owner
|
2009-08-04 13:51:54 -04:00
|
|
|
|
|
|
|
def initialize(attributes = {})
|
|
|
|
remap_attributes(attributes, {
|
|
|
|
'CreationDate' => :creation_date,
|
|
|
|
'Name' => :name
|
|
|
|
})
|
|
|
|
super
|
2009-08-06 01:55:09 -04:00
|
|
|
@objects ||= Fog::AWS::S3::Objects.new({
|
|
|
|
:bucket => bucket,
|
|
|
|
:connection => connection
|
|
|
|
})
|
2009-08-04 13:51:54 -04:00
|
|
|
end
|
2009-08-04 01:50:52 -04:00
|
|
|
|
|
|
|
def delete
|
2009-08-04 22:44:04 -04:00
|
|
|
return false if new_record?
|
2009-08-04 01:50:52 -04:00
|
|
|
connection.delete_bucket(name)
|
2009-08-04 22:44:04 -04:00
|
|
|
@new_record = true
|
2009-08-04 01:50:52 -04:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def location
|
2009-08-04 01:54:34 -04:00
|
|
|
@location ||= begin
|
|
|
|
data = s3.get_bucket_location(name)
|
|
|
|
data.body['LocationConstraint']
|
|
|
|
end
|
2009-08-04 01:50:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def payer
|
2009-08-04 01:54:34 -04:00
|
|
|
@payer ||= begin
|
|
|
|
data = connection.get_request_payment(name)
|
|
|
|
data.body['Payer']
|
|
|
|
end
|
2009-08-04 01:50:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def payer=(new_payer)
|
|
|
|
connection.put_request_payment(name, new_payer)
|
2009-08-04 01:54:34 -04:00
|
|
|
@payer = new_payer
|
2009-08-04 01:50:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
|
|
|
options = {}
|
|
|
|
if @location
|
|
|
|
options['LocationConstraint'] = @location
|
|
|
|
end
|
|
|
|
connection.put_bucket(name, options)
|
2009-08-04 22:44:04 -04:00
|
|
|
@new_record = false
|
2009-08-04 01:50:52 -04:00
|
|
|
true
|
|
|
|
end
|
2009-08-02 19:37:54 -04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|