2009-08-02 19:37:54 -04:00
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
class S3
|
|
|
|
|
|
|
|
class Objects < Fog::Collection
|
|
|
|
|
2009-09-21 14:40:16 -04:00
|
|
|
attribute :options
|
2009-08-04 13:51:54 -04:00
|
|
|
|
2009-08-29 14:20:54 -04:00
|
|
|
def all(options = {})
|
2009-09-21 14:40:16 -04:00
|
|
|
merge_attributes(:options => options)
|
|
|
|
bucket.buckets.get(bucket.name, @options).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-09-10 14:30:50 -04:00
|
|
|
def get(key, options = {}, &block)
|
|
|
|
data = connection.get_object(bucket.name, key, options, &block)
|
2009-09-02 23:17:53 -04:00
|
|
|
object_data = {
|
|
|
|
:body => data.body,
|
|
|
|
:key => key
|
|
|
|
}
|
2009-09-02 00:41:52 -04:00
|
|
|
for key, value in data.headers
|
|
|
|
if ['Content-Length', 'Content-Type', 'ETag', 'Last-Modified'].include?(key)
|
|
|
|
object_data[key] = value
|
2009-08-19 00:26:13 -04:00
|
|
|
end
|
|
|
|
end
|
2009-09-04 21:24:11 -04:00
|
|
|
object = Fog::AWS::S3::Object.new({
|
2009-09-02 00:41:52 -04:00
|
|
|
:bucket => bucket,
|
|
|
|
:connection => connection,
|
|
|
|
:objects => self
|
|
|
|
}.merge!(object_data))
|
2009-09-04 21:24:11 -04:00
|
|
|
object
|
2009-09-02 00:41:52 -04:00
|
|
|
rescue Fog::Errors::NotFound
|
|
|
|
nil
|
2009-08-19 00:26:13 -04:00
|
|
|
end
|
|
|
|
|
2009-10-03 18:43:19 -04:00
|
|
|
def get_url(key, expires)
|
|
|
|
connection.get_object_url(bucket.name, key, expires)
|
|
|
|
end
|
|
|
|
|
2009-08-29 14:20:54 -04:00
|
|
|
def head(key, options = {})
|
2009-09-02 23:17:53 -04:00
|
|
|
data = connection.head_object(bucket.name, key, options)
|
|
|
|
object_data = {
|
|
|
|
:key => key
|
|
|
|
}
|
|
|
|
for key, value in data.headers
|
2009-09-10 14:55:42 -04:00
|
|
|
if ['Content-Length', 'Content-Type', 'ETag', 'Last-Modified'].include?(key)
|
2009-09-02 23:17:53 -04:00
|
|
|
object_data[key] = value
|
2009-08-19 00:26:13 -04:00
|
|
|
end
|
|
|
|
end
|
2009-09-04 21:24:11 -04:00
|
|
|
object = Fog::AWS::S3::Object.new({
|
2009-09-02 23:17:53 -04:00
|
|
|
:bucket => bucket,
|
|
|
|
:connection => connection,
|
|
|
|
:objects => self
|
|
|
|
}.merge!(object_data))
|
2009-09-04 21:24:11 -04:00
|
|
|
object
|
2009-09-02 23:17:53 -04:00
|
|
|
rescue Fog::Errors::NotFound
|
|
|
|
nil
|
2009-08-19 00:26:13 -04:00
|
|
|
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,
|
2009-08-28 12:03:19 -04:00
|
|
|
:connection => connection,
|
|
|
|
:objects => self
|
2009-08-17 20:06:25 -04:00
|
|
|
}.merge!(attributes))
|
2009-08-04 23:09:08 -04:00
|
|
|
end
|
|
|
|
|
2009-09-02 00:41:52 -04:00
|
|
|
def reload
|
2009-09-21 14:40:16 -04:00
|
|
|
all(@options)
|
2009-09-02 00:41:52 -04:00
|
|
|
end
|
|
|
|
|
2009-08-04 23:09:08 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def bucket=(new_bucket)
|
|
|
|
@bucket = new_bucket
|
|
|
|
end
|
|
|
|
|
2009-08-02 19:37:54 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|