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