mindee 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 +4 -4
- data/CHANGELOG.md +7 -0
- data/bin/mindee.rb +20 -15
- data/bin/v2/parser.rb +19 -4
- data/lib/mindee/input/sources/local_input_source.rb +24 -5
- data/lib/mindee/v2/parsing/search/search_response.rb +8 -5
- data/lib/mindee/version.rb +1 -1
- data/sig/mindee/input/sources/local_input_source.rbs +6 -0
- data/sig/mindee/v2/parsing/search/search_models.rbs +13 -0
- data/sig/mindee/v2/parsing/search/search_response.rbs +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b779325cb790132dd8d191e72761e2145c7162d4316ac7ba254987ceb471547f
|
|
4
|
+
data.tar.gz: c00cd97ccded0ac194a1311d45adc36baa04c5e932fd49248b46c59e065c71f7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f7c68cd5d0281f22e0b4476fa6470dc840612045c15eeb6127fe8f50f78c5170f0c07fb5bbe30049f7029330f34390102b11c2ec59264ce2d95b71cf998486e9
|
|
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
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
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 =
|
|
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 =
|
|
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:
|
|
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 =
|
|
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::
|
|
9
|
+
# @return [Search::SearchModels] Parsed search payload.
|
|
10
10
|
attr_reader :models
|
|
11
|
-
# @return [Search::
|
|
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 =
|
|
18
|
-
@
|
|
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
|
-
@
|
|
33
|
+
@pagination.to_s,
|
|
31
34
|
'',
|
|
32
35
|
].join("\n")
|
|
33
36
|
end
|
data/lib/mindee/version.rb
CHANGED
|
@@ -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
|
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.
|
|
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-
|
|
11
|
+
date: 2026-06-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: base64
|
|
@@ -174,8 +174,8 @@ description: Quickly and easily connect to Mindee's API services using Ruby.
|
|
|
174
174
|
email:
|
|
175
175
|
- opensource@mindee.co
|
|
176
176
|
executables:
|
|
177
|
-
- mindee.rb
|
|
178
177
|
- console
|
|
178
|
+
- mindee.rb
|
|
179
179
|
extensions: []
|
|
180
180
|
extra_rdoc_files: []
|
|
181
181
|
files:
|
|
@@ -652,6 +652,7 @@ files:
|
|
|
652
652
|
- sig/mindee/v2/parsing/search/model_webhook.rbs
|
|
653
653
|
- sig/mindee/v2/parsing/search/pagination_metadata.rbs
|
|
654
654
|
- sig/mindee/v2/parsing/search/search_model.rbs
|
|
655
|
+
- sig/mindee/v2/parsing/search/search_models.rbs
|
|
655
656
|
- sig/mindee/v2/parsing/search/search_response.rbs
|
|
656
657
|
- sig/mindee/v2/parsing/search_models.rbs
|
|
657
658
|
- sig/mindee/v2/product/base_product.rbs
|