2011-07-10 09:44:35 -04:00
|
|
|
require 'fog/core/collection'
|
2011-08-24 15:07:16 -04:00
|
|
|
require 'fog/ninefold/models/storage/file'
|
2011-07-10 09:44:35 -04:00
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Storage
|
|
|
|
class Ninefold
|
|
|
|
|
|
|
|
class Files < Fog::Collection
|
|
|
|
|
|
|
|
attribute :directory
|
|
|
|
attribute :limit
|
|
|
|
attribute :marker
|
|
|
|
attribute :path
|
|
|
|
attribute :prefix
|
|
|
|
|
|
|
|
model Fog::Storage::Ninefold::File
|
|
|
|
|
2011-11-02 00:39:43 -04:00
|
|
|
def all(options = { })
|
2011-07-10 09:44:35 -04:00
|
|
|
requires :directory
|
|
|
|
directory ? ns = directory.key : ns = ''
|
|
|
|
ns = ns + '/' unless ns =~ /\/$/
|
|
|
|
data = connection.get_namespace(ns).body[:DirectoryList]
|
2011-11-02 00:39:43 -04:00
|
|
|
data = { :DirectoryEntry => [] } if data.kind_of? String
|
2011-07-10 09:44:35 -04:00
|
|
|
data[:DirectoryEntry] = [data[:DirectoryEntry]] if data[:DirectoryEntry].kind_of? Hash
|
2011-11-02 00:39:43 -04:00
|
|
|
files = data[:DirectoryEntry].select { |de| de[:FileType] == 'regular' }
|
2011-07-10 09:44:35 -04:00
|
|
|
files.each do |s|
|
|
|
|
s[:directory] = directory
|
|
|
|
end
|
|
|
|
# TODO - Load additional file meta?
|
|
|
|
load(files)
|
|
|
|
end
|
|
|
|
|
|
|
|
def get(key, &block)
|
|
|
|
requires :directory
|
2011-11-02 00:39:43 -04:00
|
|
|
data = connection.get_namespace(directory.key + key, :parse => false) #, &block)
|
2011-07-10 09:44:35 -04:00
|
|
|
file_data = data.headers.merge({
|
2011-11-02 00:39:43 -04:00
|
|
|
:body => data.body,
|
|
|
|
:key => key
|
2011-07-10 09:44:35 -04:00
|
|
|
})
|
|
|
|
new(file_data)
|
|
|
|
rescue Fog::Storage::Ninefold::NotFound
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_url(key)
|
|
|
|
requires :directory
|
|
|
|
if self.directory.public_url
|
|
|
|
"#{self.directory.public_url}/#{key}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-11-02 00:39:43 -04:00
|
|
|
def head(key, options = { })
|
2011-07-10 09:44:35 -04:00
|
|
|
requires :directory
|
2011-11-02 00:39:43 -04:00
|
|
|
data = connection.head_object(directory.key + key, :parse => false)
|
2011-07-10 09:44:35 -04:00
|
|
|
file_data = data.headers.merge({
|
2011-11-02 00:39:43 -04:00
|
|
|
:body => data.body,
|
|
|
|
:key => key
|
2011-07-10 09:44:35 -04:00
|
|
|
})
|
|
|
|
new(file_data)
|
2011-11-02 00:39:43 -04:00
|
|
|
rescue Fog::Storage::Ninefold::NotFound
|
2011-07-10 09:44:35 -04:00
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2011-11-02 00:39:43 -04:00
|
|
|
def new(attributes = { })
|
2011-07-10 09:44:35 -04:00
|
|
|
requires :directory
|
|
|
|
super({ :directory => directory }.merge!(attributes))
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|