mindee 3.6.1 → 3.7.0
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/docs/invoices_v4.md +20 -2
- data/lib/mindee/client.rb +4 -4
- data/lib/mindee/http/error.rb +13 -1
- data/lib/mindee/http/response_validation.rb +7 -2
- data/lib/mindee/product/invoice/invoice_v4_document.rb +10 -0
- data/lib/mindee/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b22c708fcdd44e0e5104e5b5e0f9cf669b7f41e46f1c627af252b86ed5b45d7
|
4
|
+
data.tar.gz: 5695f02623e644bbce0d26a3cec7096370d103b01914a97402887a87eba8cc2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b1e14cdac5f7e0a54d5326a2a9a54387568bddc7060e505468ee3f56896cba9a6d1da341d9a5918f695e99ef7aa79d95d065b43a692f8f036892fd0c4fae070
|
7
|
+
data.tar.gz: 92a95c7c1802fc6099a5ce13a869add7d7865ace5331c8d5a449ca4ed83d4e5e6573a193ed151e75f7b4ec8c2da41f30bd23cc2c71e1889d83ddf4012978123d
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Mindee Ruby API Library Changelog
|
2
2
|
|
3
|
+
## v3.6.2 - 2024-03-28
|
4
|
+
### Changes
|
5
|
+
* :sparkles: update Invoice to v4.5
|
6
|
+
### Fixes
|
7
|
+
* :bug: fix invalid error codes
|
8
|
+
|
9
|
+
|
3
10
|
## v3.6.1 - 2024-03-07
|
4
11
|
### Changes
|
5
12
|
* :recycle: update error handling to account for future evolutions
|
data/docs/invoices_v4.md
CHANGED
@@ -34,12 +34,12 @@ puts result.document
|
|
34
34
|
########
|
35
35
|
Document
|
36
36
|
########
|
37
|
-
:Mindee ID:
|
37
|
+
:Mindee ID: a9062dd1-0d34-42ab-9505-0481a8545106
|
38
38
|
:Filename: default_sample.jpg
|
39
39
|
|
40
40
|
Inference
|
41
41
|
#########
|
42
|
-
:Product: mindee/invoices v4.
|
42
|
+
:Product: mindee/invoices v4.5
|
43
43
|
:Rotation applied: Yes
|
44
44
|
|
45
45
|
Prediction
|
@@ -65,6 +65,8 @@ Prediction
|
|
65
65
|
:Customer Name: JIRO DOI
|
66
66
|
:Customer Company Registrations:
|
67
67
|
:Customer Address: 1954 Bloor Street West Toronto, ON, M6P 3K9 Canada
|
68
|
+
:Shipping Address:
|
69
|
+
:Billing Address: 1954 Bloor Street West Toronto, ON, M6P 3K9 Canada
|
68
70
|
:Document Type: INVOICE
|
69
71
|
:Line Items:
|
70
72
|
+--------------------------------------+--------------+----------+------------+--------------+--------------+------------+
|
@@ -103,6 +105,8 @@ Page 0
|
|
103
105
|
:Customer Name: JIRO DOI
|
104
106
|
:Customer Company Registrations:
|
105
107
|
:Customer Address: 1954 Bloor Street West Toronto, ON, M6P 3K9 Canada
|
108
|
+
:Shipping Address:
|
109
|
+
:Billing Address: 1954 Bloor Street West Toronto, ON, M6P 3K9 Canada
|
106
110
|
:Document Type: INVOICE
|
107
111
|
:Line Items:
|
108
112
|
+--------------------------------------+--------------+----------+------------+--------------+--------------+------------+
|
@@ -205,6 +209,13 @@ A `InvoiceV4LineItem` implements the following attributes:
|
|
205
209
|
# Attributes
|
206
210
|
The following fields are extracted for Invoice V4:
|
207
211
|
|
212
|
+
## Billing Address
|
213
|
+
**billing_address** ([StringField](#string-field)): The customer's address used for billing.
|
214
|
+
|
215
|
+
```rb
|
216
|
+
puts result.document.inference.prediction.billing_address.value
|
217
|
+
```
|
218
|
+
|
208
219
|
## Customer Address
|
209
220
|
**customer_address** ([StringField](#string-field)): The address of the customer.
|
210
221
|
|
@@ -281,6 +292,13 @@ for reference_numbers_elem in result.document.inference.prediction.reference_num
|
|
281
292
|
end
|
282
293
|
```
|
283
294
|
|
295
|
+
## Shipping Address
|
296
|
+
**shipping_address** ([StringField](#string-field)): Customer's delivery address.
|
297
|
+
|
298
|
+
```rb
|
299
|
+
puts result.document.inference.prediction.shipping_address.value
|
300
|
+
```
|
301
|
+
|
284
302
|
## Supplier Address
|
285
303
|
**supplier_address** ([StringField](#string-field)): The address of the supplier or merchant.
|
286
304
|
|
data/lib/mindee/client.rb
CHANGED
@@ -138,9 +138,9 @@ module Mindee
|
|
138
138
|
# * `:on_min_pages` Apply the operation only if document has at least this many pages.
|
139
139
|
# @param cropper [Boolean, nil] Whether to include cropper results for each page.
|
140
140
|
# This performs a cropping operation on the server and will increase response time.
|
141
|
-
# @param initial_delay_sec [Integer, Float
|
142
|
-
# @param delay_sec [Integer, Float
|
143
|
-
# @param max_retries [Integer
|
141
|
+
# @param initial_delay_sec [Integer, Float] initial delay before polling. Defaults to 4.
|
142
|
+
# @param delay_sec [Integer, Float] delay between polling attempts. Defaults to 2.
|
143
|
+
# @param max_retries [Integer] maximum amount of retries. Defaults to 60.
|
144
144
|
# @return [Mindee::Parsing::Common::ApiResponse]
|
145
145
|
def enqueue_and_parse(
|
146
146
|
input_source,
|
@@ -167,7 +167,7 @@ module Mindee
|
|
167
167
|
polling_attempts = 1
|
168
168
|
job_id = enqueue_res.job.id
|
169
169
|
queue_res = parse_queued(job_id, product_class, endpoint: endpoint)
|
170
|
-
while
|
170
|
+
while queue_res.job.status != Mindee::Parsing::Common::JobStatus::COMPLETED && polling_attempts < max_retries
|
171
171
|
sleep(delay_sec)
|
172
172
|
queue_res = parse_queued(job_id, product_class, endpoint: endpoint)
|
173
173
|
polling_attempts += 1
|
data/lib/mindee/http/error.rb
CHANGED
@@ -8,10 +8,22 @@ module Mindee
|
|
8
8
|
module Error
|
9
9
|
module_function
|
10
10
|
|
11
|
+
# Extracts the HTTP error from the response hash, or the job error if there is one.
|
12
|
+
# @param response [Hash] dictionary response retrieved by the server
|
13
|
+
def extract_error(response)
|
14
|
+
return unless response.respond_to?(:each_pair)
|
15
|
+
|
16
|
+
if !response.dig('api_request', 'error').empty?
|
17
|
+
response.dig('api_request', 'error')
|
18
|
+
elsif !response.dig('job', 'error').empty?
|
19
|
+
response.dig('job', 'error')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
11
23
|
# Creates an error object based on what's retrieved from a request.
|
12
24
|
# @param response [Hash] dictionary response retrieved by the server
|
13
25
|
def create_error_obj(response)
|
14
|
-
error_obj =
|
26
|
+
error_obj = extract_error(response)
|
15
27
|
if error_obj.nil?
|
16
28
|
error_obj = if response.include?('Maximum pdf pages')
|
17
29
|
{
|
@@ -31,6 +31,9 @@ module Mindee
|
|
31
31
|
return false unless (200..302).cover?(response.code.to_i)
|
32
32
|
|
33
33
|
hashed_response = JSON.parse(response.body, object_class: Hash)
|
34
|
+
|
35
|
+
return false if hashed_response.dig('job', 'status') == Mindee::Parsing::Common::JobStatus::FAILURE
|
36
|
+
|
34
37
|
return false if hashed_response.dig('job', 'error') && !hashed_response.dig('job', 'error').empty?
|
35
38
|
|
36
39
|
true
|
@@ -41,13 +44,15 @@ module Mindee
|
|
41
44
|
def self.clean_request!(response)
|
42
45
|
return response if (response.code.to_i < 200) || (response.code.to_i > 302)
|
43
46
|
|
44
|
-
return response
|
47
|
+
return response if response.body.empty?
|
45
48
|
|
46
49
|
hashed_response = JSON.parse(response.body, object_class: Hash)
|
47
50
|
if hashed_response.dig('api_request', 'status_code').to_i > 399
|
48
51
|
response.instance_variable_set(:@code, hashed_response['api_request']['status_code'].to_s)
|
49
52
|
end
|
50
|
-
|
53
|
+
|
54
|
+
return if !hashed_response.dig('job', 'error').empty? &&
|
55
|
+
(hashed_response.dig('job', 'status') != Mindee::Parsing::Common::JobStatus::FAILURE.to_s)
|
51
56
|
|
52
57
|
response.instance_variable_set(:@code, '500')
|
53
58
|
end
|
@@ -9,6 +9,9 @@ module Mindee
|
|
9
9
|
# Invoice V4 document prediction.
|
10
10
|
class InvoiceV4Document < Mindee::Parsing::Common::Prediction
|
11
11
|
include Mindee::Parsing::Standard
|
12
|
+
# The customer's address used for billing.
|
13
|
+
# @return [Mindee::Parsing::Standard::StringField]
|
14
|
+
attr_reader :billing_address
|
12
15
|
# The address of the customer.
|
13
16
|
# @return [Mindee::Parsing::Standard::StringField]
|
14
17
|
attr_reader :customer_address
|
@@ -39,6 +42,9 @@ module Mindee
|
|
39
42
|
# List of Reference numbers, including PO number.
|
40
43
|
# @return [Array<Mindee::Parsing::Standard::StringField>]
|
41
44
|
attr_reader :reference_numbers
|
45
|
+
# Customer's delivery address.
|
46
|
+
# @return [Mindee::Parsing::Standard::StringField]
|
47
|
+
attr_reader :shipping_address
|
42
48
|
# The address of the supplier or merchant.
|
43
49
|
# @return [Mindee::Parsing::Standard::StringField]
|
44
50
|
attr_reader :supplier_address
|
@@ -68,6 +74,7 @@ module Mindee
|
|
68
74
|
# @param page_id [Integer, nil]
|
69
75
|
def initialize(prediction, page_id)
|
70
76
|
super()
|
77
|
+
@billing_address = StringField.new(prediction['billing_address'], page_id)
|
71
78
|
@customer_address = StringField.new(prediction['customer_address'], page_id)
|
72
79
|
@customer_company_registrations = []
|
73
80
|
prediction['customer_company_registrations'].each do |item|
|
@@ -87,6 +94,7 @@ module Mindee
|
|
87
94
|
prediction['reference_numbers'].each do |item|
|
88
95
|
@reference_numbers.push(StringField.new(item, page_id))
|
89
96
|
end
|
97
|
+
@shipping_address = StringField.new(prediction['shipping_address'], page_id)
|
90
98
|
@supplier_address = StringField.new(prediction['supplier_address'], page_id)
|
91
99
|
@supplier_company_registrations = []
|
92
100
|
prediction['supplier_company_registrations'].each do |item|
|
@@ -127,6 +135,8 @@ module Mindee
|
|
127
135
|
out_str << "\n:Customer Name: #{@customer_name}".rstrip
|
128
136
|
out_str << "\n:Customer Company Registrations: #{customer_company_registrations}".rstrip
|
129
137
|
out_str << "\n:Customer Address: #{@customer_address}".rstrip
|
138
|
+
out_str << "\n:Shipping Address: #{@shipping_address}".rstrip
|
139
|
+
out_str << "\n:Billing Address: #{@billing_address}".rstrip
|
130
140
|
out_str << "\n:Document Type: #{@document_type}".rstrip
|
131
141
|
out_str << "\n:Line Items:"
|
132
142
|
out_str << line_items
|
data/lib/mindee/version.rb
CHANGED
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: 3.
|
4
|
+
version: 3.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mindee, SA
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03-
|
11
|
+
date: 2024-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: marcel
|