2010-10-04 17:02:08 -04:00
|
|
|
require 'fog/core/collection'
|
2010-09-08 17:40:02 -04:00
|
|
|
require 'fog/aws/models/storage/file'
|
2010-03-13 16:37:24 -05:00
|
|
|
|
2009-08-02 19:37:54 -04:00
|
|
|
module Fog
|
|
|
|
module AWS
|
2010-09-08 17:40:02 -04:00
|
|
|
class Storage
|
2010-09-02 19:01:19 -04:00
|
|
|
|
2010-01-14 23:44:39 -05:00
|
|
|
class Files < Fog::Collection
|
2009-08-02 19:37:54 -04:00
|
|
|
|
2010-09-07 14:30:02 -04:00
|
|
|
attribute :delimiter, :aliases => 'Delimiter'
|
2010-04-26 20:04:47 -04:00
|
|
|
attribute :directory
|
2010-09-07 14:30:02 -04:00
|
|
|
attribute :is_truncated, :aliases => 'IsTruncated'
|
|
|
|
attribute :marker, :aliases => 'Marker'
|
|
|
|
attribute :max_keys, :aliases => ['MaxKeys', 'max-keys']
|
|
|
|
attribute :prefix, :aliases => 'Prefix'
|
2009-08-04 13:51:54 -04:00
|
|
|
|
2010-09-08 17:40:02 -04:00
|
|
|
model Fog::AWS::Storage::File
|
2009-10-30 02:35:28 -04:00
|
|
|
|
2009-08-29 14:20:54 -04:00
|
|
|
def all(options = {})
|
2010-09-02 19:01:19 -04:00
|
|
|
requires :directory
|
2010-03-31 00:04:27 -04:00
|
|
|
options = {
|
|
|
|
'delimiter' => @delimiter,
|
|
|
|
'marker' => @marker,
|
|
|
|
'max-keys' => @max_keys,
|
|
|
|
'prefix' => @prefix
|
|
|
|
}.merge!(options)
|
|
|
|
options = options.reject {|key,value| value.nil? || value.to_s.empty?}
|
2010-01-05 01:03:24 -05:00
|
|
|
merge_attributes(options)
|
2010-03-08 19:19:48 -05:00
|
|
|
parent = directory.collection.get(
|
2010-05-03 18:02:08 -04:00
|
|
|
directory.key,
|
2009-12-24 19:10:14 -05:00
|
|
|
options
|
2009-12-14 13:28:43 -05:00
|
|
|
)
|
2010-03-08 19:19:48 -05:00
|
|
|
if parent
|
2010-08-18 15:23:42 -04:00
|
|
|
merge_attributes(parent.files.attributes)
|
2010-03-08 19:19:48 -05:00
|
|
|
load(parent.files.map {|file| file.attributes})
|
2010-01-05 01:03:24 -05:00
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
2009-08-04 23:09:08 -04:00
|
|
|
end
|
|
|
|
|
2009-09-10 14:30:50 -04:00
|
|
|
def get(key, options = {}, &block)
|
2010-09-02 19:01:19 -04:00
|
|
|
requires :directory
|
2010-05-03 18:02:08 -04:00
|
|
|
data = connection.get_object(directory.key, key, options, &block)
|
2010-01-14 23:44:39 -05:00
|
|
|
file_data = {
|
2009-09-02 23:17:53 -04:00
|
|
|
:body => data.body,
|
|
|
|
:key => key
|
|
|
|
}
|
2009-09-02 00:41:52 -04:00
|
|
|
for key, value in data.headers
|
2010-11-08 20:14:21 -05:00
|
|
|
if model.aliases.include?(key)
|
2010-01-14 23:44:39 -05:00
|
|
|
file_data[key] = value
|
2009-08-19 00:26:13 -04:00
|
|
|
end
|
|
|
|
end
|
2010-01-14 23:44:39 -05:00
|
|
|
new(file_data)
|
2009-11-08 15:16:52 -05:00
|
|
|
rescue Excon::Errors::NotFound
|
2009-09-02 00:41:52 -04:00
|
|
|
nil
|
2009-08-19 00:26:13 -04:00
|
|
|
end
|
|
|
|
|
2009-10-03 18:43:19 -04:00
|
|
|
def get_url(key, expires)
|
2010-09-02 19:01:19 -04:00
|
|
|
requires :directory
|
2010-05-03 18:02:08 -04:00
|
|
|
connection.get_object_url(directory.key, key, expires)
|
2009-10-03 18:43:19 -04:00
|
|
|
end
|
|
|
|
|
2009-08-29 14:20:54 -04:00
|
|
|
def head(key, options = {})
|
2010-09-02 19:01:19 -04:00
|
|
|
requires :directory
|
2010-05-03 18:02:08 -04:00
|
|
|
data = connection.head_object(directory.key, key, options)
|
2010-01-14 23:44:39 -05:00
|
|
|
file_data = {
|
2009-09-02 23:17:53 -04:00
|
|
|
:key => key
|
|
|
|
}
|
|
|
|
for key, value in data.headers
|
2010-11-08 20:14:21 -05:00
|
|
|
if model.aliases.include?(key)
|
2010-01-14 23:44:39 -05:00
|
|
|
file_data[key] = value
|
2009-08-19 00:26:13 -04:00
|
|
|
end
|
|
|
|
end
|
2010-01-14 23:44:39 -05:00
|
|
|
new(file_data)
|
2009-11-08 15:16:52 -05:00
|
|
|
rescue Excon::Errors::NotFound
|
2009-09-02 23:17:53 -04:00
|
|
|
nil
|
2009-08-19 00:26:13 -04:00
|
|
|
end
|
|
|
|
|
2009-08-04 23:09:08 -04:00
|
|
|
def new(attributes = {})
|
2010-09-02 19:01:19 -04:00
|
|
|
requires :directory
|
2010-01-14 23:44:39 -05:00
|
|
|
super({ :directory => directory }.merge!(attributes))
|
2009-09-02 00:41:52 -04:00
|
|
|
end
|
|
|
|
|
2009-08-02 19:37:54 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|