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)


109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/mindee/parsing/common/api_response.rb', line 109

def initialize(product_class, http_response, raw_http)
  @raw_http = raw_http.to_s
  raise '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)



102
103
104
# File 'lib/mindee/parsing/common/api_response.rb', line 102

def api_request
  @api_request
end

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



98
99
100
# File 'lib/mindee/parsing/common/api_response.rb', line 98

def document
  @document
end

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



100
101
102
# File 'lib/mindee/parsing/common/api_response.rb', line 100

def job
  @job
end

#raw_httpString (readonly)

Returns:

  • (String)


104
105
106
# File 'lib/mindee/parsing/common/api_response.rb', line 104

def raw_http
  @raw_http
end