mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
allow use of optional params for s3 get/head object
This commit is contained in:
parent
d1ba2b8d15
commit
da0d4b79b2
2 changed files with 34 additions and 6 deletions
|
@ -7,7 +7,12 @@ module Fog
|
|||
# ==== 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
|
||||
# * response<~Fog::AWS::Response>:
|
||||
# * body<~String> - Contents of object
|
||||
|
@ -16,11 +21,17 @@ module Fog
|
|||
# * 'Content-Type'<~String> - MIME type of object
|
||||
# * 'ETag'<~String> - Etag of object
|
||||
# * 'Last-Modified'<~String> - Last modified timestamp for object
|
||||
# FIXME: optional params
|
||||
def get_object(bucket_name, object_name)
|
||||
def get_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({
|
||||
:expects => 200,
|
||||
:headers => {},
|
||||
:headers => headers,
|
||||
:host => "#{bucket_name}.#{@host}",
|
||||
:method => 'GET',
|
||||
:path => object_name
|
||||
|
|
|
@ -4,6 +4,16 @@ module Fog
|
|||
|
||||
# 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
|
||||
# * response<~Fog::AWS::Response>:
|
||||
# * body<~String> - Contents of object
|
||||
|
@ -12,10 +22,17 @@ module Fog
|
|||
# * 'Content-Type'<~String> - MIME type of object
|
||||
# * 'ETag'<~String> - Etag of 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({
|
||||
:expects => 200,
|
||||
:headers => {},
|
||||
:headers => headers,
|
||||
:host => "#{bucket_name}.#{@host}",
|
||||
:method => 'HEAD',
|
||||
:path => object_name
|
||||
|
|
Loading…
Reference in a new issue