2010-10-04 17:02:08 -04:00
|
|
|
require 'fog/core/collection'
|
2010-09-18 13:40:48 -04:00
|
|
|
require 'fog/google/models/storage/directory'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Google
|
|
|
|
class Storage
|
|
|
|
|
|
|
|
class Directories < Fog::Collection
|
|
|
|
|
|
|
|
model Fog::Google::Storage::Directory
|
|
|
|
|
|
|
|
def all
|
2010-09-18 14:36:52 -04:00
|
|
|
data = connection.get_service.body['Buckets']
|
|
|
|
load(data)
|
2010-09-18 13:40:48 -04: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'])
|
|
|
|
options = {}
|
|
|
|
for k, v in data
|
|
|
|
if ['Delimiter', 'IsTruncated', 'Marker', 'MaxKeys', 'Prefix'].include?(k)
|
|
|
|
options[k] = v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
directory.files.merge_attributes(options)
|
|
|
|
directory.files.load(data['Contents'])
|
|
|
|
directory
|
|
|
|
rescue Excon::Errors::NotFound
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|