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/directories.rb

61 lines
1.5 KiB
Ruby
Raw Normal View History

2010-03-13 13:37:24 -08:00
require 'fog/collection'
require 'fog/aws/models/s3/directory'
2009-08-02 16:37:54 -07:00
module Fog
module AWS
2010-03-13 13:37:24 -08:00
module S3
class Real
def directories
Fog::AWS::S3::Directories.new(:connection => self)
end
end
2009-08-02 16:37:54 -07:00
2010-03-13 13:37:24 -08:00
class Mock
def directories
Fog::AWS::S3::Directories.new(:connection => self)
end
2009-08-02 16:37:54 -07:00
end
2010-01-14 20:44:39 -08:00
class Directories < Fog::Collection
2009-08-02 16:37:54 -07:00
2010-01-14 20:44:39 -08:00
model Fog::AWS::S3::Directory
2009-08-02 16:37:54 -07:00
def all
data = connection.get_service.body['Buckets']
load(data)
2009-08-02 16:37:54 -07:00
end
def get(key, options = {})
remap_attributes(options, {
:delimiter => 'delimiter',
:marker => 'marker',
:max_keys => 'max-keys',
:prefix => 'prefix'
})
data = connection.get_bucket(key, options).body
directory = new(:key => data['Name'])
2009-09-21 11:40:16 -07:00
options = {}
for key, value in data
2009-09-21 11:40:16 -07:00
if ['Delimiter', 'IsTruncated', 'Marker', 'MaxKeys', 'Prefix'].include?(key)
options[key] = value
end
end
2010-01-14 20:44:39 -08:00
directory.files.merge_attributes(options)
files = data['Contents']
while data['IsTruncated']
data = connection.get_bucket(key, options.merge!('marker' => files.last['Key'])).body
files.concat(data['Contents'])
end
directory.files.load(files)
2010-01-14 20:44:39 -08:00
directory
rescue Excon::Errors::NotFound
nil
end
2009-08-02 16:37:54 -07:00
end
end
end
end