2010-03-19 21:29:42 -04:00
|
|
|
require 'fog/model'
|
|
|
|
|
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-09-07 14:30:02 -04:00
|
|
|
identity :key, :aliases => 'Key'
|
2010-02-27 16:39:33 -05:00
|
|
|
|
2010-03-11 10:48:12 -05:00
|
|
|
attr_accessor :body
|
2010-09-07 14:30:02 -04:00
|
|
|
attribute :content_length, :aliases => 'Content-Length'
|
|
|
|
attribute :content_type, :aliases => 'Content-Type'
|
|
|
|
attribute :etag, :aliases => 'Etag'
|
|
|
|
attribute :last_modified, :aliases => '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
|
|
|
|
connection.delete_object(directory.name, @key)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def owner=(new_owner)
|
|
|
|
if new_owner
|
|
|
|
@owner = {
|
|
|
|
:display_name => new_owner['DisplayName'],
|
|
|
|
:id => new_owner['ID']
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-07-17 18:19:15 -04:00
|
|
|
def save
|
2010-02-27 16:39:33 -05:00
|
|
|
requires :body, :directory, :key
|
2010-07-17 18:19:15 -04:00
|
|
|
data = connection.put_object(directory.name, @key, @body)
|
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
|