2010-10-04 14:02:08 -07:00
|
|
|
require 'fog/core/collection'
|
2011-08-24 13:50:42 -05:00
|
|
|
require 'fog/aws/models/storage/directory'
|
2010-03-13 13:37:24 -08:00
|
|
|
|
2009-08-02 16:37:54 -07:00
|
|
|
module Fog
|
2011-06-15 14:26:43 -07:00
|
|
|
module Storage
|
|
|
|
class AWS
|
2009-08-02 16:37:54 -07:00
|
|
|
|
2010-01-14 20:44:39 -08:00
|
|
|
class Directories < Fog::Collection
|
2009-08-02 16:37:54 -07:00
|
|
|
|
2011-06-15 14:26:43 -07:00
|
|
|
model Fog::Storage::AWS::Directory
|
2009-10-29 23:35:28 -07:00
|
|
|
|
2009-08-02 16:37:54 -07:00
|
|
|
def all
|
2010-03-06 20:02:10 -08:00
|
|
|
data = connection.get_service.body['Buckets']
|
|
|
|
load(data)
|
2009-08-02 16:37:54 -07:00
|
|
|
end
|
|
|
|
|
2010-05-02 19:59:15 -07:00
|
|
|
def get(key, options = {})
|
2009-09-01 21:41:52 -07:00
|
|
|
remap_attributes(options, {
|
2010-01-05 17:27:09 -08:00
|
|
|
:delimiter => 'delimiter',
|
|
|
|
:marker => 'marker',
|
|
|
|
:max_keys => 'max-keys',
|
|
|
|
:prefix => 'prefix'
|
2009-09-01 21:41:52 -07:00
|
|
|
})
|
2010-05-02 19:59:15 -07:00
|
|
|
data = connection.get_bucket(key, options).body
|
|
|
|
directory = new(:key => data['Name'])
|
2009-09-21 11:40:16 -07:00
|
|
|
options = {}
|
2010-06-18 14:23:52 -07:00
|
|
|
for k, v in data
|
2010-11-19 14:09:06 -08:00
|
|
|
if ['CommonPrefixes', 'Delimiter', 'IsTruncated', 'Marker', 'MaxKeys', 'Prefix'].include?(k)
|
2010-06-18 14:23:52 -07:00
|
|
|
options[k] = v
|
2009-08-31 22:40:07 -07:00
|
|
|
end
|
2009-08-29 11:20:54 -07:00
|
|
|
end
|
2010-01-14 20:44:39 -08:00
|
|
|
directory.files.merge_attributes(options)
|
2010-06-18 17:16:58 -07:00
|
|
|
directory.files.load(data['Contents'])
|
2010-01-14 20:44:39 -08:00
|
|
|
directory
|
2009-11-08 12:16:52 -08:00
|
|
|
rescue Excon::Errors::NotFound
|
2009-09-01 21:41:52 -07:00
|
|
|
nil
|
2009-08-29 11:20:54 -07:00
|
|
|
end
|
|
|
|
|
2009-08-02 16:37:54 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|