Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add the ability to retrieve object metadata using a #metadata method …

…on an object
  • Loading branch information...
commit 5197b3c2d15ecddc862bd09c2b65e3636169e8e9 1 parent 26a8353
@scsmith scsmith authored
Showing with 11 additions and 1 deletion.
  1. +2 −1  lib/s3/object.rb
  2. +9 −0 test/object_test.rb
View
3  lib/s3/object.rb
@@ -6,7 +6,7 @@ class Object
extend Forwardable
attr_accessor :content_type, :content_disposition, :content_encoding, :cache_control
- attr_reader :last_modified, :etag, :size, :bucket, :key, :acl, :storage_class
+ attr_reader :last_modified, :etag, :size, :bucket, :key, :acl, :storage_class, :metadata
attr_writer :content
def_instance_delegators :bucket, :name, :service, :bucket_request, :vhost?, :host, :path_prefix
@@ -235,6 +235,7 @@ def dump_headers
end
def parse_headers(response)
+ @metadata = response.to_hash.select{|k,v| k.to_s.start_with?('x-amz-meta') }
self.etag = response["etag"] if response.key?("etag")
self.content_type = response["content-type"] if response.key?("content-type")
self.content_disposition = response["content-disposition"] if response.key?("content-disposition")
View
9 test/object_test.rb
@@ -22,6 +22,7 @@ def setup
@response_binary["content-encoding"] = nil
@response_binary["last-modified"] = Time.now.httpdate
@response_binary["content-length"] = 20
+ @response_binary["x-amz-meta-test"] = 'metadata'
@xml_body = <<-EOXML
<?xml version="1.0" encoding="UTF-8"?>
@@ -132,6 +133,14 @@ def setup
assert @object_lena.retrieve
end
+ test "retrieve headers" do
+ @object_lena.expects(:object_request).twice.with(:head, {}).returns(@response_binary)
+ assert @object_lena.retrieve
+
+ meta = {"x-amz-meta-test"=>["metadata"]}
+ assert_equal meta, @object_lena.retrieve.metadata
+ end
+
test "exists" do
@object_lena.expects(:retrieve).returns(true)
assert @object_lena.exists?
Please sign in to comment.
Something went wrong with that request. Please try again.