2010-10-04 17:02:08 -04:00
|
|
|
require 'fog/core/collection'
|
2011-08-24 15:12:29 -04:00
|
|
|
require 'fog/rackspace/models/storage/directory'
|
2010-03-19 21:29:42 -04:00
|
|
|
|
2010-02-27 16:39:33 -05:00
|
|
|
module Fog
|
2011-06-15 17:26:43 -04:00
|
|
|
module Storage
|
|
|
|
class Rackspace
|
2010-02-27 16:39:33 -05:00
|
|
|
|
|
|
|
class Directories < Fog::Collection
|
|
|
|
|
2011-06-15 17:26:43 -04:00
|
|
|
model Fog::Storage::Rackspace::Directory
|
2010-02-27 16:39:33 -05:00
|
|
|
|
|
|
|
def all
|
|
|
|
data = connection.get_containers.body
|
2010-03-06 23:02:10 -05:00
|
|
|
load(data)
|
2010-02-27 16:39:33 -05:00
|
|
|
end
|
|
|
|
|
2011-06-16 16:22:37 -04:00
|
|
|
# Supply the :cdn_cname option to use the Rackspace CDN CNAME functionality on the public_url.
|
|
|
|
#
|
|
|
|
# > fog.directories.get('video', :cdn_cname => 'http://cdn.lunenburg.org').files.first.public_url
|
|
|
|
# => 'http://cdn.lunenburg.org/hayley-dancing.mov'
|
2010-05-02 22:59:15 -04:00
|
|
|
def get(key, options = {})
|
2010-10-18 14:09:19 -04:00
|
|
|
data = connection.get_container(key, options)
|
2011-06-16 16:22:37 -04:00
|
|
|
directory = new(:key => key, :cdn_cname => options[:cdn_cname])
|
2010-10-18 14:09:19 -04:00
|
|
|
for key, value in data.headers
|
|
|
|
if ['X-Container-Bytes-Used', 'X-Container-Object-Count'].include?(key)
|
|
|
|
directory.merge_attributes(key => value)
|
|
|
|
end
|
|
|
|
end
|
2010-02-27 16:39:33 -05:00
|
|
|
directory.files.merge_attributes(options)
|
|
|
|
directory.files.instance_variable_set(:@loaded, true)
|
2010-10-18 14:09:19 -04:00
|
|
|
data.body.each do |file|
|
2010-02-27 16:39:33 -05:00
|
|
|
directory.files << directory.files.new(file)
|
|
|
|
end
|
|
|
|
directory
|
2011-06-15 17:26:43 -04:00
|
|
|
rescue Fog::Storage::Rackspace::NotFound
|
2010-02-27 16:39:33 -05:00
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|