2010-03-13 16:37:24 -05:00
|
|
|
require 'fog/model'
|
|
|
|
require 'fog/aws/models/s3/files'
|
|
|
|
|
2009-08-02 19:37:54 -04:00
|
|
|
module Fog
|
|
|
|
module AWS
|
2010-09-03 04:11:45 -04:00
|
|
|
class S3
|
2009-08-02 19:37:54 -04:00
|
|
|
|
2010-01-14 23:44:39 -05:00
|
|
|
class Directory < Fog::Model
|
2010-05-02 22:59:15 -04:00
|
|
|
extend Fog::Deprecation
|
|
|
|
deprecate(:name, :key)
|
2010-05-04 17:31:42 -04:00
|
|
|
deprecate(:name=, :key=)
|
2009-08-02 19:37:54 -04:00
|
|
|
|
2010-05-04 17:31:42 -04:00
|
|
|
identity :key, ['Name', 'name']
|
2009-10-23 13:27:23 -04:00
|
|
|
|
2009-08-30 17:43:01 -04:00
|
|
|
attribute :creation_date, 'CreationDate'
|
2009-08-04 13:51:54 -04:00
|
|
|
|
2009-08-30 17:14:11 -04:00
|
|
|
def destroy
|
2010-05-02 22:59:15 -04:00
|
|
|
requires :key
|
|
|
|
connection.delete_bucket(key)
|
2009-08-27 23:47:01 -04:00
|
|
|
true
|
2009-11-08 15:16:52 -05:00
|
|
|
rescue Excon::Errors::NotFound
|
2009-09-01 01:40:07 -04:00
|
|
|
false
|
2009-08-04 01:50:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def location
|
2010-05-02 22:59:15 -04:00
|
|
|
requires :key
|
|
|
|
data = connection.get_bucket_location(key)
|
2009-09-02 23:17:53 -04:00
|
|
|
data.body['LocationConstraint']
|
2009-08-04 01:50:52 -04:00
|
|
|
end
|
|
|
|
|
2009-10-23 12:42:51 -04:00
|
|
|
def location=(new_location)
|
|
|
|
@location = new_location
|
|
|
|
end
|
|
|
|
|
2010-01-14 23:44:39 -05:00
|
|
|
def files
|
|
|
|
@files ||= begin
|
|
|
|
Fog::AWS::S3::Files.new(
|
|
|
|
:directory => self,
|
2009-09-02 00:41:52 -04:00
|
|
|
:connection => connection
|
|
|
|
)
|
|
|
|
end
|
2009-08-13 01:48:17 -04:00
|
|
|
end
|
|
|
|
|
2009-08-04 01:50:52 -04:00
|
|
|
def payer
|
2010-05-02 22:59:15 -04:00
|
|
|
requires :key
|
|
|
|
data = connection.get_request_payment(key)
|
2009-09-02 23:17:53 -04:00
|
|
|
data.body['Payer']
|
2009-08-04 01:50:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def payer=(new_payer)
|
2010-05-02 22:59:15 -04:00
|
|
|
requires :key
|
|
|
|
connection.put_request_payment(key, new_payer)
|
2009-08-04 01:54:34 -04:00
|
|
|
@payer = new_payer
|
2009-08-04 01:50:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
2010-05-02 22:59:15 -04:00
|
|
|
requires :key
|
2009-08-04 01:50:52 -04:00
|
|
|
options = {}
|
|
|
|
if @location
|
|
|
|
options['LocationConstraint'] = @location
|
|
|
|
end
|
2010-05-02 22:59:15 -04:00
|
|
|
connection.put_bucket(key, options)
|
2009-08-27 23:47:01 -04:00
|
|
|
true
|
2009-08-04 01:50:52 -04:00
|
|
|
end
|
2009-08-02 19:37:54 -04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|