class Orchestrate::API::Response
A generic response from the API
.
Attributes
body[R]
@return [String, Hash] The response body from Orchestrate
client[R]
@return [Orchestrate::Client] The client used to generate the response.
request_id[R]
@return [String] The Orchestrate
API
Request ID. For use when troubleshooting.
request_time[R]
@return [Time] The time at which the response was made.
Public Class Methods
new(faraday_response, client)
click to toggle source
Instantiate a new Respose @param faraday_response [Faraday::Response] The Faraday response object. @param client [Orchestrate::Client] The client used to generate the response.
# 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
Public Instance Methods
to_s()
click to toggle source
@!visibility private
# File lib/orchestrate/api/response.rb, line 56 def to_s "#<#{self.class.name} status=#{status} request_id=#{request_id}>" end
Also aliased as: inspect
Private Instance Methods
handle_error_response()
click to toggle source
# File lib/orchestrate/api/response.rb, line 62 def handle_error_response err_type = if body && body['code'] ERRORS.find {|err| err.status == status && err.code == body['code'] } else errors = ERRORS.select {|err| err.status == status} errors.length == 1 ? errors.first : nil end if err_type raise err_type.new(self) elsif status < 500 raise RequestError.new(self) else raise ServiceError.new(self) end end