mindee-lite 5.2.1 → 5.2.2

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: 4252d5543e5e163559b6699c8ce78819a1fbd1aefb0a2565ac660125aae5450a
4
- data.tar.gz: f495ddafda38ba5f5cf6c0e00e88a331a32264a297704a941136d61b660700a8
3
+ metadata.gz: f309aa0cd9c594dd11e44b754a6f313f56786ddc0e03b7ea1503d38d48ae4701
4
+ data.tar.gz: c00cd97ccded0ac194a1311d45adc36baa04c5e932fd49248b46c59e065c71f7
5
5
  SHA512:
6
- metadata.gz: dd4a25c2c4f5a01ead752732f696bbf26cedbd0e10ebcb823773e171c3a2e9bcac0d8c69cbb0618421841abd6d5bb7981c70391ff6942d694f393481f29b3597
7
- data.tar.gz: 6718cc7f954306771effbc7e96236bd246ed7aaf34f6296278d55cc821e3d850e54ce03608c64d7d81cb05d4b4ed8cf4055e2d0c08ec4ec315c0dfc0d948a188
6
+ metadata.gz: bc4983fa4d22c23b4fac65c3d9d36441114c8a94117f4aed73dd628aca2ea1b1216ad05cc0cadd2b1f9298c98561f674786c559eb69b4f40184c1e8960a06fdd
7
+ data.tar.gz: d53c54dee59e8f1ee9ff6b62267def50a08248d27e491f2d5ccd53a28277812167c507efa7f1f990cb7a264985df126b7a9cb8c544c728dd98a5d243207b26f2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Mindee Ruby API Library Changelog
2
2
 
3
+ ## v5.2.2 - 2026-06-18
4
+ ### Changes
5
+ * :recycle: refactor CLI to conform with other client libraries
6
+ * :recycle: add secondary accessor for search model pagination to match json return
7
+ * :recycle: ensure HEIF images are detected as such and properly handled
8
+
9
+
3
10
  ## v5.2.1 - 2026-05-27
4
11
  ### Changes
5
12
  * :recycle: add polling options as a dedicated parameter (#252)
data/bin/mindee.rb CHANGED
@@ -6,24 +6,29 @@ require 'optparse'
6
6
  require_relative 'v1/parser'
7
7
  require_relative 'v2/parser'
8
8
 
9
- def setup_main_parser
10
- v1_parser = MindeeCLI::V1Parser.new(ARGV)
11
- v2_parser = MindeeCLI::V2Parser.new(ARGV)
12
- main_parser = OptionParser.new do |opts|
13
- opts.banner = "Usage: mindee [command]"
14
- opts.separator "Commands:"
15
- opts.separator " v1 Use Version 1 of the Mindee API"
16
- opts.separator " v2 Use Version 2 of the Mindee API"
9
+ def root_help
10
+ help = "Usage: mindee command [options]\n\nAvailable commands:\n"
11
+ help += " #{'v1'.ljust(50)}Use Version 1 of the Mindee API\n"
12
+ help += " #{'search-models'.ljust(50)}Search for available models for this API key\n"
13
+
14
+ V2_PRODUCTS.each do |product_key, product_values|
15
+ help += " #{product_key.ljust(50)}#{product_values[:description]}\n"
17
16
  end
18
- main_command = ARGV.shift
19
17
 
20
- case main_command
21
- when 'v1'
22
- v1_parser.execute
23
- when 'v2'
24
- v2_parser.execute
18
+ help
19
+ end
20
+
21
+ def setup_main_parser
22
+ main_command = ARGV.first
23
+
24
+ if main_command == 'v1'
25
+ ARGV.shift
26
+ MindeeCLI::V1Parser.new(ARGV).execute
27
+ elsif main_command.nil? || %w[help -h --help].include?(main_command)
28
+ abort(root_help)
25
29
  else
26
- abort(main_parser.help)
30
+ ARGV.shift if main_command == 'v2'
31
+ MindeeCLI::V2Parser.new(ARGV, command_prefix: 'mindee').execute
27
32
  end
28
33
  end
29
34
 
data/bin/v2/parser.rb CHANGED
@@ -19,10 +19,11 @@ module MindeeCLI
19
19
  # @return [Parser]
20
20
  attr_reader :search_parser
21
21
 
22
- def initialize(arguments)
22
+ def initialize(arguments, command_prefix: 'mindee v2')
23
23
  @arguments = arguments
24
+ @command_prefix = command_prefix
24
25
  @options_parser = OptionParser.new do |opts|
25
- opts.banner = 'Usage: mindee v2 command [options]'
26
+ opts.banner = "Usage: #{@command_prefix} command [options]"
26
27
  end
27
28
  @product_parser = init_product_parser
28
29
  @search_parser = init_search_parser
@@ -67,6 +68,8 @@ module MindeeCLI
67
68
  else
68
69
  abort("#{e.message}\n\n#{@product_parser[command].help}")
69
70
  end
71
+ rescue Mindee::Error::MindeeError => e
72
+ abort(format_cli_error(e))
70
73
  end
71
74
 
72
75
  private
@@ -83,9 +86,21 @@ module MindeeCLI
83
86
  abort(error_msg)
84
87
  end
85
88
 
89
+ def format_cli_error(error)
90
+ if error.is_a?(Mindee::Error::MindeeHTTPErrorV2) && error.status.to_i == 401
91
+ "CLI error: Missing credentials. Provide an API key using '--key' or " \
92
+ "the 'MINDEE_V2_API_KEY' environment variable."
93
+ elsif error.is_a?(Mindee::Error::MindeeAPIError) && error.message.include?('Missing API key')
94
+ "CLI error: Missing API key. Provide it using '--key' or " \
95
+ "the 'MINDEE_V2_API_KEY' environment variable."
96
+ else
97
+ "CLI error: #{error.message}"
98
+ end
99
+ end
100
+
86
101
  def init_search_parser
87
102
  OptionParser.new do |options_parser|
88
- options_parser.banner = 'Usage: mindee v2 search-models [options]'
103
+ options_parser.banner = "Usage: #{@command_prefix} search-models [options]"
89
104
  init_common_options(options_parser)
90
105
  options_parser.on('-n [NAME]', '--name [NAME]',
91
106
  'Search for partial matches in model name. Note: case insensitive') do |v|
@@ -159,7 +174,7 @@ module MindeeCLI
159
174
  v2_product_parser = {}
160
175
  V2_PRODUCTS.each do |product_key, product_values|
161
176
  v2_product_parser[product_key] = OptionParser.new do |options_parser|
162
- options_parser.banner = "Usage: mindee v2 #{product_key} [options] file"
177
+ options_parser.banner = "Usage: #{@command_prefix} #{product_key} [options] file"
163
178
  options_parser.on('-m MODEL_ID', '--model-id MODEL_ID', 'Model ID') { |v| @options[:model_id] = v }
164
179
  options_parser.on('-a ALIAS', '--alias ALIAS', 'Add a file alias to the response') do |v|
165
180
  @options[:alias] = v
@@ -16,6 +16,7 @@ module Mindee
16
16
  ALLOWED_MIME_TYPES = [
17
17
  'application/pdf',
18
18
  'image/heic',
19
+ 'image/heif',
19
20
  'image/png',
20
21
  'image/jpeg',
21
22
  'image/tiff',
@@ -37,11 +38,7 @@ module Mindee
37
38
  def initialize(io_stream, filename, repair_pdf: false)
38
39
  @io_stream = io_stream
39
40
  @filename = filename
40
- @file_mimetype = if repair_pdf
41
- Marcel::MimeType.for @io_stream
42
- else
43
- Marcel::MimeType.for @io_stream, name: @filename
44
- end
41
+ @file_mimetype = detect_mime_type(repair_pdf)
45
42
  if ALLOWED_MIME_TYPES.include? @file_mimetype
46
43
  logger.debug("Loaded new input #{@filename} from #{self.class}")
47
44
  return
@@ -197,6 +194,28 @@ module Mindee
197
194
 
198
195
  Mindee::PDF::PDFTools.source_text?(@io_stream)
199
196
  end
197
+
198
+ private
199
+
200
+ # Checks the mimetype for the file. If it is a PDF, it will attempt to repair it if repair_pdf is true.
201
+ # @param repair_pdf [bool] Whether to attempt to repair the PDF.
202
+ # @return [String] The mimetype of the file.
203
+ def detect_mime_type(repair_pdf)
204
+ return Marcel::MimeType.for(@io_stream) if repair_pdf
205
+
206
+ heif_mimetype_from_extension || Marcel::MimeType.for(@io_stream, name: @filename)
207
+ end
208
+
209
+ # Checks the file extension for a HEIF mimetype.
210
+ # @return [String, nil] The mimetype if found, nil otherwise.
211
+ def heif_mimetype_from_extension
212
+ case File.extname(@filename.to_s).downcase
213
+ when '.heic'
214
+ 'image/heic'
215
+ when '.heif'
216
+ 'image/heif'
217
+ end
218
+ end
200
219
  end
201
220
 
202
221
  # Replaces non-ASCII characters by their UNICODE escape sequence.
@@ -6,16 +6,19 @@ module Mindee
6
6
  module Search
7
7
  # Models search response.
8
8
  class SearchResponse < CommonResponse
9
- # @return [Search::Search] Parsed search payload.
9
+ # @return [Search::SearchModels] Parsed search payload.
10
10
  attr_reader :models
11
- # @return [Search::Search] Pagination metadata.
11
+ # @return [Search::PaginationMetadata] Pagination metadata.
12
+ attr_reader :pagination
13
+ # @return [Search::PaginationMetadata] Pagination metadata.
12
14
  attr_reader :pagination_metadata
13
15
 
14
16
  def initialize(server_response)
15
17
  super
16
18
 
17
- @models = Search::SearchModels.new(server_response['models'])
18
- @pagination_metadata = PaginationMetadata.new(server_response['pagination'])
19
+ @models = SearchModels.new(server_response['models'])
20
+ @pagination = PaginationMetadata.new(server_response['pagination'])
21
+ @pagination_metadata = @pagination
19
22
  end
20
23
 
21
24
  # String representation.
@@ -27,7 +30,7 @@ module Mindee
27
30
  @models.to_s,
28
31
  'Pagination Metadata',
29
32
  '###################',
30
- @pagination_metadata.to_s,
33
+ @pagination.to_s,
31
34
  '',
32
35
  ].join("\n")
33
36
  end
@@ -3,7 +3,7 @@
3
3
  # Mindee
4
4
  module Mindee
5
5
  # Current version.
6
- VERSION = '5.2.1'
6
+ VERSION = '5.2.2'
7
7
 
8
8
  # Finds and return the current platform.
9
9
  # @return [Symbol, Hash[String | Symbol, Regexp], Nil?]
@@ -23,6 +23,12 @@ module Mindee
23
23
  def write_to_file: (String?) -> void
24
24
  def compress!: (?quality: Integer, ?max_width: Integer?, ?max_height: Integer?, ?force_source_text: bool, ?disable_source_text: bool) -> Integer
25
25
  def source_text?: -> bool?
26
+
27
+ private
28
+
29
+ def detect_mime_type: (bool) -> String
30
+
31
+ def heif_mimetype_from_extension: -> String?
26
32
  end
27
33
  def self.convert_to_unicode_escape: (String) -> String
28
34
  end
@@ -0,0 +1,13 @@
1
+ # lib/mindee/v2/parsing/search/search_models.rb
2
+
3
+ module Mindee
4
+ module V2
5
+ module Parsing
6
+ module Search
7
+ # Array of search models.
8
+ class SearchModels < Array[SearchModel]
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -5,6 +5,7 @@ module Mindee
5
5
  module Search
6
6
  class SearchResponse
7
7
  attr_reader models: Array[SearchResponse]
8
+ attr_reader pagination: PaginationMetadata
8
9
  attr_reader pagination_metadata: PaginationMetadata
9
10
 
10
11
  def initialize: (Hash[String|Symbol, untyped]) -> void
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mindee-lite
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.1
4
+ version: 5.2.2
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-27 00:00:00.000000000 Z
11
+ date: 2026-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64
@@ -57,8 +57,8 @@ description: Quickly and easily connect to Mindee's API services using Ruby. Thi
57
57
  email:
58
58
  - opensource@mindee.co
59
59
  executables:
60
- - mindee.rb
61
60
  - console
61
+ - mindee.rb
62
62
  extensions: []
63
63
  extra_rdoc_files: []
64
64
  files:
@@ -535,6 +535,7 @@ files:
535
535
  - sig/mindee/v2/parsing/search/model_webhook.rbs
536
536
  - sig/mindee/v2/parsing/search/pagination_metadata.rbs
537
537
  - sig/mindee/v2/parsing/search/search_model.rbs
538
+ - sig/mindee/v2/parsing/search/search_models.rbs
538
539
  - sig/mindee/v2/parsing/search/search_response.rbs
539
540
  - sig/mindee/v2/parsing/search_models.rbs
540
541
  - sig/mindee/v2/product/base_product.rbs