allow use of optional params for s3 get/head object

This commit is contained in:
Wesley Beary 2009-07-22 09:38:06 -07:00
parent d1ba2b8d15
commit da0d4b79b2
2 changed files with 34 additions and 6 deletions

View File

@ -7,7 +7,12 @@ module Fog
# ==== Parameters # ==== Parameters
# * bucket_name<~String> - Name of bucket to read from # * bucket_name<~String> - Name of bucket to read from
# * object_name<~String> - Name of object to read # * object_name<~String> - Name of object to read
# # * options<~Hash>:
# * :if_match<~String> - Returns object only if its etag matches this value, otherwise returns 412 (Precondition Failed).
# * :if_modified_since<~Time> - Returns object only if it has been modified since this time, otherwise returns 304 (Not Modified).
# * :if_none_match<~String> - Returns object only if its etag differs from this value, otherwise returns 304 (Not Modified)
# * :if_unmodified_since<~Time> - Returns object only if it has not been modified since this time, otherwise returns 412 (Precodition Failed).
# * :range<~String> - Range of object to download
# ==== Returns # ==== Returns
# * response<~Fog::AWS::Response>: # * response<~Fog::AWS::Response>:
# * body<~String> - Contents of object # * body<~String> - Contents of object
@ -16,11 +21,17 @@ module Fog
# * 'Content-Type'<~String> - MIME type of object # * 'Content-Type'<~String> - MIME type of object
# * 'ETag'<~String> - Etag of object # * 'ETag'<~String> - Etag of object
# * 'Last-Modified'<~String> - Last modified timestamp for object # * 'Last-Modified'<~String> - Last modified timestamp for object
# FIXME: optional params def get_object(bucket_name, object_name, options = {})
def get_object(bucket_name, object_name) headers = {}
headers['If-Match'] = options[:if_match] if options[:if_match]
headers['If-Modified-Since'] = options[:if_modified_since].utc.strftime("%a, %d %b %Y %H:%M:%S +0000") if options[:if_modified_since]
headers['If-None-Match'] = options[:if_none_match] if options[:if_none_match]
headers['If-Unmodified-Since'] = options[:if_unmodified_since].utc.strftime("%a, %d %b %Y %H:%M:%S +0000") if options[:if_unmodified_since]
headers[:range] = options[:range] if options[:range]
request({ request({
:expects => 200, :expects => 200,
:headers => {}, :headers => headers,
:host => "#{bucket_name}.#{@host}", :host => "#{bucket_name}.#{@host}",
:method => 'GET', :method => 'GET',
:path => object_name :path => object_name

View File

@ -4,6 +4,16 @@ module Fog
# Get headers for an object from S3 # Get headers for an object from S3
# #
# ==== Parameters
# * bucket_name<~String> - Name of bucket to read from
# * object_name<~String> - Name of object to read
# * options<~Hash>:
# * :if_match<~String> - Returns object only if its etag matches this value, otherwise returns 412 (Precondition Failed).
# * :if_modified_since<~Time> - Returns object only if it has been modified since this time, otherwise returns 304 (Not Modified).
# * :if_none_match<~String> - Returns object only if its etag differs from this value, otherwise returns 304 (Not Modified)
# * :if_unmodified_since<~Time> - Returns object only if it has not been modified since this time, otherwise returns 412 (Precodition Failed).
# * :range<~String> - Range of object to download
#
# ==== Returns # ==== Returns
# * response<~Fog::AWS::Response>: # * response<~Fog::AWS::Response>:
# * body<~String> - Contents of object # * body<~String> - Contents of object
@ -12,10 +22,17 @@ module Fog
# * 'Content-Type'<~String> - MIME type of object # * 'Content-Type'<~String> - MIME type of object
# * 'ETag'<~String> - Etag of object # * 'ETag'<~String> - Etag of object
# * 'Last-Modified'<~String> - Last modified timestamp for object # * 'Last-Modified'<~String> - Last modified timestamp for object
def head_object(bucket_name, object_name) def head_object(bucket_name, object_name, options={})
headers = {}
headers['If-Match'] = options[:if_match] if options[:if_match]
headers['If-Modified-Since'] = options[:if_modified_since].utc.strftime("%a, %d %b %Y %H:%M:%S +0000") if options[:if_modified_since]
headers['If-None-Match'] = options[:if_none_match] if options[:if_none_match]
headers['If-Unmodified-Since'] = options[:if_unmodified_since].utc.strftime("%a, %d %b %Y %H:%M:%S +0000") if options[:if_unmodified_since]
headers[:range] = options[:range] if options[:range]
request({ request({
:expects => 200, :expects => 200,
:headers => {}, :headers => headers,
:host => "#{bucket_name}.#{@host}", :host => "#{bucket_name}.#{@host}",
:method => 'HEAD', :method => 'HEAD',
:path => object_name :path => object_name