1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/aws/models/s3/buckets.rb

63 lines
1.8 KiB
Ruby
Raw Normal View History

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
model Fog::AWS::S3::Bucket
2009-08-02 19:37:54 -04:00
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))
buckets = Fog::AWS::S3::Buckets.new(:connection => connection)
2009-08-02 19:37:54 -04:00
data['Buckets'].each do |bucket|
buckets << Fog::AWS::S3::Bucket.new({
:collection => buckets,
:connection => connection,
:owner => owner
2009-08-04 13:51:54 -04:00
}.merge!(bucket))
2009-08-02 19:37:54 -04:00
end
buckets
2009-08-02 19:37:54 -04:00
end
def get(name, options = {})
remap_attributes(options, {
2009-09-21 14:40:16 -04:00
:max_keys => 'max-keys',
})
data = connection.get_bucket(name, options).body
bucket = Fog::AWS::S3::Bucket.new({
:collection => self,
:connection => connection,
:name => data['Name']
})
2009-09-21 14:40:16 -04:00
options = {}
for key, value in data
2009-09-21 14:40:16 -04:00
if ['Delimiter', 'IsTruncated', 'Marker', 'MaxKeys', 'Prefix'].include?(key)
options[key] = value
end
end
bucket.objects.merge_attributes(options)
data['Contents'].each do |object|
owner = Fog::AWS::S3::Owner.new(object.delete('Owner').merge!(:connection => connection))
bucket.objects << Fog::AWS::S3::Object.new({
:bucket => bucket,
:connection => connection,
:collection => bucket.objects,
:owner => owner
}.merge!(object))
end
bucket
rescue Fog::Errors::NotFound
nil
end
2009-08-02 19:37:54 -04:00
end
end
end
end