lib/s33r/client.rb in s33r-0.3 vs lib/s33r/client.rb in s33r-0.3.1
- old
+ new
@@ -7,12 +7,12 @@
# The client performs operations over the network,
# using the core to build request headers and content;
# only client-specific headers are managed here: other headers
# can be handled by the core.
#--
- # TODO: need to wrap XML returned into object representation.
# TODO: use customisable thread pool for requests.
+ # TODO: timeout on requests.
#--
class Client
include S33r
attr_accessor :aws_access_key, :aws_secret_access_key
@@ -92,12 +92,10 @@
# Send a request over the wire.
#
# This method streams +data+ if it responds to the +stat+ method
# (as files do).
- #
- #-- TODO: set timeout on requests in case S3 is unresponsive
def do_request(method, path, data=nil, headers={})
req = get_requester(method, path)
req.chunk_size = @chunk_size
# add the S3 headers which are always required
@@ -128,13 +126,14 @@
if @dump_requests
puts req.to_s
end
@client.start do
- return @client.request(req, data)
+ response = @client.request(req, data)
+ response.check_s3_availability
+ response
end
-
end
# Return an instance of an appropriate request class.
def get_requester(method, path)
raise S33rException::UnsupportedHTTPMethod, "The #{method} HTTP method is not supported" if !(METHOD_VERBS.include?(method))
@@ -195,12 +194,22 @@
# Returns true if bucket exists.
def bucket_exists?(bucket_name)
do_head("/#{bucket_name}").ok?
end
- # Fetch a resource and return a fleshed-out S3Object instance.
+ # Fetch head info for a key in a bucket.
+ def head_resource(bucket_name, resource_key, headers={})
+ do_head("/#{bucket_name}/#{resource_key}", headers)
+ end
+
+ # Fetch a resource.
def get_resource(bucket_name, resource_key, headers={})
do_get("/#{bucket_name}/#{resource_key}", headers)
+ end
+
+ # TODO: return S3Object
+ def get_object(bucket_name, resource_key, headers)
+ response = get_resource(bucket_name, resource_key, headers)
end
# Put some generic resource onto S3.
def put_resource(bucket_name, resource_key, data, headers={})
do_put("/#{bucket_name}/" + "#{CGI::escape(resource_key)}", data, headers)
\ No newline at end of file