Class: Fog::AWS::S3::Buckets

Inherits:
Collection show all
Defined in:
lib/fog/aws/models/s3/buckets.rb

Instance Method Summary collapse

Methods inherited from Collection

#_dump, _load, aliases, attribute, attributes, #attributes, #connection, #connection=, #create, #initialize, #inspect, #merge_attributes, model, #model, #new, #reload

Constructor Details

This class inherits a constructor from Fog::Collection

Instance Method Details

#allObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fog/aws/models/s3/buckets.rb', line 13

def all
  data = connection.get_service.body
  buckets = Fog::AWS::S3::Buckets.new(:connection => connection)
  data['Buckets'].each do |bucket|
    buckets << Fog::AWS::S3::Bucket.new({
      :collection => buckets,
      :connection => connection,
      :owner      => {
        :display_name => owner['DisplayName'], 
        :id => owner['ID']
      }
    }.merge!(bucket))
  end
  buckets
end

#get(name, options = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/fog/aws/models/s3/buckets.rb', line 29

def get(name, options = {})
  remap_attributes(options, {
    :max_keys     => 'max-keys',
  })
  data = connection.get_bucket(name, options).body
  bucket = Fog::AWS::S3::Bucket.new({
    :collection => self,
    :connection => connection,
    :name       => data['Name']
  })
  options = {}
  for key, value in data
    if ['Delimiter', 'IsTruncated', 'Marker', 'MaxKeys', 'Prefix'].include?(key)
      options[key] = value
    end
  end
  bucket.objects.merge_attributes(options)
  data['Contents'].each do |object|
    bucket.objects << Fog::AWS::S3::Object.new({
      :bucket     => bucket,
      :connection => connection,
      :collection => bucket.objects,
      :owner      => {
        :display_name => owner['DisplayName'], 
        :id => owner['ID']
      }
    }.merge!(object))
  end
  bucket
rescue Excon::Errors::NotFound
  nil
end