Class: Orchestrate::API::Response

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/orchestrate/api/response.rb

Overview

A generic response from the API.

Direct Known Subclasses

CollectionResponse, ItemResponse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(faraday_response, client) ⇒ Response

Instantiate a new Respose

Parameters:

  • faraday_response (Faraday::Response)

    The Faraday response object.

  • client (Orchestrate::Client)

    The client used to generate the response.


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

#bodyString, Hash (readonly)

Returns The response body from Orchestrate.

Returns:

  • (String, Hash)

    The response body from Orchestrate


# File 'lib/orchestrate/api/response.rb', line 12

#clientOrchestrate::Client (readonly)

Returns The client used to generate the response.

Returns:


32
33
34
# File 'lib/orchestrate/api/response.rb', line 32

def client
  @client
end

#headersHash{String => String} (readonly)

Returns The response headers.

Returns:

  • (Hash{String => String})

    The response headers


# File 'lib/orchestrate/api/response.rb', line 12

#request_idString (readonly)

Returns The Orchestrate API Request ID. For use when troubleshooting.

Returns:

  • (String)

    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_timeTime (readonly)

Returns The time at which the response was made.

Returns:

  • (Time)

    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

#statusInteger (readonly)

Returns The HTTP Status code of the response.

Returns:

  • (Integer)

    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.

Returns:

  • (true, false)

    If the response is finished or not.


# File 'lib/orchestrate/api/response.rb', line 12

#on_complete {|block| ... } ⇒ Object

Yields:

  • (block)

    A block to be called when the response has completed.


# 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.

Returns:

  • (true, false)

    If the response is 1xx-3xx class response or a 4xx-5xx class response.


# File 'lib/orchestrate/api/response.rb', line 12