class Azure::Core::Http::HttpResponse
A small proxy to clean up the API of Net::HTTPResponse.
Attributes
uri[RW]
Public Class Methods
new(http_response, uri="")
click to toggle source
Public: Initialize a new response.
http_response - A Net::HTTPResponse.
# File lib/azure/core/http/http_response.rb, line 26 def initialize(http_response, uri="") @http_response = http_response @uri = uri end
Public Instance Methods
body()
click to toggle source
Public: Get the response body.
Returns a String
.
# File lib/azure/core/http/http_response.rb, line 36 def body @http_response.body end
exception()
click to toggle source
Public: Get an error that wraps this HTTP response, as long as this response was unsuccessful. This method will return nil if the response was successful.
Returns an Azure::Core::Http::HTTPError
.
# File lib/azure/core/http/http_response.rb, line 74 def exception HTTPError.new(self) unless success? end
Also aliased as: error
headers()
click to toggle source
Public: Get all the response headers as a Hash.
Returns a Hash.
# File lib/azure/core/http/http_response.rb, line 65 def headers @headers ||= HeaderHash.new(@http_response.to_hash) end
message()
click to toggle source
Public: Get the response status message.
Returns a String
.
# File lib/azure/core/http/http_response.rb, line 43 def message @http_response.message end
status_code()
click to toggle source
Public: Get the response status code.
Returns a Fixnum.
# File lib/azure/core/http/http_response.rb, line 50 def status_code @http_response.code.to_i end
success?()
click to toggle source
Public: Check if this response was successful. A request is considered successful if the response is in the 200 - 399 range.
Returns nil|false.
# File lib/azure/core/http/http_response.rb, line 58 def success? (200..399).include? status_code end