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
|
2010-01-14 23:44:39 -05:00
|
|
|
class Directories < Fog::Collection
|
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
|
2012-12-22 18:30:12 -05:00
|
|
|
data = service.get_service.body['Buckets']
|
2010-03-06 23:02:10 -05:00
|
|
|
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
|
|
|
})
|
2012-12-22 18:30:12 -05:00
|
|
|
data = service.get_bucket(key, options).body
|
2013-04-12 14:18:42 -04:00
|
|
|
directory = new(:key => data['Name'], :is_persisted => true)
|
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
|