mindee 3.15.0 → 3.17.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.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +18 -0
  3. data/bin/mindee.rb +20 -2
  4. data/docs/business_card_v1.md +169 -0
  5. data/docs/code_samples/{international_id_v1_async.txt → business_card_v1_async.txt} +1 -1
  6. data/docs/code_samples/delivery_notes_v1_async.txt +19 -0
  7. data/docs/code_samples/driver_license_v1_async.txt +19 -0
  8. data/docs/code_samples/expense_receipts_v5_async.txt +19 -0
  9. data/docs/code_samples/french_healthcard_v1_async.txt +19 -0
  10. data/docs/code_samples/ind_passport_v1_async.txt +19 -0
  11. data/docs/code_samples/payslip_fra_v3_async.txt +19 -0
  12. data/docs/code_samples/workflow_execution.txt +29 -0
  13. data/docs/delivery_notes_v1.md +143 -0
  14. data/docs/driver_license_v1.md +156 -0
  15. data/docs/energy_bill_fra_v1.md +2 -2
  16. data/docs/expense_receipts_v5.md +27 -2
  17. data/docs/financial_document_v1.md +8 -4
  18. data/docs/{carte_vitale_v1.md → french_healthcard_v1.md} +14 -24
  19. data/docs/ind_passport_v1.md +281 -0
  20. data/docs/invoices_v4.md +12 -8
  21. data/docs/payslip_fra_v3.md +319 -0
  22. data/docs/resume_v1.md +17 -16
  23. data/lib/mindee/client.rb +48 -8
  24. data/lib/mindee/http/workflow_endpoint.rb +90 -0
  25. data/lib/mindee/http.rb +1 -0
  26. data/lib/mindee/parsing/common/api_response.rb +22 -1
  27. data/lib/mindee/parsing/common/execution.rb +73 -0
  28. data/lib/mindee/parsing/common/execution_file.rb +24 -0
  29. data/lib/mindee/parsing/common/execution_priority.rb +30 -0
  30. data/lib/mindee/parsing/common.rb +3 -0
  31. data/lib/mindee/product/{international_id/international_id_v1.rb → business_card/business_card_v1.rb} +9 -9
  32. data/lib/mindee/product/business_card/business_card_v1_document.rb +85 -0
  33. data/lib/mindee/product/{international_id/international_id_v1_page.rb → business_card/business_card_v1_page.rb} +7 -7
  34. data/lib/mindee/product/delivery_note/delivery_note_v1.rb +39 -0
  35. data/lib/mindee/product/delivery_note/delivery_note_v1_document.rb +61 -0
  36. data/lib/mindee/product/delivery_note/delivery_note_v1_page.rb +32 -0
  37. data/lib/mindee/product/driver_license/driver_license_v1.rb +39 -0
  38. data/lib/mindee/product/driver_license/driver_license_v1_document.rb +91 -0
  39. data/lib/mindee/product/driver_license/driver_license_v1_page.rb +32 -0
  40. data/lib/mindee/product/financial_document/financial_document_v1_document.rb +1 -1
  41. data/lib/mindee/product/financial_document/financial_document_v1_page.rb +1 -1
  42. data/lib/mindee/product/fr/health_card/health_card_v1.rb +41 -0
  43. data/lib/mindee/product/fr/health_card/health_card_v1_document.rb +52 -0
  44. data/lib/mindee/product/fr/health_card/health_card_v1_page.rb +34 -0
  45. data/lib/mindee/product/fr/payslip/payslip_v3.rb +41 -0
  46. data/lib/mindee/product/fr/payslip/payslip_v3_bank_account_detail.rb +54 -0
  47. data/lib/mindee/product/fr/payslip/payslip_v3_document.rb +166 -0
  48. data/lib/mindee/product/fr/payslip/payslip_v3_employee.rb +78 -0
  49. data/lib/mindee/product/fr/payslip/payslip_v3_employer.rb +78 -0
  50. data/lib/mindee/product/fr/payslip/payslip_v3_employment.rb +78 -0
  51. data/lib/mindee/product/fr/payslip/payslip_v3_page.rb +34 -0
  52. data/lib/mindee/product/fr/payslip/payslip_v3_paid_time_off.rb +89 -0
  53. data/lib/mindee/product/fr/payslip/payslip_v3_pay_detail.rb +100 -0
  54. data/lib/mindee/product/fr/payslip/payslip_v3_pay_period.rb +66 -0
  55. data/lib/mindee/product/fr/payslip/payslip_v3_salary_detail.rb +89 -0
  56. data/lib/mindee/product/ind/indian_passport/indian_passport_v1.rb +41 -0
  57. data/lib/mindee/product/ind/indian_passport/indian_passport_v1_document.rb +143 -0
  58. data/lib/mindee/product/ind/indian_passport/indian_passport_v1_page.rb +34 -0
  59. data/lib/mindee/product/invoice/invoice_v4_document.rb +1 -1
  60. data/lib/mindee/product/invoice/invoice_v4_page.rb +1 -1
  61. data/lib/mindee/product/resume/resume_v1_document.rb +3 -1
  62. data/lib/mindee/product/resume/resume_v1_page.rb +1 -1
  63. data/lib/mindee/product/resume/resume_v1_professional_experience.rb +8 -0
  64. data/lib/mindee/product.rb +13 -8
  65. data/lib/mindee/version.rb +1 -1
  66. metadata +46 -10
  67. data/docs/eu_driver_license_v1.md +0 -227
  68. data/docs/proof_of_address_v1.md +0 -211
  69. data/docs/us_driver_license_v1.md +0 -272
  70. data/lib/mindee/product/international_id/international_id_v1_document.rb +0 -109
@@ -0,0 +1,319 @@
1
+ ---
2
+ title: FR Payslip OCR Ruby
3
+ category: 622b805aaec68102ea7fcbc2
4
+ slug: ruby-fr-payslip-ocr
5
+ parentDoc: 6294d97ee723f1008d2ab28e
6
+ ---
7
+ The Ruby OCR SDK supports the [Payslip API](https://platform.mindee.com/mindee/payslip_fra).
8
+
9
+ Using the [sample below](https://github.com/mindee/client-lib-test-data/blob/main/products/payslip_fra/default_sample.jpg), we are going to illustrate how to extract the data that we want using the OCR SDK.
10
+ ![Payslip sample](https://github.com/mindee/client-lib-test-data/blob/main/products/payslip_fra/default_sample.jpg?raw=true)
11
+
12
+ # Quick-Start
13
+ ```rb
14
+ require 'mindee'
15
+
16
+ # Init a new client
17
+ mindee_client = Mindee::Client.new(api_key: 'my-api-key')
18
+
19
+ # Load a file from disk
20
+ input_source = mindee_client.source_from_path('/path/to/the/file.ext')
21
+
22
+ # Parse the file
23
+ result = mindee_client.enqueue_and_parse(
24
+ input_source,
25
+ Mindee::Product::FR::Payslip::PayslipV3
26
+ )
27
+
28
+ # Print a full summary of the parsed data in RST format
29
+ puts result.document
30
+
31
+ # Print the document-level parsed data
32
+ # puts result.document.inference.prediction
33
+
34
+ ```
35
+
36
+ **Output (RST):**
37
+ ```rst
38
+ ########
39
+ Document
40
+ ########
41
+ :Mindee ID: a479e3e7-6838-4e82-9a7d-99289f34ec7f
42
+ :Filename: default_sample.jpg
43
+
44
+ Inference
45
+ #########
46
+ :Product: mindee/payslip_fra v3.0
47
+ :Rotation applied: Yes
48
+
49
+ Prediction
50
+ ==========
51
+ :Pay Period:
52
+ :End Date: 2023-03-31
53
+ :Month: 03
54
+ :Payment Date: 2023-03-29
55
+ :Start Date: 2023-03-01
56
+ :Year: 2023
57
+ :Employee:
58
+ :Address: 52 RUE DES FLEURS 33500 LIBOURNE FRANCE
59
+ :Date of Birth:
60
+ :First Name: Jean Luc
61
+ :Last Name: Picard
62
+ :Phone Number:
63
+ :Registration Number:
64
+ :Social Security Number: 123456789012345
65
+ :Employer:
66
+ :Address: 1 RUE DU TONNOT 25210 DOUBS
67
+ :Company ID: 12345678901234
68
+ :Company Site:
69
+ :NAF Code: 1234A
70
+ :Name: DEMO COMPANY
71
+ :Phone Number:
72
+ :URSSAF Number:
73
+ :Bank Account Details:
74
+ :Bank Name:
75
+ :IBAN:
76
+ :SWIFT:
77
+ :Employment:
78
+ :Category: Cadre
79
+ :Coefficient: 600,000
80
+ :Collective Agreement: Construction -- Promotion
81
+ :Job Title: Directeur Régional du Développement
82
+ :Position Level: Niveau 5 Echelon 3
83
+ :Seniority Date:
84
+ :Start Date: 2022-05-01
85
+ :Salary Details:
86
+ +--------------+-----------+--------------------------------------+--------+-----------+
87
+ | Amount | Base | Description | Number | Rate |
88
+ +==============+===========+======================================+========+===========+
89
+ | 6666.67 | | Salaire de base | | |
90
+ +--------------+-----------+--------------------------------------+--------+-----------+
91
+ | 9.30 | | Part patronale Mutuelle NR | | |
92
+ +--------------+-----------+--------------------------------------+--------+-----------+
93
+ | 508.30 | | Avantages en nature voiture | | |
94
+ +--------------+-----------+--------------------------------------+--------+-----------+
95
+ :Pay Detail:
96
+ :Gross Salary: 7184.27
97
+ :Gross Salary YTD: 18074.81
98
+ :Income Tax Rate: 17.60
99
+ :Income Tax Withheld: 1030.99
100
+ :Net Paid: 3868.32
101
+ :Net Paid Before Tax: 4899.31
102
+ :Net Taxable: 5857.90
103
+ :Net Taxable YTD: 14752.73
104
+ :Total Cost Employer: 10486.94
105
+ :Total Taxes and Deductions: 1650.36
106
+ :Paid Time Off:
107
+ +-----------+--------+-------------+-----------+-----------+
108
+ | Accrued | Period | Type | Remaining | Used |
109
+ +===========+========+=============+===========+===========+
110
+ | | N-1 | VACATION | | |
111
+ +-----------+--------+-------------+-----------+-----------+
112
+ | 6.17 | N | VACATION | 6.17 | |
113
+ +-----------+--------+-------------+-----------+-----------+
114
+ | 2.01 | N | RTT | 2.01 | |
115
+ +-----------+--------+-------------+-----------+-----------+
116
+ ```
117
+
118
+ # Field Types
119
+ ## Standard Fields
120
+ These fields are generic and used in several products.
121
+
122
+ ### Basic Field
123
+ Each prediction object contains a set of fields that inherit from the generic `Field` class.
124
+ A typical `Field` object will have the following attributes:
125
+
126
+ * **value** (`String`, `Float`, `Integer`, `Boolean`): corresponds to the field value. Can be `nil` if no value was extracted.
127
+ * **confidence** (Float, nil): the confidence score of the field prediction.
128
+ * **bounding_box** (`Mindee::Geometry::Quadrilateral`, `nil`): contains exactly 4 relative vertices (points) coordinates of a right rectangle containing the field in the document.
129
+ * **polygon** (`Mindee::Geometry::Polygon`, `nil`): contains the relative vertices coordinates (`Point`) of a polygon containing the field in the image.
130
+ * **page_id** (`Integer`, `nil`): the ID of the page, always `nil` when at document-level.
131
+ * **reconstructed** (`Boolean`): indicates whether an object was reconstructed (not extracted as the API gave it).
132
+
133
+
134
+ Aside from the previous attributes, all basic fields have access to a `to_s` method that can be used to print their value as a string.
135
+
136
+ ## Specific Fields
137
+ Fields which are specific to this product; they are not used in any other product.
138
+
139
+ ### Bank Account Details Field
140
+ Information about the employee's bank account.
141
+
142
+ A `PayslipV3BankAccountDetail` implements the following attributes:
143
+
144
+ * `bank_name` (String): The name of the bank.
145
+ * `iban` (String): The IBAN of the bank account.
146
+ * `swift` (String): The SWIFT code of the bank.
147
+ Fields which are specific to this product; they are not used in any other product.
148
+
149
+ ### Employee Field
150
+ Information about the employee.
151
+
152
+ A `PayslipV3Employee` implements the following attributes:
153
+
154
+ * `address` (String): The address of the employee.
155
+ * `date_of_birth` (String): The date of birth of the employee.
156
+ * `first_name` (String): The first name of the employee.
157
+ * `last_name` (String): The last name of the employee.
158
+ * `phone_number` (String): The phone number of the employee.
159
+ * `registration_number` (String): The registration number of the employee.
160
+ * `social_security_number` (String): The social security number of the employee.
161
+ Fields which are specific to this product; they are not used in any other product.
162
+
163
+ ### Employer Field
164
+ Information about the employer.
165
+
166
+ A `PayslipV3Employer` implements the following attributes:
167
+
168
+ * `address` (String): The address of the employer.
169
+ * `company_id` (String): The company ID of the employer.
170
+ * `company_site` (String): The site of the company.
171
+ * `naf_code` (String): The NAF code of the employer.
172
+ * `name` (String): The name of the employer.
173
+ * `phone_number` (String): The phone number of the employer.
174
+ * `urssaf_number` (String): The URSSAF number of the employer.
175
+ Fields which are specific to this product; they are not used in any other product.
176
+
177
+ ### Employment Field
178
+ Information about the employment.
179
+
180
+ A `PayslipV3Employment` implements the following attributes:
181
+
182
+ * `category` (String): The category of the employment.
183
+ * `coefficient` (String): The coefficient of the employment.
184
+ * `collective_agreement` (String): The collective agreement of the employment.
185
+ * `job_title` (String): The job title of the employee.
186
+ * `position_level` (String): The position level of the employment.
187
+ * `seniority_date` (String): The seniority date of the employment.
188
+ * `start_date` (String): The start date of the employment.
189
+ Fields which are specific to this product; they are not used in any other product.
190
+
191
+ ### Paid Time Off Field
192
+ Information about paid time off.
193
+
194
+ A `PayslipV3PaidTimeOff` implements the following attributes:
195
+
196
+ * `accrued` (Float): The amount of paid time off accrued in the period.
197
+ * `period` (String): The paid time off period.
198
+
199
+ #### Possible values include:
200
+ - N
201
+ - N-1
202
+ - N-2
203
+
204
+ * `pto_type` (String): The type of paid time off.
205
+
206
+ #### Possible values include:
207
+ - VACATION
208
+ - RTT
209
+ - COMPENSATORY
210
+
211
+ * `remaining` (Float): The remaining amount of paid time off at the end of the period.
212
+ * `used` (Float): The amount of paid time off used in the period.
213
+ Fields which are specific to this product; they are not used in any other product.
214
+
215
+ ### Pay Detail Field
216
+ Detailed information about the pay.
217
+
218
+ A `PayslipV3PayDetail` implements the following attributes:
219
+
220
+ * `gross_salary` (Float): The gross salary of the employee.
221
+ * `gross_salary_ytd` (Float): The year-to-date gross salary of the employee.
222
+ * `income_tax_rate` (Float): The income tax rate of the employee.
223
+ * `income_tax_withheld` (Float): The income tax withheld from the employee's pay.
224
+ * `net_paid` (Float): The net paid amount of the employee.
225
+ * `net_paid_before_tax` (Float): The net paid amount before tax of the employee.
226
+ * `net_taxable` (Float): The net taxable amount of the employee.
227
+ * `net_taxable_ytd` (Float): The year-to-date net taxable amount of the employee.
228
+ * `total_cost_employer` (Float): The total cost to the employer.
229
+ * `total_taxes_and_deductions` (Float): The total taxes and deductions of the employee.
230
+ Fields which are specific to this product; they are not used in any other product.
231
+
232
+ ### Pay Period Field
233
+ Information about the pay period.
234
+
235
+ A `PayslipV3PayPeriod` implements the following attributes:
236
+
237
+ * `end_date` (String): The end date of the pay period.
238
+ * `month` (String): The month of the pay period.
239
+ * `payment_date` (String): The date of payment for the pay period.
240
+ * `start_date` (String): The start date of the pay period.
241
+ * `year` (String): The year of the pay period.
242
+ Fields which are specific to this product; they are not used in any other product.
243
+
244
+ ### Salary Details Field
245
+ Detailed information about the earnings.
246
+
247
+ A `PayslipV3SalaryDetail` implements the following attributes:
248
+
249
+ * `amount` (Float): The amount of the earning.
250
+ * `base` (Float): The base rate value of the earning.
251
+ * `description` (String): The description of the earnings.
252
+ * `number` (Float): The number of units in the earning.
253
+ * `rate` (Float): The rate of the earning.
254
+
255
+ # Attributes
256
+ The following fields are extracted for Payslip V3:
257
+
258
+ ## Bank Account Details
259
+ **bank_account_details** ([PayslipV3BankAccountDetail](#bank-account-details-field)): Information about the employee's bank account.
260
+
261
+ ```rb
262
+ puts result.document.inference.prediction.bank_account_details.value
263
+ ```
264
+
265
+ ## Employee
266
+ **employee** ([PayslipV3Employee](#employee-field)): Information about the employee.
267
+
268
+ ```rb
269
+ puts result.document.inference.prediction.employee.value
270
+ ```
271
+
272
+ ## Employer
273
+ **employer** ([PayslipV3Employer](#employer-field)): Information about the employer.
274
+
275
+ ```rb
276
+ puts result.document.inference.prediction.employer.value
277
+ ```
278
+
279
+ ## Employment
280
+ **employment** ([PayslipV3Employment](#employment-field)): Information about the employment.
281
+
282
+ ```rb
283
+ puts result.document.inference.prediction.employment.value
284
+ ```
285
+
286
+ ## Paid Time Off
287
+ **paid_time_off** (Array<[PayslipV3PaidTimeOff](#paid-time-off-field)>): Information about paid time off.
288
+
289
+ ```rb
290
+ for paid_time_off_elem in result.document.inference.prediction.paid_time_off do
291
+ puts paid_time_off_elem.value
292
+ end
293
+ ```
294
+
295
+ ## Pay Detail
296
+ **pay_detail** ([PayslipV3PayDetail](#pay-detail-field)): Detailed information about the pay.
297
+
298
+ ```rb
299
+ puts result.document.inference.prediction.pay_detail.value
300
+ ```
301
+
302
+ ## Pay Period
303
+ **pay_period** ([PayslipV3PayPeriod](#pay-period-field)): Information about the pay period.
304
+
305
+ ```rb
306
+ puts result.document.inference.prediction.pay_period.value
307
+ ```
308
+
309
+ ## Salary Details
310
+ **salary_details** (Array<[PayslipV3SalaryDetail](#salary-details-field)>): Detailed information about the earnings.
311
+
312
+ ```rb
313
+ for salary_details_elem in result.document.inference.prediction.salary_details do
314
+ puts salary_details_elem.value
315
+ end
316
+ ```
317
+
318
+ # Questions?
319
+ [Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g)
data/docs/resume_v1.md CHANGED
@@ -38,13 +38,13 @@ puts result.document
38
38
  ########
39
39
  Document
40
40
  ########
41
- :Mindee ID: bc80bae0-af75-4464-95a9-2419403c75bf
41
+ :Mindee ID: 9daa3085-152c-454e-9245-636f13fc9dc3
42
42
  :Filename: default_sample.jpg
43
43
 
44
44
  Inference
45
45
  #########
46
- :Product: mindee/resume v1.0
47
- :Rotation applied: No
46
+ :Product: mindee/resume v1.1
47
+ :Rotation applied: Yes
48
48
 
49
49
  Prediction
50
50
  ==========
@@ -54,8 +54,8 @@ Prediction
54
54
  :Surnames: Morgan
55
55
  :Nationality:
56
56
  :Email Address: christoper.m@gmail.com
57
- :Phone Number: +44 (0) 20 7666 8555
58
- :Address: 177 Great Portland Street, London W5W 6PQ
57
+ :Phone Number: +44 (0)20 7666 8555
58
+ :Address: 177 Great Portland Street, London, W5W 6PQ
59
59
  :Social Networks:
60
60
  +----------------------+----------------------------------------------------+
61
61
  | Name | URL |
@@ -72,38 +72,37 @@ Prediction
72
72
  +----------+----------------------+
73
73
  | ZHO | Beginner |
74
74
  +----------+----------------------+
75
- | DEU | Intermediate |
75
+ | DEU | Beginner |
76
76
  +----------+----------------------+
77
77
  :Hard Skills: HTML5
78
78
  PHP OOP
79
79
  JavaScript
80
80
  CSS
81
81
  MySQL
82
+ SQL
82
83
  :Soft Skills: Project management
84
+ Creative design
83
85
  Strong decision maker
84
86
  Innovative
85
87
  Complex problem solver
86
- Creative design
87
88
  Service-focused
88
89
  :Education:
89
90
  +-----------------+---------------------------+-----------+----------+---------------------------+-------------+------------+
90
91
  | Domain | Degree | End Month | End Year | School | Start Month | Start Year |
91
92
  +=================+===========================+===========+==========+===========================+=============+============+
92
- | Computer Inf... | Bachelor | | | Columbia University, NY | | 2014 |
93
+ | Computer Inf... | Bachelor | | 2014 | Columbia University, NY | | |
93
94
  +-----------------+---------------------------+-----------+----------+---------------------------+-------------+------------+
94
95
  :Professional Experiences:
95
- +-----------------+------------+---------------------------+-----------+----------+----------------------+-------------+------------+
96
- | Contract Type | Department | Employer | End Month | End Year | Role | Start Month | Start Year |
97
- +=================+============+===========================+===========+==========+======================+=============+============+
98
- | Full-Time | | Luna Web Design, New York | 05 | 2019 | Web Developer | 09 | 2015 |
99
- +-----------------+------------+---------------------------+-----------+----------+----------------------+-------------+------------+
96
+ +-----------------+------------+--------------------------------------+---------------------------+-----------+----------+----------------------+-------------+------------+
97
+ | Contract Type | Department | Description | Employer | End Month | End Year | Role | Start Month | Start Year |
98
+ +=================+============+======================================+===========================+===========+==========+======================+=============+============+
99
+ | | | Cooperate with designers to creat... | Luna Web Design, New York | 05 | 2019 | Web Developer | 09 | 2015 |
100
+ +-----------------+------------+--------------------------------------+---------------------------+-----------+----------+----------------------+-------------+------------+
100
101
  :Certificates:
101
102
  +------------+--------------------------------+---------------------------+------+
102
103
  | Grade | Name | Provider | Year |
103
104
  +============+================================+===========================+======+
104
- | | PHP Framework (certificate)... | | 2014 |
105
- +------------+--------------------------------+---------------------------+------+
106
- | | Programming Languages: Java... | | |
105
+ | | PHP Framework (certificate)... | | |
107
106
  +------------+--------------------------------+---------------------------+------+
108
107
  ```
109
108
 
@@ -171,6 +170,7 @@ A `ResumeV1Language` implements the following attributes:
171
170
  * `level` (String): The candidate's level for the language.
172
171
 
173
172
  #### Possible values include:
173
+ - Native
174
174
  - Fluent
175
175
  - Proficient
176
176
  - Intermediate
@@ -192,6 +192,7 @@ A `ResumeV1ProfessionalExperience` implements the following attributes:
192
192
  - Freelance
193
193
 
194
194
  * `department` (String): The specific department or division within the company.
195
+ * `description` (String): The description of the professional experience as written in the document.
195
196
  * `employer` (String): The name of the company or organization.
196
197
  * `end_month` (String): The month when the professional experience ended.
197
198
  * `end_year` (String): The year when the professional experience ended.
data/lib/mindee/client.rb CHANGED
@@ -149,8 +149,8 @@ module Mindee
149
149
  # * `:on_min_pages` Apply the operation only if document has at least this many pages.
150
150
  # @param cropper [Boolean, nil] Whether to include cropper results for each page.
151
151
  # This performs a cropping operation on the server and will increase response time.
152
- # @param initial_delay_sec [Integer, Float] initial delay before polling. Defaults to 4.
153
- # @param delay_sec [Integer, Float] delay between polling attempts. Defaults to 2.
152
+ # @param initial_delay_sec [Integer, Float] initial delay before polling. Defaults to 2.
153
+ # @param delay_sec [Integer, Float] delay between polling attempts. Defaults to 1.5.
154
154
  # @param max_retries [Integer] maximum amount of retries. Defaults to 60.
155
155
  # @return [Mindee::Parsing::Common::ApiResponse]
156
156
  def enqueue_and_parse(
@@ -162,8 +162,8 @@ module Mindee
162
162
  close_file: true,
163
163
  page_options: nil,
164
164
  cropper: false,
165
- initial_delay_sec: 4,
166
- delay_sec: 2,
165
+ initial_delay_sec: 2,
166
+ delay_sec: 1.5,
167
167
  max_retries: 60
168
168
  )
169
169
  enqueue_res = enqueue(
@@ -195,6 +195,46 @@ module Mindee
195
195
 
196
196
  # rubocop:enable Metrics/ParameterLists
197
197
 
198
+ # Sends a document to a workflow.
199
+ #
200
+ # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::UrlInputSource]
201
+ # @param document_alias [String, nil] Alias to give to the document.
202
+ # @param priority [Symbol, nil] Priority to give to the document.
203
+ # @param full_text [Boolean] Whether to include the full OCR text response in compatible APIs.
204
+ # This performs a full OCR operation on the server and may increase response time.
205
+ #
206
+ # @param public_url [String, nil] A unique, encrypted URL for accessing the document validation interface without
207
+ # requiring authentication.
208
+ # @param page_options [Hash, nil] Page cutting/merge options:
209
+ #
210
+ # * `:page_indexes` Zero-based list of page indexes.
211
+ # * `:operation` Operation to apply on the document, given the `page_indexes specified:
212
+ # * `:KEEP_ONLY` - keep only the specified pages, and remove all others.
213
+ # * `:REMOVE` - remove the specified pages, and keep all others.
214
+ # * `:on_min_pages` Apply the operation only if document has at least this many pages.
215
+ #
216
+ #
217
+ # @return [Mindee::Parsing::Common::WorkflowResponse]
218
+ def execute_workflow(
219
+ input_source,
220
+ workflow_id,
221
+ document_alias: nil,
222
+ priority: nil,
223
+ full_text: false,
224
+ public_url: nil,
225
+ page_options: nil
226
+ )
227
+ if input_source.is_a?(Mindee::Input::Source::LocalInputSource) && !page_options.nil? && input_source.pdf?
228
+ input_source.process_pdf(page_options)
229
+ end
230
+
231
+ workflow_endpoint = Mindee::HTTP::WorkflowEndpoint.new(workflow_id, api_key: @api_key)
232
+ prediction, raw_http = workflow_endpoint.execute_workflow(input_source, full_text, document_alias, priority,
233
+ public_url)
234
+ Mindee::Parsing::Common::WorkflowResponse.new(Product::Generated::GeneratedV1,
235
+ prediction, raw_http)
236
+ end
237
+
198
238
  # Load a prediction.
199
239
  #
200
240
  # @param product_class [Mindee::Inference] class of the product
@@ -272,13 +312,13 @@ module Mindee
272
312
  # @param max_retries [Integer, nil] maximum amount of retries.
273
313
  def validate_async_params(initial_delay_sec, delay_sec, max_retries)
274
314
  min_delay_sec = 1
275
- min_initial_delay_sec = 2
315
+ min_initial_delay_sec = 1
276
316
  min_retries = 2
277
- raise "Cannot set auto-poll delay to less than #{min_delay_sec} seconds" if delay_sec < min_delay_sec
317
+ raise "Cannot set auto-poll delay to less than #{min_delay_sec} second(s)" if delay_sec < min_delay_sec
278
318
  if initial_delay_sec < min_initial_delay_sec
279
- raise "Cannot set initial parsing delay to less than #{min_initial_delay_sec} seconds"
319
+ raise "Cannot set initial parsing delay to less than #{min_initial_delay_sec} second(s)"
280
320
  end
281
- raise "Cannot set auto-poll delay to less than #{min_retries} seconds" if max_retries < min_retries
321
+ raise "Cannot set auto-poll retries to less than #{min_retries}" if max_retries < min_retries
282
322
  end
283
323
 
284
324
  # Creates an endpoint with the given values. Raises an error if the endpoint is invalid.
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'net/http'
5
+ require_relative 'error'
6
+
7
+ module Mindee
8
+ module HTTP
9
+ # Handles the routing for workflow calls.
10
+ class WorkflowEndpoint
11
+ # @return [String]
12
+ attr_reader :api_key
13
+ # @return [Integer]
14
+ attr_reader :request_timeout
15
+ # @return [String]
16
+ attr_reader :url
17
+
18
+ def initialize(workflow_id, api_key: '')
19
+ @request_timeout = ENV.fetch(REQUEST_TIMEOUT_ENV_NAME, TIMEOUT_DEFAULT).to_i
20
+ @api_key = api_key.nil? || api_key.empty? ? ENV.fetch(API_KEY_ENV_NAME, API_KEY_DEFAULT) : api_key
21
+ base_url = ENV.fetch(BASE_URL_ENV_NAME, BASE_URL_DEFAULT)
22
+ @url = "#{base_url.chomp('/')}/workflows/#{workflow_id}/executions"
23
+ end
24
+
25
+ # Sends a document to the workflow.
26
+ # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::UrlInputSource]
27
+ # @param document_alias [String, nil] Alias to give to the document.
28
+ # @param priority [Symbol, nil] Priority to give to the document.
29
+ # @param full_text [Boolean] Whether to include the full OCR text response in compatible APIs.
30
+ # @param public_url [String, nil] A unique, encrypted URL for accessing the document validation interface without
31
+ # requiring authentication.
32
+ # @return [Array]
33
+ def execute_workflow(input_source, full_text, document_alias, priority, public_url)
34
+ check_api_key
35
+ response = workflow_execution_req_post(input_source, document_alias, priority, full_text, public_url)
36
+ hashed_response = JSON.parse(response.body, object_class: Hash)
37
+ return [hashed_response, response.body] if ResponseValidation.valid_async_response?(response)
38
+
39
+ ResponseValidation.clean_request!(response)
40
+ error = Error.handle_error(@url_name, response)
41
+ raise error
42
+ end
43
+
44
+ # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::UrlInputSource]
45
+ # @param document_alias [String, nil] Alias to give to the document.
46
+ # @param priority [Symbol, nil] Priority to give to the document.
47
+ # @param full_text [Boolean] Whether to include the full OCR text response in compatible APIs.
48
+ # @param public_url [String, nil] A unique, encrypted URL for accessing the document validation interface without
49
+ # requiring authentication.
50
+ # @return [Net::HTTPResponse, nil]
51
+ def workflow_execution_req_post(input_source, document_alias, priority, full_text, public_url)
52
+ uri = URI(@url)
53
+ params = {}
54
+ params[:full_text_ocr] = 'true' if full_text
55
+ uri.query = URI.encode_www_form(params)
56
+
57
+ headers = {
58
+ 'Authorization' => "Token #{@api_key}",
59
+ 'User-Agent' => USER_AGENT,
60
+ }
61
+ req = Net::HTTP::Post.new(uri, headers)
62
+ form_data = if input_source.is_a?(Mindee::Input::Source::UrlInputSource)
63
+ [['document', input_source.url]]
64
+ else
65
+ [input_source.read_document]
66
+ end
67
+ form_data.push ['alias', document_alias] if document_alias
68
+ form_data.push ['public_url', public_url] if public_url
69
+ form_data.push ['priority', priority.to_s] if priority
70
+
71
+ req.set_form(form_data, 'multipart/form-data')
72
+
73
+ response = nil
74
+ Net::HTTP.start(uri.hostname, uri.port, use_ssl: true, read_timeout: @request_timeout) do |http|
75
+ response = http.request(req)
76
+ end
77
+ response
78
+ end
79
+
80
+ # Checks API key
81
+ def check_api_key
82
+ return unless @api_key.nil? || @api_key.empty?
83
+
84
+ raise "Missing API key. Check your Client Configuration.\n" \
85
+ 'You can set this using the ' \
86
+ "'#{HTTP::API_KEY_ENV_NAME}' environment variable."
87
+ end
88
+ end
89
+ end
90
+ end
data/lib/mindee/http.rb CHANGED
@@ -2,3 +2,4 @@
2
2
 
3
3
  require_relative 'http/endpoint'
4
4
  require_relative 'http/error'
5
+ require_relative 'http/workflow_endpoint'
@@ -32,7 +32,7 @@ module Mindee
32
32
  attr_reader :id
33
33
  # @return [Mindee::Parsing::Standard::DateField]
34
34
  attr_reader :issued_at
35
- # @return [Mindee::Parsing::Standard::DateField, nil]
35
+ # @return [Time, nil]
36
36
  attr_reader :available_at
37
37
  # @return [JobStatus, Symbol]
38
38
  attr_reader :status
@@ -121,6 +121,27 @@ module Mindee
121
121
  @job = Mindee::Parsing::Common::Job.new(http_response['job']) if http_response.key?('job')
122
122
  end
123
123
  end
124
+
125
+ # Represents the server response after a document is sent to a workflow.
126
+ class WorkflowResponse
127
+ # Set the prediction model used to parse the document.
128
+ # The response object will be instantiated based on this parameter.
129
+ # @return [Mindee::Parsing::Common::Execution]
130
+ attr_reader :execution
131
+ # @return [Mindee::Parsing::Common::ApiRequest]
132
+ attr_reader :api_request
133
+ # @return [String]
134
+ attr_reader :raw_http
135
+
136
+ # @param http_response [Hash]
137
+ # @param product_class [Mindee::Inference]
138
+ def initialize(product_class, http_response, raw_http)
139
+ @raw_http = raw_http.to_s
140
+ @api_request = Mindee::Parsing::Common::ApiRequest.new(http_response['api_request'])
141
+ product_class = (product_class || Product::Generated::GeneratedV1)
142
+ @execution = Mindee::Parsing::Common::Execution.new(product_class, http_response['execution'])
143
+ end
144
+ end
124
145
  end
125
146
  end
126
147
  end