2009-08-02 19:37:54 -04:00
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
class S3
|
|
|
|
|
|
|
|
class Objects < Fog::Collection
|
|
|
|
|
2009-08-17 20:09:08 -04:00
|
|
|
attr_accessor :is_truncated,
|
2009-08-17 20:06:25 -04:00
|
|
|
:marker,
|
|
|
|
:max_keys,
|
|
|
|
:prefix
|
2009-08-04 13:51:54 -04:00
|
|
|
|
|
|
|
def initialize(attributes = {})
|
|
|
|
remap_attributes(attributes, {
|
|
|
|
'IsTruncated' => :is_truncated,
|
2009-08-17 21:07:46 -04:00
|
|
|
'Marker' => :marker,
|
|
|
|
'MaxKeys' => :max_keys,
|
|
|
|
'Prefix' => :prefix
|
2009-08-04 13:51:54 -04:00
|
|
|
})
|
|
|
|
super
|
|
|
|
end
|
2009-08-02 19:37:54 -04:00
|
|
|
|
2009-08-17 20:32:02 -04:00
|
|
|
def all(options = {})
|
2009-08-06 01:55:09 -04:00
|
|
|
data = connection.get_bucket(bucket.name, options).body
|
|
|
|
objects_data = {}
|
|
|
|
for key, value in data
|
|
|
|
if ['IsTruncated', 'Marker', 'MaxKeys', 'Prefix'].include?(key)
|
|
|
|
objects_data[key] = value
|
2009-08-04 23:09:08 -04:00
|
|
|
end
|
|
|
|
end
|
2009-08-06 01:55:09 -04:00
|
|
|
objects = Fog::AWS::S3::Objects.new({
|
|
|
|
:bucket => bucket,
|
|
|
|
:connection => connection
|
|
|
|
}.merge!(objects_data))
|
|
|
|
data['Contents'].each do |object|
|
|
|
|
owner = Fog::AWS::S3::Owner.new(object.delete('Owner').merge!(:connection => connection))
|
2009-08-13 01:48:17 -04:00
|
|
|
objects << Fog::AWS::S3::Object.new({
|
2009-08-19 00:26:13 -04:00
|
|
|
:bucket => bucket,
|
|
|
|
:connection => connection,
|
|
|
|
:owner => owner
|
2009-08-06 01:55:09 -04:00
|
|
|
}.merge!(object))
|
|
|
|
end
|
|
|
|
objects
|
2009-08-04 23:09:08 -04:00
|
|
|
end
|
|
|
|
|
2009-08-27 23:47:01 -04:00
|
|
|
def bucket
|
|
|
|
@bucket
|
|
|
|
end
|
|
|
|
|
2009-08-06 01:55:09 -04:00
|
|
|
def create(attributes = {})
|
|
|
|
object = new(attributes)
|
|
|
|
object.save
|
|
|
|
object
|
2009-08-04 23:09:08 -04:00
|
|
|
end
|
|
|
|
|
2009-08-19 00:26:13 -04:00
|
|
|
def get
|
|
|
|
data = connection.get_object(bucket.name, key, options)
|
|
|
|
object_data = { :body => data.body}
|
|
|
|
for key, value in data.headers
|
|
|
|
if ['Content-Length', 'Content-Type', 'ETag', 'Last-Modified'].include?(key)
|
|
|
|
object_data[key] = value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
Fog::AWS::S3::Object.new({
|
|
|
|
:bucket => bucket,
|
|
|
|
:connection => connection
|
|
|
|
}.merge!(object_data))
|
|
|
|
end
|
|
|
|
|
|
|
|
def head
|
|
|
|
data = connection.head_object(bucket.name, key, options)
|
|
|
|
object_data = {}
|
|
|
|
for key, value in data.headers
|
|
|
|
if ['Content-Length', 'Content-Type', 'ETag', 'Last-Modified'].include?(key)
|
|
|
|
object_data[key] = value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
Fog::AWS::S3::Object.new({
|
|
|
|
:bucket => bucket,
|
|
|
|
:connection => connection
|
|
|
|
}.merge!(object_data))
|
|
|
|
end
|
|
|
|
|
2009-08-04 23:09:08 -04:00
|
|
|
def new(attributes = {})
|
2009-08-17 20:06:25 -04:00
|
|
|
Fog::AWS::S3::Object.new({
|
|
|
|
:bucket => bucket,
|
|
|
|
:connection => connection
|
|
|
|
}.merge!(attributes))
|
2009-08-04 23:09:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def bucket=(new_bucket)
|
|
|
|
@bucket = new_bucket
|
|
|
|
end
|
|
|
|
|
2009-08-02 19:37:54 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|