Class: ServiceClient::Response
- Inherits:
-
Object
- Object
- ServiceClient::Response
- Includes:
- Errors
- Defined in:
- lib/service_client/response.rb
Overview
The Response class encapsulates the HTTP response received by the ServiceClient gem.
Constant Summary
Constants included from Errors
Instance Attribute Summary collapse
-
#code ⇒ Integer
readonly
The HTTP status code of the response.
-
#data ⇒ Hash, ...
readonly
The parsed body of the response.
-
#headers ⇒ Hash
readonly
The HTTP headers of the response.
Class Method Summary collapse
-
.call(response) ⇒ ServiceClient::Response
Initializes a new instance of Response and calls it to determine success or failure.
Instance Method Summary collapse
-
#call ⇒ ServiceClient::Response
Determines whether the response was successful or not.
-
#initialize(response) ⇒ Response
constructor
Initializes a new instance of Response with the given HTTP response object.
Methods included from Errors
Constructor Details
#initialize(response) ⇒ Response
Initializes a new instance of Response with the given HTTP response object.
19 20 21 22 23 |
# File 'lib/service_client/response.rb', line 19 def initialize(response) @code = response.code @data = response.parsed_response @headers = response.headers end |
Instance Attribute Details
#code ⇒ Integer (readonly)
The HTTP status code of the response.
11 12 13 |
# File 'lib/service_client/response.rb', line 11 def code @code end |
#data ⇒ Hash, ... (readonly)
The parsed body of the response.
11 12 13 |
# File 'lib/service_client/response.rb', line 11 def data @data end |
#headers ⇒ Hash (readonly)
The HTTP headers of the response.
11 12 13 |
# File 'lib/service_client/response.rb', line 11 def headers @headers end |
Class Method Details
.call(response) ⇒ ServiceClient::Response
Initializes a new instance of Response and calls it to determine success or failure.
and object if the response was unsuccessful.
45 46 47 |
# File 'lib/service_client/response.rb', line 45 def call(response) new(response).call end |
Instance Method Details
#call ⇒ ServiceClient::Response
Determines whether the response was successful or not.
29 30 31 32 33 34 35 36 |
# File 'lib/service_client/response.rb', line 29 def call case code when 200..299 self else raise_error(code.to_s, self) end end |