Class: Mindee::Parsing::Common::ApiResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/mindee/parsing/common/api_response.rb

Overview

Wrapper class for all predictions (synchronous and asynchronous)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(product_class, http_response, raw_http) ⇒ ApiResponse

Returns a new instance of ApiResponse.

Parameters:

  • product_class (Mindee::Inference)
  • http_response (Hash)
  • raw_http (String)

Raises:



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/mindee/parsing/common/api_response.rb', line 39

def initialize(product_class, http_response, raw_http)
  logger.debug('Handling API response')
  @raw_http = raw_http.to_s
  raise Errors::MindeeAPIError, 'Invalid response format.' unless http_response.key?('api_request')

  @api_request = Mindee::Parsing::Common::ApiRequest.new(http_response['api_request'])

  if http_response.key?('document') &&
     (!http_response.key?('job') ||
       http_response['job']['status'] == 'completed') &&
     @api_request.status == RequestStatus::SUCCESS
    @document = Mindee::Parsing::Common::Document.new(product_class, http_response['document'])
  end
  @job = Mindee::Parsing::Common::Job.new(http_response['job']) if http_response.key?('job')
end

Instance Attribute Details

#api_requestMindee::Parsing::Common::ApiRequest (readonly)



32
33
34
# File 'lib/mindee/parsing/common/api_response.rb', line 32

def api_request
  @api_request
end

#documentMindee::Parsing::Common::Document? (readonly)



28
29
30
# File 'lib/mindee/parsing/common/api_response.rb', line 28

def document
  @document
end

#jobMindee::Parsing::Common::Job? (readonly)



30
31
32
# File 'lib/mindee/parsing/common/api_response.rb', line 30

def job
  @job
end

#raw_httpString (readonly)

Returns:

  • (String)


34
35
36
# File 'lib/mindee/parsing/common/api_response.rb', line 34

def raw_http
  @raw_http
end