mindee 5.2.0 → 5.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4035b0201f4458b0bdb6066c4602d132ef2695436d47d2c36f27a5eccf8c5af8
4
- data.tar.gz: dfa07b33ef6c2da5f5d973fa47c01ff969bcd011e3b595785f2f06dd411b4c4c
3
+ metadata.gz: addb1d4afceb4816df637946d7d0028da0459681ae05ecf5ce9550f5a2329b2c
4
+ data.tar.gz: f495ddafda38ba5f5cf6c0e00e88a331a32264a297704a941136d61b660700a8
5
5
  SHA512:
6
- metadata.gz: 620d7b8e30cb6368451485d4119a357f991b5105c73d7407d18294ef440c17d2d0602960a00742fb5a3969d33cd7308a8771833bb01fd2fb8bfd74eb64fc5fef
7
- data.tar.gz: 10644668f5aa9b0c2848e252cfe8174368c3bd49f5483028c9d0a7e316356986c0300acd875e162156e5338ff53d3d297e47aec5fd33ca9824e39d3d3181272b
6
+ metadata.gz: 2e2784c6fb7c8a8cb98eb1bb6d191b451899fbd4c4a4ae985d8f7d0271b4aa2a97edc64a0b084a700d8769def4b0400cdab24393b3eb7b1f14726407d7f2c93b
7
+ data.tar.gz: 6718cc7f954306771effbc7e96236bd246ed7aaf34f6296278d55cc821e3d850e54ce03608c64d7d81cb05d4b4ed8cf4055e2d0c08ec4ec315c0dfc0d948a188
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Mindee Ruby API Library Changelog
2
2
 
3
+ ## v5.2.1 - 2026-05-27
4
+ ### Changes
5
+ * :recycle: add polling options as a dedicated parameter (#252)
6
+
7
+
3
8
  ## v5.2.0 - 2026-05-19
4
9
  ### Changes
5
10
  * :sparkles: add webhook info to model searches
@@ -3,6 +3,7 @@
3
3
  module Mindee
4
4
  # Centralized check for optional heavy dependencies
5
5
  module Dependencies
6
+ # Checks the presence of dependencies.
6
7
  def self.check_all_dependencies
7
8
  require 'origami'
8
9
  require 'mini_magick'
@@ -12,16 +13,20 @@ module Mindee
12
13
  false
13
14
  end
14
15
 
16
+ # Memoized check.
15
17
  @all_deps_available = check_all_dependencies
16
18
 
19
+ # Checks whether all dependencies are available.
17
20
  def self.all_deps_available?
18
21
  check_all_dependencies
19
22
  end
20
23
 
24
+ # Raises an error if dependencies are not available.
21
25
  def self.require_all_deps!
22
26
  raise LoadError, MINDEE_DEPENDENCIES_LOAD_ERROR unless all_deps_available?
23
27
  end
24
28
 
29
+ # Error message to display when dependencies are not available.
25
30
  MINDEE_DEPENDENCIES_LOAD_ERROR = 'Attempted to load Mindee PDF/Image tools without required dependencies. ' \
26
31
  "If you need to process local files, please replace the 'mindee-lite' gem " \
27
32
  "with the standard 'mindee' gem in your Gemfile."
@@ -9,7 +9,7 @@ module Mindee
9
9
  # @param image [MiniMagick::Image, StringIO] Input image.
10
10
  # @param quality [Integer, nil] Quality of the final file.
11
11
  # @param max_width [Integer, nil] Maximum width. If not specified, the horizontal ratio will remain the same.
12
- # @param max_height [Integer] Maximum height. If not specified, the vertical ratio will remain the same.
12
+ # @param max_height [Integer, nil] Maximum height. If not specified, the vertical ratio will remain the same.
13
13
  # @return [StringIO]
14
14
  def self.compress_image(image, quality: 85, max_width: nil, max_height: nil)
15
15
  processed_image = ImageUtils.to_image(image)
@@ -22,7 +22,7 @@ module Mindee
22
22
  # @param [String] model_id ID of the model
23
23
  # @param [String, nil] file_alias File alias, if applicable.
24
24
  # @param [Array<String>, nil] webhook_ids List of webhook IDs to propagate the API response to.
25
- # @param [Hash, nil] polling_options Options for polling. Set only if having timeout issues.
25
+ # @param [Hash, PollingOptions, nil] polling_options Options for polling. Set only if having timeout issues.
26
26
  # @param [Boolean, nil] close_file Whether to close the file after parsing.
27
27
  def initialize(
28
28
  model_id,
@@ -40,6 +40,13 @@ module Mindee
40
40
  @close_file = close_file.nil? || close_file
41
41
  end
42
42
 
43
+ # Sets polling options after normalizing hash inputs.
44
+ # @param [Hash, PollingOptions, nil] polling_options
45
+ # @return [PollingOptions]
46
+ def polling_options=(polling_options)
47
+ @polling_options = get_clean_polling_options(polling_options)
48
+ end
49
+
43
50
  # @return [String] Slug for the endpoint.
44
51
  def self.slug
45
52
  if self == BaseParameters
@@ -83,12 +83,14 @@ module Mindee
83
83
  # @return [StringIO] The fixed stream.
84
84
  # @raise [Mindee::Error::MindeePDFError]
85
85
  def self.fix_pdf(stream, maximum_offset: 500)
86
- out_stream = StringIO.new
86
+ out_stream = StringIO.new(''.b)
87
87
  stream.gets('%PDF-')
88
88
  raise Error::MindeePDFError if stream.eof? || stream.pos > maximum_offset
89
89
 
90
90
  stream.pos = stream.pos - 5
91
- out_stream << stream.read
91
+ out_stream.write(stream.read.to_s.b)
92
+ out_stream.rewind
93
+ out_stream
92
94
  end
93
95
 
94
96
  # Cuts a PDF file according to provided options.
@@ -57,14 +57,16 @@ module Mindee
57
57
  # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource]
58
58
  # The source of the input document (local file or URL).
59
59
  # @param params [Hash, Input::BaseParameters] Parameters for the inference.
60
+ # @param polling_options [Hash, PollingOptions, nil] Parameters for polling.
60
61
  # @return [Parsing::BaseResponse]
61
62
  def enqueue_and_get_result(
62
63
  product,
63
64
  input_source,
64
- params
65
+ params,
66
+ polling_options = nil
65
67
  )
66
68
  enqueue_response = enqueue(product, input_source, params)
67
- normalized_params = normalize_parameters(product.params_type, params)
69
+ normalized_params = normalize_parameters(product.params_type, params, polling_options: polling_options)
68
70
  normalized_params.validate_async_params
69
71
 
70
72
  if enqueue_response.job.id.nil? || enqueue_response.job.id.empty?
@@ -121,8 +123,14 @@ module Mindee
121
123
 
122
124
  # If needed, converts the parsing options provided as a hash into a proper BaseParameters subclass object.
123
125
  # @param params [Hash, Class<BaseParameters>] Params.
126
+ # @param polling_options [Hash, PollingOptions, nil] Polling options.
124
127
  # @return [BaseParameters]
125
- def normalize_parameters(param_class, params)
128
+ def normalize_parameters(param_class, params, polling_options: nil)
129
+ if params.is_a?(Hash)
130
+ params[:polling_options] = polling_options if polling_options
131
+ elsif params.is_a?(Mindee::Input::BaseParameters) && !polling_options.nil?
132
+ params.polling_options = polling_options
133
+ end
126
134
  return param_class.from_hash(params: params) if params.is_a?(Hash)
127
135
 
128
136
  params
@@ -16,7 +16,7 @@ module Mindee
16
16
  # @param [String] model_id ID of the model
17
17
  # @param [String, nil] file_alias File alias, if applicable.
18
18
  # @param [Array<String>, nil] webhook_ids List of webhook IDs to propagate the API response to.
19
- # @param [Hash, nil] polling_options Options for polling. Set only if having timeout issues.
19
+ # @param [Hash, PollingOptions, nil] polling_options Options for polling. Set only if having timeout issues.
20
20
  # @param [Boolean, nil] close_file Whether to close the file after parsing.
21
21
  def initialize(
22
22
  model_id,
@@ -16,7 +16,7 @@ module Mindee
16
16
  # @param [String] model_id ID of the model
17
17
  # @param [String, nil] file_alias File alias, if applicable.
18
18
  # @param [Array<String>, nil] webhook_ids List of webhook IDs to propagate the API response to.
19
- # @param [Hash, nil] polling_options Options for polling. Set only if having timeout issues.
19
+ # @param [Hash, PollingOptions, nil] polling_options Options for polling. Set only if having timeout issues.
20
20
  # @param [Boolean, nil] close_file Whether to close the file after parsing.
21
21
  def initialize(
22
22
  model_id,
@@ -13,7 +13,7 @@ module Mindee
13
13
  # @return [Mindee::V2::Product::Extraction::Params::DataSchemaReplace]
14
14
  attr_reader :replace
15
15
 
16
- # @param data_schema [Hash, String]
16
+ # @param data_schema [Hash, DataSchema, String]
17
17
  def initialize(data_schema)
18
18
  case data_schema
19
19
  when String
@@ -46,7 +46,7 @@ module Mindee
46
46
  # @param [String, nil] file_alias File alias, if applicable.
47
47
  # @param [Array<String>, nil] webhook_ids
48
48
  # @param [String, nil] text_context
49
- # @param [Hash, nil] polling_options
49
+ # @param [Hash, PollingOptions, nil] polling_options
50
50
  # @param [Boolean, nil] close_file
51
51
  # @param [DataSchemaField, String, Hash nil] data_schema
52
52
  def initialize(
@@ -16,7 +16,7 @@ module Mindee
16
16
  # @param [String] model_id ID of the model
17
17
  # @param [String, nil] file_alias File alias, if applicable.
18
18
  # @param [Array<String>, nil] webhook_ids List of webhook IDs to propagate the API response to.
19
- # @param [Hash, nil] polling_options Options for polling. Set only if having timeout issues.
19
+ # @param [Hash, PollingOptions, nil] polling_options Options for polling. Set only if having timeout issues.
20
20
  # @param [Boolean, nil] close_file Whether to close the file after parsing.
21
21
  def initialize(
22
22
  model_id,
@@ -17,7 +17,7 @@ module Mindee
17
17
  # @param [String] model_id ID of the model
18
18
  # @param [String, nil] file_alias File alias, if applicable.
19
19
  # @param [Array<String>, nil] webhook_ids List of webhook IDs to propagate the API response to.
20
- # @param [Hash, nil] polling_options Options for polling. Set only if having timeout issues.
20
+ # @param [Hash, PollingOptions, nil] polling_options Options for polling. Set only if having timeout issues.
21
21
  # @param [Boolean, nil] close_file Whether to close the file after parsing.
22
22
  def initialize(
23
23
  model_id,
@@ -3,7 +3,7 @@
3
3
  # Mindee
4
4
  module Mindee
5
5
  # Current version.
6
- VERSION = '5.2.0'
6
+ VERSION = '5.2.1'
7
7
 
8
8
  # Finds and return the current platform.
9
9
  # @return [Symbol, Hash[String | Symbol, Regexp], Nil?]
@@ -26,6 +26,7 @@ module Mindee
26
26
 
27
27
  def append_form_data: (Array[Array[untyped]]) -> Array[Array[untyped]]
28
28
  def validate_async_params: () -> void
29
+ def polling_options=: (Hash[Symbol | String, untyped] | PollingOptions?) -> PollingOptions
29
30
 
30
31
  private
31
32
 
@@ -17,13 +17,13 @@ module Mindee
17
17
 
18
18
  def enqueue: [T] (HTTP::_ProductClass[T] product, Input::Source::LocalInputSource | Input::Source::URLInputSource, Hash[String | Symbol, untyped] | Input::BaseParameters params) -> V2::Parsing::JobResponse
19
19
 
20
- def enqueue_and_get_result: [T] (HTTP::_ProductClass[T] product, Input::Source::LocalInputSource | Input::Source::URLInputSource, Hash[String | Symbol, untyped] | Input::BaseParameters params) -> T
20
+ def enqueue_and_get_result: [T] (HTTP::_ProductClass[T] product, Input::Source::LocalInputSource | Input::Source::URLInputSource, Hash[String | Symbol, untyped] | Input::BaseParameters params, ?Hash[String | Symbol, untyped] | Input::PollingOptions?) -> T
21
21
 
22
22
  def search_models: (String?, String?) -> Mindee::V2::Parsing::Search::SearchResponse
23
23
 
24
24
  def validate_async_params: (Integer | Float, Integer | Float, Integer) -> void
25
25
 
26
- def normalize_parameters: (singleton(Input::BaseParameters) param_class, Hash[String | Symbol, untyped] | Input::BaseParameters params) -> Input::BaseParameters
26
+ def normalize_parameters: (singleton(Input::BaseParameters) param_class, Hash[String | Symbol, untyped] | Input::BaseParameters params, ?polling_options: Hash[String | Symbol, untyped] | Input::PollingOptions?) -> Input::BaseParameters
27
27
  end
28
28
  end
29
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mindee
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.0
4
+ version: 5.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mindee, SA
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-05-19 00:00:00.000000000 Z
11
+ date: 2026-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64