Class: Mindee::Parsing::Common::ApiResponse
- Inherits:
-
Object
- Object
- Mindee::Parsing::Common::ApiResponse
- Defined in:
- lib/mindee/parsing/common/api_response.rb
Overview
Wrapper class for all predictions (synchronous and asynchronous)
Instance Attribute Summary collapse
- #api_request ⇒ Mindee::Parsing::Common::ApiRequest readonly
- #document ⇒ Mindee::Parsing::Common::Document? readonly
- #job ⇒ Mindee::Parsing::Common::Job? readonly
- #raw_http ⇒ String readonly
Instance Method Summary collapse
-
#initialize(product_class, http_response, raw_http) ⇒ ApiResponse
constructor
A new instance of ApiResponse.
Constructor Details
#initialize(product_class, http_response, raw_http) ⇒ ApiResponse
Returns a new instance of ApiResponse.
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_request ⇒ Mindee::Parsing::Common::ApiRequest (readonly)
102 103 104 |
# File 'lib/mindee/parsing/common/api_response.rb', line 102 def api_request @api_request end |
#document ⇒ Mindee::Parsing::Common::Document? (readonly)
98 99 100 |
# File 'lib/mindee/parsing/common/api_response.rb', line 98 def document @document end |
#job ⇒ Mindee::Parsing::Common::Job? (readonly)
100 101 102 |
# File 'lib/mindee/parsing/common/api_response.rb', line 100 def job @job end |
#raw_http ⇒ String (readonly)
104 105 106 |
# File 'lib/mindee/parsing/common/api_response.rb', line 104 def raw_http @raw_http end |