README.rdoc in rest-client-1.5.1 vs README.rdoc in rest-client-1.6.0.a

- old
+ new

@@ -11,12 +11,14 @@ require 'rest_client' RestClient.get 'http://example.com/resource' - RestClient.get 'https://user:password@example.com/private/resource' + RestClient.get 'http://example.com/resource', {:params => {:id => 50, 'foo' => 'bar'}} + RestClient.get 'https://user:password@example.com/private/resource', {:accept => :json} + RestClient.post 'http://example.com/resource', :param1 => 'one', :nested => { :param2 => 'two' } RestClient.post "http://example.com/resource", { 'x' => 1 }.to_json, :content_type => :json, :accept => :json RestClient.delete 'http://example.com/resource' @@ -75,12 +77,12 @@ See RestClient::Resource docs for details. == Exceptions (see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html) -* for results code between 200 and 206 a RestClient::Response will be returned -* for results code 301 and 302 the redirection will be followed if the request is a get or a head +* for results code between 200 and 207 a RestClient::Response will be returned +* for results code 301, 302 or 307 the redirection will be followed if the request is a get or a head * for result code 303 the redirection will be followed and the request transformed into a get * for other cases a RestClient::Exception holding the Response will be raised, a specific exception class will be thrown for know error codes RestClient.get 'http://example.com/resource' ➔ RestClient::ResourceNotFound: RestClient::ResourceNotFound @@ -96,34 +98,34 @@ A block can be passed to the RestClient method, this block will then be called with the Response. Response.return! can be called to invoke the default response's behavior. # Don't raise exceptions but return the response - RestClient.get('http://example.com/resource'){|response| response } + RestClient.get('http://example.com/resource'){|response, request| response } ➔ 404 Resource Not Found | text/html 282 bytes # Manage a specific error code - RestClient.get('http://my-rest-service.com/resource'){ |response, &block| + RestClient.get('http://my-rest-service.com/resource'){ |response, request, &block| case response.code when 200 p "It worked !" response when 423 raise SomeCustomExceptionIfYouWant else - response.return! &block + response.return!(request, &block) end } # Follow redirections for all request types and not only for get and head - # RFC : "If the 301 (or 302) status code is received in response to a request other than GET or HEAD, + # RFC : "If the 301, 302 or 307 status code is received in response to a request other than GET or HEAD, # the user agent MUST NOT automatically redirect the request unless it can be confirmed by the user, # since this might change the conditions under which the request was issued." - RestClient.get('http://my-rest-service.com/resource'){ |response, &block| - if [301, 302].include? response.code - response.follow_redirection &block + RestClient.get('http://my-rest-service.com/resource'){ |response, request, &block| + if [301, 302, 307].include? response.code + response.follow_redirection(request, &block) else - response.return! &block + response.return!(request, &block) end } == Non-normalized URIs.