2010-10-04 14:02:08 -07:00
|
|
|
require 'fog/core/collection'
|
2011-08-24 14:12:29 -05:00
|
|
|
require 'fog/rackspace/models/storage/directory'
|
2010-03-19 18:29:42 -07:00
|
|
|
|
2010-02-27 13:39:33 -08:00
|
|
|
module Fog
|
2011-06-15 14:26:43 -07:00
|
|
|
module Storage
|
|
|
|
class Rackspace
|
2010-02-27 13:39:33 -08:00
|
|
|
class Directories < Fog::Collection
|
2011-06-15 14:26:43 -07:00
|
|
|
model Fog::Storage::Rackspace::Directory
|
2010-02-27 13:39:33 -08:00
|
|
|
|
2013-03-07 16:01:42 -06:00
|
|
|
# Returns list of directories
|
2013-03-27 09:50:30 -05:00
|
|
|
# @return [Fog::Storage::Rackspace::Directories] Retrieves a list directories.
|
2013-04-15 13:12:14 -05:00
|
|
|
# @raise [Fog::Storage::Rackspace::NotFound] - HTTP 404
|
|
|
|
# @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400
|
|
|
|
# @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500
|
|
|
|
# @raise [Fog::Storage::Rackspace::ServiceError]
|
2013-03-07 16:01:42 -06:00
|
|
|
# @note Fog's current implementation only returns 10,000 directories
|
|
|
|
# @see http://docs.rackspace.com/files/api/v1/cf-devguide/content/View_List_of_Containers-d1e1100.html
|
2010-02-27 13:39:33 -08:00
|
|
|
def all
|
2012-12-22 23:24:03 +00:00
|
|
|
data = service.get_containers.body
|
2010-03-06 20:02:10 -08:00
|
|
|
load(data)
|
2010-02-27 13:39:33 -08:00
|
|
|
end
|
|
|
|
|
2013-03-07 16:01:42 -06:00
|
|
|
# Retrieves directory
|
|
|
|
# @param [String] key of directory
|
|
|
|
# @param options [Hash]:
|
|
|
|
# @option options [String] cdn_cname CDN CNAME used when calling Directory#public_url
|
2013-03-11 10:05:23 -05:00
|
|
|
# @return [Fog::Storage::Rackspace::Directory]
|
2013-04-15 13:12:14 -05:00
|
|
|
# @raise [Fog::Storage::Rackspace::NotFound] - HTTP 404
|
|
|
|
# @raise [Fog::Storage::Rackspace::BadRequest] - HTTP 400
|
|
|
|
# @raise [Fog::Storage::Rackspace::InternalServerError] - HTTP 500
|
|
|
|
# @raise [Fog::Storage::Rackspace::ServiceError]
|
2013-03-07 16:01:42 -06:00
|
|
|
# @example
|
2013-03-11 10:05:23 -05:00
|
|
|
# directory = fog.directories.get('video', :cdn_cname => 'http://cdn.lunenburg.org')
|
|
|
|
# files = directory.files
|
|
|
|
# files.first.public_url
|
2011-06-16 16:22:37 -04:00
|
|
|
#
|
2013-03-07 16:01:42 -06:00
|
|
|
# @see Directory#public_url
|
|
|
|
# @see http://docs.rackspace.com/files/api/v1/cf-devguide/content/View-Container_Info-d1e1285.html
|
2010-05-02 19:59:15 -07:00
|
|
|
def get(key, options = {})
|
2012-12-22 23:24:03 +00:00
|
|
|
data = service.get_container(key, options)
|
2011-06-16 16:22:37 -04:00
|
|
|
directory = new(:key => key, :cdn_cname => options[:cdn_cname])
|
2010-10-18 11:09:19 -07: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
|
2014-02-19 12:30:59 +00:00
|
|
|
|
2013-02-13 14:23:55 -06:00
|
|
|
directory.metadata = Metadata.from_headers(directory, data.headers)
|
2010-02-27 13:39:33 -08:00
|
|
|
directory.files.merge_attributes(options)
|
|
|
|
directory.files.instance_variable_set(:@loaded, true)
|
2014-02-19 12:30:59 +00:00
|
|
|
|
2010-10-18 11:09:19 -07:00
|
|
|
data.body.each do |file|
|
2010-02-27 13:39:33 -08:00
|
|
|
directory.files << directory.files.new(file)
|
|
|
|
end
|
|
|
|
directory
|
2011-06-15 14:26:43 -07:00
|
|
|
rescue Fog::Storage::Rackspace::NotFound
|
2010-02-27 13:39:33 -08:00
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|