1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/aws/models/s3/objects.rb

101 lines
2.7 KiB
Ruby
Raw Normal View History

2009-08-02 19:37:54 -04:00
module Fog
module AWS
class S3
class Objects < Fog::Collection
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 = {})
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
end
end
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({
:bucket => bucket,
:connection => connection,
:owner => owner
}.merge!(object))
end
objects
end
def bucket
@bucket
end
def create(attributes = {})
object = new(attributes)
object.save
object
end
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
def new(attributes = {})
2009-08-17 20:06:25 -04:00
Fog::AWS::S3::Object.new({
:bucket => bucket,
:connection => connection
}.merge!(attributes))
end
private
def bucket=(new_bucket)
@bucket = new_bucket
end
2009-08-02 19:37:54 -04:00
end
end
end
end