Class: Azure::Core::Http::HttpResponse
- Inherits:
-
Object
- Object
- Azure::Core::Http::HttpResponse
- Defined in:
- lib/azure/core/http/http_response.rb
Overview
A small proxy to clean up the API of Net::HTTPResponse.
Defined Under Namespace
Classes: MockResponse
Instance Attribute Summary collapse
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
-
#body ⇒ Object
Public: Get the response body.
-
#exception ⇒ Object
(also: #error)
Public: Get an error that wraps this HTTP response, as long as this response was unsuccessful.
-
#headers ⇒ Object
Public: Get all the response headers as a Hash.
-
#initialize(http_response, uri = '') ⇒ HttpResponse
constructor
Public: Initialize a new response.
-
#reason_phrase ⇒ Object
Public: Get the response reason phrase.
-
#status_code ⇒ Object
Public: Get the response status code.
-
#success? ⇒ Boolean
Public: Check if this response was successful.
Constructor Details
#initialize(http_response, uri = '') ⇒ HttpResponse
Public: Initialize a new response.
http_response - A Net::HTTPResponse.
25 26 27 28 |
# File 'lib/azure/core/http/http_response.rb', line 25 def initialize(http_response, uri='') @http_response = http_response @uri = uri end |
Instance Attribute Details
#uri ⇒ Object
Returns the value of attribute uri.
30 31 32 |
# File 'lib/azure/core/http/http_response.rb', line 30 def uri @uri end |
Instance Method Details
#body ⇒ Object
Public: Get the response body.
Returns a String.
35 36 37 |
# File 'lib/azure/core/http/http_response.rb', line 35 def body @http_response.body end |
#exception ⇒ Object Also known as: error
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.
73 74 75 |
# File 'lib/azure/core/http/http_response.rb', line 73 def exception HTTPError.new(self) unless success? end |
#headers ⇒ Object
Public: Get all the response headers as a Hash.
Returns a Hash.
64 65 66 |
# File 'lib/azure/core/http/http_response.rb', line 64 def headers @http_response.headers end |
#reason_phrase ⇒ Object
Public: Get the response reason phrase.
Returns a String.
49 50 51 |
# File 'lib/azure/core/http/http_response.rb', line 49 def reason_phrase @http_response.reason_phrase end |
#status_code ⇒ Object
Public: Get the response status code.
Returns a Fixnum.
42 43 44 |
# File 'lib/azure/core/http/http_response.rb', line 42 def status_code @http_response.status end |
#success? ⇒ Boolean
Public: Check if this response was successful. A request is considered successful if the response is in the 200 - 399 range.
Returns nil|false.
57 58 59 |
# File 'lib/azure/core/http/http_response.rb', line 57 def success? @http_response.success? end |