2012-10-19 01:33:20 -04:00
|
|
|
require 'fog/core/collection'
|
|
|
|
require 'fog/hp/models/storage/shared_file'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Storage
|
|
|
|
class HP
|
|
|
|
|
|
|
|
class SharedFiles < Fog::Collection
|
|
|
|
|
|
|
|
attribute :shared_directory
|
|
|
|
|
|
|
|
model Fog::Storage::HP::SharedFile
|
|
|
|
|
|
|
|
def all
|
|
|
|
requires :shared_directory
|
|
|
|
parent = shared_directory.collection.get(shared_directory.url)
|
|
|
|
if parent
|
|
|
|
load(parent.files.map {|file| file.attributes})
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
rescue Fog::Storage::HP::NotFound, Fog::HP::Errors::Forbidden
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def get(key, &block)
|
|
|
|
requires :shared_directory
|
|
|
|
shared_object_url = "#{shared_directory.url}/#{key}"
|
|
|
|
data = connection.get_shared_object(shared_object_url, &block)
|
|
|
|
file_data = data.headers.merge({
|
|
|
|
:body => data.body,
|
|
|
|
:key => key
|
|
|
|
})
|
|
|
|
new(file_data)
|
|
|
|
rescue Fog::Storage::HP::NotFound, Fog::HP::Errors::Forbidden
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def head(key)
|
|
|
|
requires :shared_directory
|
|
|
|
shared_object_url = "#{shared_directory.url}/#{key}"
|
|
|
|
data = connection.head_shared_object(shared_object_url)
|
|
|
|
file_data = data.headers.merge({
|
2012-10-24 18:53:38 -04:00
|
|
|
:body => '',
|
2012-10-19 01:33:20 -04:00
|
|
|
:key => key
|
|
|
|
})
|
|
|
|
new(file_data)
|
|
|
|
rescue Fog::Storage::HP::NotFound, Fog::HP::Errors::Forbidden
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def new(attributes = {})
|
|
|
|
requires :shared_directory
|
|
|
|
super({ :shared_directory => shared_directory }.merge!(attributes))
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|