Class: Orchestrate::API::Response
- Inherits:
-
Object
- Object
- Orchestrate::API::Response
- Extended by:
- Forwardable
- Defined in:
- lib/orchestrate/api/response.rb
Overview
A generic response from the API.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#body ⇒ String, Hash
readonly
The response body from Orchestrate.
-
#client ⇒ Orchestrate::Client
readonly
The client used to generate the response.
-
#headers ⇒ Hash{String => String}
readonly
The response headers.
-
#request_id ⇒ String
readonly
The Orchestrate API Request ID.
-
#request_time ⇒ Time
readonly
The time at which the response was made.
-
#status ⇒ Integer
readonly
The HTTP Status code of the response.
Instance Method Summary collapse
-
#finished? ⇒ true, false
If the response is finished or not.
-
#initialize(faraday_response, client) ⇒ Response
constructor
Instantiate a new Respose.
- #on_complete {|block| ... } ⇒ Object
-
#success? ⇒ true, false
If the response is 1xx-3xx class response or a 4xx-5xx class response.
Constructor Details
#initialize(faraday_response, client) ⇒ Response
Instantiate a new Respose
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/orchestrate/api/response.rb', line 40 def initialize(faraday_response, client) @client = client @response = faraday_response @response.on_complete do @request_id = headers['X-Orchestrate-Req-Id'] if headers['X-Orchestrate-Req-Id'] @request_time = Time.parse(headers['Date']) if headers['Date'] if headers['Content-Type'] =~ /json/ && !@response.body.strip.empty? @body = JSON.parse(@response.body) else @body = @response.body end handle_error_response unless success? end end |
Instance Attribute Details
#body ⇒ String, Hash (readonly)
Returns The response body from Orchestrate.
|
# File 'lib/orchestrate/api/response.rb', line 12
|
#client ⇒ Orchestrate::Client (readonly)
Returns The client used to generate the response.
32 33 34 |
# File 'lib/orchestrate/api/response.rb', line 32 def client @client end |
#headers ⇒ Hash{String => String} (readonly)
Returns The response headers.
|
# File 'lib/orchestrate/api/response.rb', line 12
|
#request_id ⇒ String (readonly)
Returns The Orchestrate API Request ID. For use when troubleshooting.
26 27 28 |
# File 'lib/orchestrate/api/response.rb', line 26 def request_id @request_id end |
#request_time ⇒ Time (readonly)
Returns The time at which the response was made.
29 30 31 |
# File 'lib/orchestrate/api/response.rb', line 29 def request_time @request_time end |
#status ⇒ Integer (readonly)
Returns The HTTP Status code of the response.
|
# File 'lib/orchestrate/api/response.rb', line 12
|
Instance Method Details
#finished? ⇒ true, false
Returns If the response is finished or not.
|
# File 'lib/orchestrate/api/response.rb', line 12
|
#on_complete {|block| ... } ⇒ Object
|
# File 'lib/orchestrate/api/response.rb', line 12
|
#success? ⇒ true, false
Returns If the response is 1xx-3xx class response or a 4xx-5xx class response.
|
# File 'lib/orchestrate/api/response.rb', line 12
|