Class: Mindee::V2::ClientOptions::BaseProductParameters
- Defined in:
- lib/mindee/v2/client_options/base_product_parameters.rb,
sig/mindee/v2/client_options/base_product_parameters.rbs
Overview
Base class for parameters accepted by all V2 endpoints.
Direct Known Subclasses
Product::Classification::Params::ClassificationParameters, Product::Crop::Params::CropParameters, Product::Extraction::Params::ExtractionParameters, Product::OCR::Params::OCRParameters, Product::Split::Params::SplitParameters
Class Attribute Summary collapse
-
.slug ⇒ String
readonly
Slug for the endpoint.
Instance Attribute Summary collapse
-
#close_file ⇒ Boolean?
readonly
Whether to close the file after parsing.
-
#file_alias ⇒ String?
readonly
For example, an internal document ID, reference number, or database key.
-
#model_id ⇒ String
readonly
Model ID to use for the inference.
-
#polling_options ⇒ Input::PollingOptions
Options for polling.
-
#webhook_ids ⇒ Array<String>?
readonly
If empty, no webhooks will be used.
Class Method Summary collapse
-
.from_hash(params: {}) ⇒ BaseProductParameters
Load from a hash.
-
.load_from_hash(params: {}) ⇒ Hash
Loads a prediction from a Hash.
Instance Method Summary collapse
-
#append_form_data(form_data) ⇒ Array
Appends base form data to the provided array.
-
#get_clean_polling_options(polling_options) ⇒ Input::PollingOptions
Cleans a proper polling options object potentially from a hash.
-
#initialize(model_id, file_alias: nil, webhook_ids: nil, polling_options: nil, close_file: true) ⇒ BaseProductParameters
constructor
issues.
-
#slug ⇒ String
Slug for the endpoint.
-
#validate_async_params ⇒ void
Validates the parameters for async auto-polling.
Constructor Details
#initialize(model_id, file_alias: nil, webhook_ids: nil, polling_options: nil, close_file: true) ⇒ BaseProductParameters
issues.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/mindee/v2/client_options/base_product_parameters.rb', line 32 def initialize( model_id, file_alias: nil, webhook_ids: nil, polling_options: nil, close_file: true ) raise Error::MindeeInputError, 'Model ID is required.' if model_id.nil? || model_id.empty? @model_id = model_id @file_alias = file_alias @webhook_ids = webhook_ids || [] @polling_options = () @close_file = close_file.nil? || close_file end |
Class Attribute Details
.slug ⇒ String (readonly)
Returns Slug for the endpoint.
56 57 58 59 60 61 62 |
# File 'lib/mindee/v2/client_options/base_product_parameters.rb', line 56 def self.slug if self == BaseProductParameters raise NotImplementedError, 'Cannot access `slug` directly on the BaseProductParameters class.' end '' end |
Instance Attribute Details
#close_file ⇒ Boolean? (readonly)
Returns Whether to close the file after parsing.
24 25 26 |
# File 'lib/mindee/v2/client_options/base_product_parameters.rb', line 24 def close_file @close_file end |
#file_alias ⇒ String? (readonly)
For example, an internal document ID, reference number, or database key. If set, it will be included in the job and result responses.
14 15 16 |
# File 'lib/mindee/v2/client_options/base_product_parameters.rb', line 14 def file_alias @file_alias end |
#model_id ⇒ String (readonly)
Returns Model ID to use for the inference. Required.
9 10 11 |
# File 'lib/mindee/v2/client_options/base_product_parameters.rb', line 9 def model_id @model_id end |
#polling_options ⇒ Input::PollingOptions
Returns Options for polling. Set only if having timeout issues.
21 22 23 |
# File 'lib/mindee/v2/client_options/base_product_parameters.rb', line 21 def @polling_options end |
#webhook_ids ⇒ Array<String>? (readonly)
If empty, no webhooks will be used.
18 19 20 |
# File 'lib/mindee/v2/client_options/base_product_parameters.rb', line 18 def webhook_ids @webhook_ids end |
Class Method Details
.from_hash(params: {}) ⇒ BaseProductParameters
Load from a hash
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/mindee/v2/client_options/base_product_parameters.rb', line 72 def self.from_hash(params: {}) load_from_hash(params: params) new( params[:model_id], file_alias: params[:file_alias], webhook_ids: params[:webhook_ids], polling_options: params[:polling_options], close_file: params[:close_file] ) end |
.load_from_hash(params: {}) ⇒ Hash
Loads a prediction from a Hash.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/mindee/v2/client_options/base_product_parameters.rb', line 86 def self.load_from_hash(params: {}) params.transform_keys!(&:to_sym) if params.empty? || params[:model_id].nil? || params[:model_id].empty? raise Error::MindeeInputError, 'Model ID is required.' end = params.fetch(:page_options, Input::PollingOptions.new) if .is_a?(Hash) = .transform_keys(&:to_sym) Input::PollingOptions.new( initial_delay_sec: .fetch(:initial_delay_sec, 2.0), delay_sec: .fetch(:delay_sec, 1.5), max_retries: .fetch(:max_retries, 80) ) end params end |
Instance Method Details
#append_form_data(form_data) ⇒ Array
Appends base form data to the provided array.
108 109 110 111 112 113 |
# File 'lib/mindee/v2/client_options/base_product_parameters.rb', line 108 def append_form_data(form_data) form_data.push(['alias', @file_alias]) if @file_alias webhook_ids = @webhook_ids || [] form_data.push(['webhook_ids', webhook_ids.join(',')]) unless @webhook_ids.nil? || webhook_ids.empty? form_data end |
#get_clean_polling_options(polling_options) ⇒ Input::PollingOptions
Cleans a proper polling options object potentially from a hash.
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/mindee/v2/client_options/base_product_parameters.rb', line 140 def () return Input::PollingOptions.new if .is_a?(Input::PollingOptions) if .is_a?(Hash) = .transform_keys(&:to_sym) = Input::PollingOptions.new( initial_delay_sec: .fetch(:initial_delay_sec, 2.0), delay_sec: .fetch(:delay_sec, 1.5), max_retries: .fetch(:max_retries, 80) ) else = if .is_a?(Input::PollingOptions) || Input::PollingOptions.new else Input::PollingOptions.new end end end |
#slug ⇒ String
Returns Slug for the endpoint.
65 66 67 |
# File 'lib/mindee/v2/client_options/base_product_parameters.rb', line 65 def slug self.class.slug end |
#validate_async_params ⇒ void
This method returns an undefined value.
Validates the parameters for async auto-polling
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/mindee/v2/client_options/base_product_parameters.rb', line 116 def validate_async_params min_delay_sec = 1 min_initial_delay_sec = 1 min_retries = 2 if @polling_options.delay_sec < min_delay_sec raise ArgumentError, "Cannot set auto-poll delay to less than #{min_delay_sec} second(s)" end if @polling_options.initial_delay_sec < min_initial_delay_sec raise ArgumentError, "Cannot set initial parsing delay to less than #{min_initial_delay_sec} second(s)" end return unless @polling_options.max_retries < min_retries raise ArgumentError, "Cannot set auto-poll retries to less than #{min_retries}" end |