2009-08-02 19:37:54 -04:00
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
class S3
|
|
|
|
|
|
|
|
def buckets
|
|
|
|
Fog::AWS::S3::Buckets.new(:connection => self)
|
|
|
|
end
|
|
|
|
|
|
|
|
class Buckets < Fog::Collection
|
|
|
|
|
|
|
|
def all
|
|
|
|
data = connection.get_service.body
|
2009-08-04 13:51:54 -04:00
|
|
|
owner = Fog::AWS::S3::Owner.new(data.delete('Owner').merge!(:connection => connection))
|
2009-09-04 21:24:11 -04:00
|
|
|
buckets = Fog::AWS::S3::Buckets.new(:connection => connection)
|
2009-08-02 19:37:54 -04:00
|
|
|
data['Buckets'].each do |bucket|
|
2009-09-04 21:24:11 -04:00
|
|
|
buckets << Fog::AWS::S3::Bucket.new({
|
|
|
|
:buckets => buckets,
|
2009-08-28 12:03:19 -04:00
|
|
|
:connection => connection,
|
|
|
|
:owner => owner
|
2009-08-04 13:51:54 -04:00
|
|
|
}.merge!(bucket))
|
2009-08-02 19:37:54 -04:00
|
|
|
end
|
2009-09-04 21:24:11 -04:00
|
|
|
buckets
|
2009-08-02 19:37:54 -04:00
|
|
|
end
|
|
|
|
|
2009-08-04 01:50:52 -04:00
|
|
|
def create(attributes = {})
|
|
|
|
bucket = new(attributes)
|
|
|
|
bucket.save
|
|
|
|
bucket
|
|
|
|
end
|
|
|
|
|
2009-08-29 14:20:54 -04:00
|
|
|
def get(name, options = {})
|
2009-09-02 00:41:52 -04:00
|
|
|
remap_attributes(options, {
|
|
|
|
:is_truncated => 'IsTruncated',
|
|
|
|
:marker => 'Marker',
|
|
|
|
:max_keys => 'MaxKeys',
|
|
|
|
:prefix => 'Prefix'
|
|
|
|
})
|
|
|
|
data = connection.get_bucket(name, options).body
|
|
|
|
bucket = Fog::AWS::S3::Bucket.new({
|
|
|
|
:buckets => self,
|
|
|
|
:connection => connection,
|
|
|
|
:name => data['Name']
|
|
|
|
})
|
|
|
|
objects_data = {}
|
|
|
|
for key, value in data
|
|
|
|
if ['IsTruncated', 'Marker', 'MaxKeys', 'Prefix'].include?(key)
|
|
|
|
objects_data[key] = value
|
2009-09-01 01:40:07 -04:00
|
|
|
end
|
2009-08-29 14:20:54 -04:00
|
|
|
end
|
2009-09-02 00:41:52 -04:00
|
|
|
bucket.objects.merge_attributes(objects_data)
|
|
|
|
data['Contents'].each do |object|
|
|
|
|
owner = Fog::AWS::S3::Owner.new(object.delete('Owner').merge!(:connection => connection))
|
2009-09-04 21:24:11 -04:00
|
|
|
bucket.objects << Fog::AWS::S3::Object.new({
|
2009-09-02 00:41:52 -04:00
|
|
|
:bucket => bucket,
|
|
|
|
:connection => connection,
|
|
|
|
:objects => self,
|
|
|
|
:owner => owner
|
|
|
|
}.merge!(object))
|
|
|
|
end
|
|
|
|
bucket
|
|
|
|
rescue Fog::Errors::NotFound
|
|
|
|
nil
|
2009-08-29 14:20:54 -04:00
|
|
|
end
|
|
|
|
|
2009-08-04 01:50:52 -04:00
|
|
|
def new(attributes = {})
|
2009-08-28 12:03:19 -04:00
|
|
|
Fog::AWS::S3::Bucket.new(
|
|
|
|
attributes.merge!(
|
|
|
|
:connection => connection,
|
|
|
|
:buckets => self
|
|
|
|
)
|
|
|
|
)
|
2009-08-04 01:50:52 -04:00
|
|
|
end
|
|
|
|
|
2009-09-02 00:41:52 -04:00
|
|
|
def reload
|
|
|
|
all
|
|
|
|
end
|
|
|
|
|
2009-08-02 19:37:54 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|