2009-08-02 16:37:54 -07:00
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
class S3
|
|
|
|
|
|
|
|
class Object < Fog::Model
|
|
|
|
|
2009-08-14 09:19:40 -07:00
|
|
|
attr_accessor :body,
|
2009-08-28 09:03:19 -07:00
|
|
|
:content_length,
|
|
|
|
:content_type,
|
|
|
|
:etag,
|
|
|
|
:key,
|
|
|
|
:last_modified,
|
|
|
|
:owner,
|
|
|
|
:size,
|
|
|
|
:storage_class
|
2009-08-02 16:37:54 -07:00
|
|
|
|
2009-08-04 10:51:54 -07:00
|
|
|
def initialize(attributes = {})
|
|
|
|
remap_attributes(attributes, {
|
2009-08-04 20:09:08 -07:00
|
|
|
'Content-Length' => :content_length,
|
|
|
|
'ETag' => :etag,
|
|
|
|
'Key' => :key,
|
|
|
|
'LastModified' => :last_modified,
|
|
|
|
'Last-Modified' => :last_modified,
|
|
|
|
'Size' => :size,
|
|
|
|
'StorageClass' => :storage_class
|
2009-08-04 10:51:54 -07:00
|
|
|
})
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2009-08-27 20:47:01 -07:00
|
|
|
def bucket
|
|
|
|
@bucket
|
|
|
|
end
|
|
|
|
|
2009-08-04 20:09:08 -07:00
|
|
|
def copy(target_bucket_name, target_object_key)
|
2009-08-17 17:21:43 -07:00
|
|
|
data = connection.copy_object(bucket.name, key, target_bucket_name, target_object_key).body
|
2009-08-04 20:09:08 -07:00
|
|
|
copy = self.dup
|
|
|
|
copy_data = {}
|
|
|
|
for key, value in data
|
|
|
|
if ['ETag', 'LastModified'].include?(key)
|
|
|
|
copy_data[key] = value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
copy.update_attributes(copy_data)
|
|
|
|
copy
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete
|
|
|
|
connection.delete_object(bucket, key)
|
2009-08-27 20:47:01 -07:00
|
|
|
true
|
2009-08-04 20:09:08 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def save(options = {})
|
2009-08-17 17:21:43 -07:00
|
|
|
data = connection.put_object(bucket.name, key, body, options)
|
2009-08-04 20:09:08 -07:00
|
|
|
@etag = data.headers['ETag']
|
2009-08-27 20:47:01 -07:00
|
|
|
true
|
2009-08-04 20:09:08 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def bucket=(new_bucket)
|
|
|
|
@bucket = new_bucket
|
|
|
|
end
|
|
|
|
|
2009-08-28 09:03:19 -07:00
|
|
|
def objects
|
|
|
|
@objects
|
|
|
|
end
|
|
|
|
|
|
|
|
def objects=(new_objects)
|
|
|
|
@objects = new_objects
|
|
|
|
end
|
|
|
|
|
2009-08-02 16:37:54 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|