2010-10-04 17:02:08 -04:00
|
|
|
require 'fog/core/collection'
|
2010-09-08 17:00:43 -04:00
|
|
|
require 'fog/rackspace/models/storage/file'
|
2010-03-19 21:29:42 -04:00
|
|
|
|
2010-02-27 16:39:33 -05:00
|
|
|
module Fog
|
|
|
|
module Rackspace
|
2010-09-08 16:50:23 -04:00
|
|
|
class Storage
|
2010-09-02 19:01:19 -04:00
|
|
|
|
2010-02-27 16:39:33 -05:00
|
|
|
class Files < Fog::Collection
|
|
|
|
|
2010-09-02 19:01:19 -04:00
|
|
|
attribute :directory
|
2010-02-27 16:39:33 -05:00
|
|
|
attribute :limit
|
|
|
|
attribute :marker
|
|
|
|
attribute :path
|
|
|
|
attribute :prefix
|
|
|
|
|
2010-09-08 16:50:23 -04:00
|
|
|
model Fog::Rackspace::Storage::File
|
2010-02-27 16:39:33 -05:00
|
|
|
|
|
|
|
def all(options = {})
|
2010-09-02 19:01:19 -04:00
|
|
|
requires :directory
|
2010-11-04 14:12:44 -04:00
|
|
|
options = {
|
|
|
|
'limit' => @limit,
|
|
|
|
'marker' => @marker,
|
|
|
|
'path' => @path,
|
|
|
|
'prefix' => @prefix
|
|
|
|
}.merge!(options)
|
2010-02-27 16:39:33 -05:00
|
|
|
merge_attributes(options)
|
2010-03-08 19:19:48 -05:00
|
|
|
parent = directory.collection.get(
|
2010-07-17 17:42:05 -04:00
|
|
|
directory.key,
|
2010-02-27 16:39:33 -05:00
|
|
|
options
|
|
|
|
)
|
2010-03-08 19:19:48 -05:00
|
|
|
if parent
|
|
|
|
load(parent.files.map {|file| file.attributes})
|
2010-02-27 16:39:33 -05:00
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-11-04 14:12:44 -04:00
|
|
|
def get(key, &block)
|
2010-09-02 19:01:19 -04:00
|
|
|
requires :directory
|
2010-11-04 14:12:44 -04:00
|
|
|
data = connection.get_object(directory.key, key, &block)
|
2010-02-27 16:39:33 -05:00
|
|
|
file_data = {
|
|
|
|
:body => data.body,
|
|
|
|
:key => key
|
|
|
|
}
|
|
|
|
for key, value in data.headers
|
|
|
|
if ['Content-Length', 'Content-Type', 'ETag', 'Last-Modified'].include?(key)
|
|
|
|
file_data[key] = value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
new(file_data)
|
2010-09-08 16:50:23 -04:00
|
|
|
rescue Fog::Rackspace::Storage::NotFound
|
2010-02-27 16:39:33 -05:00
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_url(key, expires)
|
2010-09-02 19:01:19 -04:00
|
|
|
requires :directory
|
2010-02-27 16:39:33 -05:00
|
|
|
connection.get_object_url(directory.name, key, expires)
|
|
|
|
end
|
|
|
|
|
|
|
|
def head(key, options = {})
|
2010-09-02 19:01:19 -04:00
|
|
|
requires :directory
|
2010-02-27 16:39:33 -05:00
|
|
|
data = connection.head_object(directory.name, key, options)
|
|
|
|
file_data = { :key => key }
|
|
|
|
for key, value in data.headers
|
|
|
|
if ['Content-Length', 'Content-Type', 'ETag', 'Last-Modified'].include?(key)
|
|
|
|
file_data[key] = value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
new(file_data)
|
2010-09-08 16:50:23 -04:00
|
|
|
rescue Fog::Rackspace::Storage::NotFound
|
2010-02-27 16:39:33 -05:00
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def new(attributes = {})
|
2010-09-02 19:01:19 -04:00
|
|
|
requires :directory
|
2010-02-27 16:39:33 -05:00
|
|
|
super({ :directory => directory }.merge!(attributes))
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|