2010-10-04 17:02:08 -04:00
|
|
|
require 'fog/core/model'
|
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-02-27 16:39:33 -05:00
|
|
|
|
|
|
|
class File < Fog::Model
|
|
|
|
|
2010-10-18 14:09:19 -04:00
|
|
|
identity :key, :aliases => 'name'
|
2010-02-27 16:39:33 -05:00
|
|
|
|
2010-10-12 21:07:36 -04:00
|
|
|
attr_writer :body
|
2010-10-18 14:09:19 -04:00
|
|
|
attribute :content_length, :aliases => ['bytes', 'Content-Length']
|
|
|
|
attribute :content_type, :aliases => ['content_type', 'Content-Type']
|
|
|
|
attribute :etag, :aliases => ['hash', 'Etag']
|
|
|
|
attribute :last_modified, :aliases => ['last_modified', 'Last-Modified']
|
2010-02-27 16:39:33 -05:00
|
|
|
|
|
|
|
def body
|
|
|
|
@body ||= if last_modified
|
|
|
|
collection.get(identity).body
|
|
|
|
else
|
|
|
|
''
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def directory
|
|
|
|
@directory
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
requires :directory, :key
|
2010-10-29 19:42:06 -04:00
|
|
|
connection.delete_object(directory.key, @key)
|
2010-02-27 16:39:33 -05:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def owner=(new_owner)
|
|
|
|
if new_owner
|
|
|
|
@owner = {
|
|
|
|
:display_name => new_owner['DisplayName'],
|
|
|
|
:id => new_owner['ID']
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-10-07 14:10:01 -04:00
|
|
|
def save(options = {})
|
2010-02-27 16:39:33 -05:00
|
|
|
requires :body, :directory, :key
|
2010-10-29 19:42:06 -04:00
|
|
|
data = connection.put_object(directory.key, @key, @body, options)
|
2010-02-27 16:39:33 -05:00
|
|
|
@etag = data.headers['ETag']
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def directory=(new_directory)
|
|
|
|
@directory = new_directory
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|