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



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)



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


#clientOrchestrate::Client (readonly)



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

def client
  @client
end

#headersHash{String => String} (readonly)



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


#request_idString (readonly)



26
27
28
# File 'lib/orchestrate/api/response.rb', line 26

def request_id
  @request_id
end

#request_timeTime (readonly)



29
30
31
# File 'lib/orchestrate/api/response.rb', line 29

def request_time
  @request_time
end

#statusInteger (readonly)



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


Instance Method Details

#finished?true, false



# 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



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