Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/v2/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def setup_specific_options(options_parser, doc_value)
# Initialize common options for search and product commands.
# @param options_parser [OptionParser]
def init_common_options(options_parser)
options_parser.on('-k [KEY]', '--key [KEY]', 'API key for the endpoint') { |v| @options[:api_key] = v }
options_parser.on('-k [KEY]', '--key [KEY]', 'Mindee V2 API key.') { |v| @options[:api_key] = v }
options_parser.on('-o FORMAT', '--output-format FORMAT', ['raw', 'full', 'summary'],
'Format of the output (raw, full, summary). Default: summary') do |format|
@options[:output_format] = format
Expand Down
1 change: 1 addition & 0 deletions lib/mindee/v2/parsing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
require_relative 'parsing/raw_text'
require_relative 'parsing/raw_text_page'
require_relative 'parsing/search'
require_relative 'parsing/failed_inference_response'
34 changes: 34 additions & 0 deletions lib/mindee/v2/parsing/failed_inference_response.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

module Mindee
module V2
module Parsing
# "Webhook payload returned when an inference fails before producing a result.
class FailedInferenceResponse < Mindee::V2::Parsing::CommonResponse
# @return [String] UUID of the failed inference.
attr_reader :inference_id
# @return [String] UUID of the model used.
attr_reader :model_id
# @return [String] Name of the input file.
attr_reader :file_name
# @return [String, Nil] Alias sent for the file, if any.
attr_reader :file_alias
# @return [Mindee::V2::Parsing::ErrorResponse] Problem details for the failure, if available.
attr_reader :error
# @return [Time] Date and time when the inference was started.
attr_reader :created_at

def initialize(server_response)
super

@inference_id = server_response['inference_id']
@model_id = server_response['model_id']
@file_name = server_response['file_name']
@file_alias = server_response['file_alias']
@error = ErrorResponse.new(server_response['error'])
@created_at = Time.iso8601(server_response['created_at'])
end
end
end
end
end
15 changes: 15 additions & 0 deletions sig/mindee/v2/parsing/failed_inference_response.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Mindee
module V2
module Parsing
class FailedInferenceResponse
def initialize: (Hash[String | Symbol, untyped]) -> void
attr_reader created_at: Time
attr_reader error: ::Mindee::V2::Parsing::ErrorResponse
attr_reader file_alias: String
attr_reader file_name: String
attr_reader inference_id: String
attr_reader model_id: String
end
end
end
end
2 changes: 1 addition & 1 deletion spec/data
17 changes: 17 additions & 0 deletions spec/v2/parsing/failed_inference_response_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

require 'mindee/v2/parsing'

describe Mindee::V2::Parsing::FailedInferenceResponse do
it 'initializes' do
json_file_path = File.join(V2_DATA_DIR, 'errors', 'webhook_error_500_failed.json')

response = described_class.new(JSON.parse(File.read(json_file_path)))
expect(response).not_to be_nil
expect(response.inference_id).to eq('12345678-1234-1234-1234-123456789ABC')
expect(response.file_name).to eq('default_sample.jpg')
expect(response.file_alias).to eq('dummy-alias.jpg')
expect(response.error.status).to eq(500)
expect(response.error.code).to eq('500-012')
end
end
Loading