mindee 4.5.0 → 4.7.0.pre.rc1

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 (316) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +17 -0
  3. data/README.md +21 -222
  4. data/docs/code_samples/default_v2.txt +28 -0
  5. data/docs/global_products/financial_document_v1.md +19 -4
  6. data/docs/global_products/invoices_v4.md +19 -4
  7. data/lib/mindee/client.rb +11 -30
  8. data/lib/mindee/client_v2.rb +109 -0
  9. data/lib/mindee/errors/mindee_http_error_v2.rb +26 -0
  10. data/lib/mindee/errors.rb +1 -0
  11. data/lib/mindee/geometry/point.rb +2 -2
  12. data/lib/mindee/geometry/quadrilateral.rb +4 -4
  13. data/lib/mindee/geometry/utils.rb +1 -0
  14. data/lib/mindee/http/api_settings_v2.rb +61 -0
  15. data/lib/mindee/http/endpoint.rb +12 -6
  16. data/lib/mindee/http/http_error_handler.rb +17 -4
  17. data/lib/mindee/http/mindee_api_v2.rb +148 -0
  18. data/lib/mindee/http/response_validation.rb +20 -1
  19. data/lib/mindee/http/workflow_endpoint.rb +2 -2
  20. data/lib/mindee/http.rb +2 -0
  21. data/lib/mindee/image/extracted_image.rb +1 -1
  22. data/lib/mindee/image/image_extractor.rb +10 -10
  23. data/lib/mindee/input/inference_parameters.rb +116 -0
  24. data/lib/mindee/input/local_response.rb +10 -1
  25. data/lib/mindee/input/polling_options.rb +26 -0
  26. data/lib/mindee/input/sources/base64_input_source.rb +2 -2
  27. data/lib/mindee/input/sources/local_input_source.rb +19 -12
  28. data/lib/mindee/input.rb +2 -0
  29. data/lib/mindee/page_options.rb +24 -0
  30. data/lib/mindee/parsing/common/api_request.rb +2 -2
  31. data/lib/mindee/parsing/common/api_response.rb +4 -0
  32. data/lib/mindee/parsing/common/execution.rb +1 -1
  33. data/lib/mindee/parsing/common/extras/extras.rb +2 -2
  34. data/lib/mindee/parsing/common/extras/rag_extra.rb +2 -0
  35. data/lib/mindee/parsing/common/inference.rb +1 -1
  36. data/lib/mindee/parsing/common/ocr/ocr.rb +4 -6
  37. data/lib/mindee/parsing/common/orientation.rb +2 -2
  38. data/lib/mindee/parsing/common/product.rb +6 -1
  39. data/lib/mindee/parsing/standard/address_field.rb +49 -0
  40. data/lib/mindee/parsing/standard/amount_field.rb +2 -2
  41. data/lib/mindee/parsing/standard/feature_field.rb +1 -1
  42. data/lib/mindee/parsing/standard/tax_field.rb +1 -1
  43. data/lib/mindee/parsing/standard.rb +1 -0
  44. data/lib/mindee/parsing/universal/universal_list_field.rb +2 -2
  45. data/lib/mindee/parsing/universal/universal_object_field.rb +7 -4
  46. data/lib/mindee/parsing/v2/common_response.rb +18 -0
  47. data/lib/mindee/parsing/v2/error_response.rb +36 -0
  48. data/lib/mindee/parsing/v2/field/base_field.rb +60 -0
  49. data/lib/mindee/parsing/v2/field/field_confidence.rb +91 -0
  50. data/lib/mindee/parsing/v2/field/field_location.rb +36 -0
  51. data/lib/mindee/parsing/v2/field/inference_fields.rb +96 -0
  52. data/lib/mindee/parsing/v2/field/list_field.rb +88 -0
  53. data/lib/mindee/parsing/v2/field/object_field.rb +102 -0
  54. data/lib/mindee/parsing/v2/field/simple_field.rb +56 -0
  55. data/lib/mindee/parsing/v2/field.rb +9 -0
  56. data/lib/mindee/parsing/v2/inference.rb +50 -0
  57. data/lib/mindee/parsing/v2/inference_file.rb +38 -0
  58. data/lib/mindee/parsing/v2/inference_model.rb +18 -0
  59. data/lib/mindee/parsing/v2/inference_response.rb +30 -0
  60. data/lib/mindee/parsing/v2/inference_result.rb +49 -0
  61. data/lib/mindee/parsing/v2/inference_result_options.rb +21 -0
  62. data/lib/mindee/parsing/v2/job.rb +86 -0
  63. data/lib/mindee/parsing/v2/job_response.rb +30 -0
  64. data/lib/mindee/parsing/v2/job_webhook.rb +60 -0
  65. data/lib/mindee/parsing/v2/raw_text.rb +21 -0
  66. data/lib/mindee/parsing/v2.rb +15 -0
  67. data/lib/mindee/pdf/extracted_pdf.rb +5 -3
  68. data/lib/mindee/pdf/pdf_extractor.rb +11 -7
  69. data/lib/mindee/pdf/pdf_processor.rb +6 -6
  70. data/lib/mindee/pdf/pdf_tools.rb +4 -2
  71. data/lib/mindee/product/financial_document/financial_document_v1_document.rb +8 -8
  72. data/lib/mindee/product/invoice/invoice_v4_document.rb +8 -8
  73. data/lib/mindee/product/universal/universal_prediction.rb +4 -4
  74. data/lib/mindee/version.rb +2 -2
  75. data/lib/mindee.rb +6 -0
  76. data/mindee.gemspec +1 -1
  77. data/sig/custom/mini_magick.rbs +14 -7
  78. data/sig/custom/net_http.rbs +4 -4
  79. data/sig/custom/origami.rbs +9 -4
  80. data/sig/mindee/client.rbs +14 -19
  81. data/sig/mindee/client_v2.rbs +17 -0
  82. data/sig/mindee/errors/mindee_http_error.rbs +6 -5
  83. data/sig/mindee/errors/mindee_http_error_v2.rbs +12 -0
  84. data/sig/mindee/errors/mindee_input_error.rbs +3 -2
  85. data/sig/mindee/geometry/min_max.rbs +4 -3
  86. data/sig/mindee/geometry/point.rbs +5 -6
  87. data/sig/mindee/geometry/polygon.rbs +3 -3
  88. data/sig/mindee/geometry/quadrilateral.rbs +5 -8
  89. data/sig/mindee/geometry/utils.rbs +8 -8
  90. data/sig/mindee/http/api_settings_v2.rbs +23 -0
  91. data/sig/mindee/http/endpoint.rbs +12 -11
  92. data/sig/mindee/http/http_error_handler.rbs +8 -3
  93. data/sig/mindee/http/mindee_api_v2.rbs +18 -0
  94. data/sig/mindee/http/response_validation.rbs +1 -0
  95. data/sig/mindee/http/workflow_endpoint.rbs +1 -1
  96. data/sig/mindee/image/extracted_image.rbs +2 -2
  97. data/sig/mindee/image/image_compressor.rbs +1 -1
  98. data/sig/mindee/image/image_extractor.rbs +5 -5
  99. data/sig/mindee/image/image_utils.rbs +10 -10
  100. data/sig/mindee/input/inference_parameters.rbs +30 -0
  101. data/sig/mindee/input/local_response.rbs +6 -5
  102. data/sig/mindee/input/polling_options.rbs +12 -0
  103. data/sig/mindee/input/sources/base64_input_source.rbs +1 -1
  104. data/sig/mindee/input/sources/local_input_source.rbs +10 -7
  105. data/sig/mindee/input/sources/url_input_source.rbs +1 -1
  106. data/sig/mindee/logging/logger.rbs +2 -0
  107. data/sig/mindee/page_options.rbs +11 -0
  108. data/sig/mindee/parsing/common/api_request.rbs +6 -6
  109. data/sig/mindee/parsing/common/api_response.rbs +2 -2
  110. data/sig/mindee/parsing/common/document.rbs +10 -10
  111. data/sig/mindee/parsing/common/execution.rbs +15 -14
  112. data/sig/mindee/parsing/common/execution_file.rbs +3 -3
  113. data/sig/mindee/parsing/common/extras/cropper_extra.rbs +3 -2
  114. data/sig/mindee/parsing/common/extras/extras.rbs +6 -5
  115. data/sig/mindee/parsing/common/extras/full_text_ocr_extra.rbs +2 -1
  116. data/sig/mindee/parsing/common/inference.rbs +16 -9
  117. data/sig/mindee/parsing/common/job.rbs +2 -2
  118. data/sig/mindee/parsing/common/ocr/mvision_v1.rbs +2 -2
  119. data/sig/mindee/parsing/common/ocr/ocr.rbs +22 -20
  120. data/sig/mindee/parsing/common/orientation.rbs +4 -3
  121. data/sig/mindee/parsing/common/page.rbs +6 -5
  122. data/sig/mindee/parsing/common/product.rbs +4 -4
  123. data/sig/mindee/parsing/common/workflow_response.rbs +8 -4
  124. data/sig/mindee/parsing/standard/abstract_field.rbs +1 -1
  125. data/sig/mindee/parsing/standard/address_field.rbs +18 -0
  126. data/sig/mindee/parsing/standard/amount_field.rbs +6 -4
  127. data/sig/mindee/parsing/standard/base_field.rbs +1 -1
  128. data/sig/mindee/parsing/standard/boolean_field.rbs +1 -1
  129. data/sig/mindee/parsing/standard/company_registration_field.rbs +3 -2
  130. data/sig/mindee/parsing/standard/date_field.rbs +6 -6
  131. data/sig/mindee/parsing/standard/locale_field.rbs +1 -1
  132. data/sig/mindee/parsing/standard/payment_details_field.rbs +7 -6
  133. data/sig/mindee/parsing/standard/position_field.rbs +2 -2
  134. data/sig/mindee/parsing/standard/string_field.rbs +1 -1
  135. data/sig/mindee/parsing/standard/tax_field.rbs +8 -7
  136. data/sig/mindee/parsing/universal/universal_list_field.rbs +4 -5
  137. data/sig/mindee/parsing/universal/universal_object_field.rbs +17 -11
  138. data/sig/mindee/parsing/v2/common_response.rbs +11 -0
  139. data/sig/mindee/parsing/v2/error_response.rbs +16 -0
  140. data/sig/mindee/parsing/v2/field/base_field.rbs +17 -0
  141. data/sig/mindee/parsing/v2/field/field_confidence.rbs +27 -0
  142. data/sig/mindee/parsing/v2/field/field_location.rbs +16 -0
  143. data/sig/mindee/parsing/v2/field/inference_fields.rbs +19 -0
  144. data/sig/mindee/parsing/v2/field/list_field.rbs +22 -0
  145. data/sig/mindee/parsing/v2/field/object_field.rbs +21 -0
  146. data/sig/mindee/parsing/v2/field/simple_field.rbs +16 -0
  147. data/sig/mindee/parsing/v2/inference.rbs +16 -0
  148. data/sig/mindee/parsing/v2/inference_file.rbs +15 -0
  149. data/sig/mindee/parsing/v2/inference_model.rbs +11 -0
  150. data/sig/mindee/parsing/v2/inference_response.rbs +12 -0
  151. data/sig/mindee/parsing/v2/inference_result.rbs +13 -0
  152. data/sig/mindee/parsing/v2/inference_result_options.rbs +11 -0
  153. data/sig/mindee/parsing/v2/job.rbs +22 -0
  154. data/sig/mindee/parsing/v2/job_response.rbs +12 -0
  155. data/sig/mindee/parsing/v2/job_webhook.rbs +17 -0
  156. data/sig/mindee/parsing/v2/raw_text.rbs +12 -0
  157. data/sig/mindee/pdf/extracted_pdf.rbs +6 -6
  158. data/sig/mindee/pdf/pdf_compressor.rbs +4 -4
  159. data/sig/mindee/pdf/pdf_extractor.rbs +8 -7
  160. data/sig/mindee/pdf/pdf_processor.rbs +4 -4
  161. data/sig/mindee/pdf/pdf_tools.rbs +22 -16
  162. data/sig/mindee/product/barcode_reader/barcode_reader_v1.rbs +1 -1
  163. data/sig/mindee/product/barcode_reader/barcode_reader_v1_document.rbs +1 -1
  164. data/sig/mindee/product/barcode_reader/barcode_reader_v1_page.rbs +2 -2
  165. data/sig/mindee/product/bill_of_lading/bill_of_lading_v1.rbs +1 -1
  166. data/sig/mindee/product/bill_of_lading/bill_of_lading_v1_carrier.rbs +2 -2
  167. data/sig/mindee/product/bill_of_lading/bill_of_lading_v1_carrier_item.rbs +3 -3
  168. data/sig/mindee/product/bill_of_lading/bill_of_lading_v1_consignee.rbs +2 -2
  169. data/sig/mindee/product/bill_of_lading/bill_of_lading_v1_document.rbs +1 -1
  170. data/sig/mindee/product/bill_of_lading/bill_of_lading_v1_notify_party.rbs +2 -2
  171. data/sig/mindee/product/bill_of_lading/bill_of_lading_v1_page.rbs +2 -2
  172. data/sig/mindee/product/bill_of_lading/bill_of_lading_v1_shipper.rbs +2 -2
  173. data/sig/mindee/product/business_card/business_card_v1.rbs +1 -1
  174. data/sig/mindee/product/business_card/business_card_v1_document.rbs +1 -1
  175. data/sig/mindee/product/business_card/business_card_v1_page.rbs +2 -2
  176. data/sig/mindee/product/cropper/cropper_v1.rbs +1 -1
  177. data/sig/mindee/product/cropper/cropper_v1_document.rbs +1 -1
  178. data/sig/mindee/product/cropper/cropper_v1_page.rbs +2 -2
  179. data/sig/mindee/product/delivery_note/delivery_note_v1.rbs +1 -1
  180. data/sig/mindee/product/delivery_note/delivery_note_v1_document.rbs +1 -1
  181. data/sig/mindee/product/delivery_note/delivery_note_v1_page.rbs +2 -2
  182. data/sig/mindee/product/driver_license/driver_license_v1.rbs +1 -1
  183. data/sig/mindee/product/driver_license/driver_license_v1_document.rbs +1 -1
  184. data/sig/mindee/product/driver_license/driver_license_v1_page.rbs +2 -2
  185. data/sig/mindee/product/financial_document/financial_document_v1.rbs +1 -1
  186. data/sig/mindee/product/financial_document/financial_document_v1_document.rbs +5 -5
  187. data/sig/mindee/product/financial_document/financial_document_v1_line_item.rbs +3 -3
  188. data/sig/mindee/product/financial_document/financial_document_v1_page.rbs +2 -2
  189. data/sig/mindee/product/fr/bank_account_details/bank_account_details_v1.rbs +1 -1
  190. data/sig/mindee/product/fr/bank_account_details/bank_account_details_v1_document.rbs +1 -1
  191. data/sig/mindee/product/fr/bank_account_details/bank_account_details_v1_page.rbs +2 -2
  192. data/sig/mindee/product/fr/bank_account_details/bank_account_details_v2.rbs +1 -1
  193. data/sig/mindee/product/fr/bank_account_details/bank_account_details_v2_bban.rbs +2 -2
  194. data/sig/mindee/product/fr/bank_account_details/bank_account_details_v2_document.rbs +1 -1
  195. data/sig/mindee/product/fr/bank_account_details/bank_account_details_v2_page.rbs +2 -2
  196. data/sig/mindee/product/fr/bank_statement/bank_statement_v2.rbs +1 -1
  197. data/sig/mindee/product/fr/bank_statement/bank_statement_v2_document.rbs +1 -1
  198. data/sig/mindee/product/fr/bank_statement/bank_statement_v2_page.rbs +2 -2
  199. data/sig/mindee/product/fr/bank_statement/bank_statement_v2_transaction.rbs +3 -3
  200. data/sig/mindee/product/fr/carte_grise/carte_grise_v1.rbs +1 -1
  201. data/sig/mindee/product/fr/carte_grise/carte_grise_v1_document.rbs +1 -1
  202. data/sig/mindee/product/fr/carte_grise/carte_grise_v1_page.rbs +2 -2
  203. data/sig/mindee/product/fr/energy_bill/energy_bill_v1.rbs +1 -1
  204. data/sig/mindee/product/fr/energy_bill/energy_bill_v1_document.rbs +1 -1
  205. data/sig/mindee/product/fr/energy_bill/energy_bill_v1_energy_consumer.rbs +2 -2
  206. data/sig/mindee/product/fr/energy_bill/energy_bill_v1_energy_supplier.rbs +2 -2
  207. data/sig/mindee/product/fr/energy_bill/energy_bill_v1_energy_usage.rbs +3 -3
  208. data/sig/mindee/product/fr/energy_bill/energy_bill_v1_meter_detail.rbs +2 -2
  209. data/sig/mindee/product/fr/energy_bill/energy_bill_v1_page.rbs +2 -2
  210. data/sig/mindee/product/fr/energy_bill/energy_bill_v1_subscription.rbs +3 -3
  211. data/sig/mindee/product/fr/energy_bill/energy_bill_v1_taxes_and_contribution.rbs +3 -3
  212. data/sig/mindee/product/fr/health_card/health_card_v1.rbs +1 -1
  213. data/sig/mindee/product/fr/health_card/health_card_v1_document.rbs +1 -1
  214. data/sig/mindee/product/fr/health_card/health_card_v1_page.rbs +2 -2
  215. data/sig/mindee/product/fr/id_card/id_card_v1.rbs +1 -1
  216. data/sig/mindee/product/fr/id_card/id_card_v1_document.rbs +1 -1
  217. data/sig/mindee/product/fr/id_card/id_card_v1_page.rbs +2 -2
  218. data/sig/mindee/product/fr/id_card/id_card_v2.rbs +1 -1
  219. data/sig/mindee/product/fr/id_card/id_card_v2_document.rbs +1 -1
  220. data/sig/mindee/product/fr/id_card/id_card_v2_page.rbs +2 -2
  221. data/sig/mindee/product/fr/payslip/payslip_v2.rbs +1 -1
  222. data/sig/mindee/product/fr/payslip/payslip_v2_bank_account_detail.rbs +2 -2
  223. data/sig/mindee/product/fr/payslip/payslip_v2_document.rbs +1 -1
  224. data/sig/mindee/product/fr/payslip/payslip_v2_employee.rbs +2 -2
  225. data/sig/mindee/product/fr/payslip/payslip_v2_employer.rbs +2 -2
  226. data/sig/mindee/product/fr/payslip/payslip_v2_employment.rbs +2 -2
  227. data/sig/mindee/product/fr/payslip/payslip_v2_page.rbs +2 -2
  228. data/sig/mindee/product/fr/payslip/payslip_v2_pay_detail.rbs +2 -2
  229. data/sig/mindee/product/fr/payslip/payslip_v2_pay_period.rbs +2 -2
  230. data/sig/mindee/product/fr/payslip/payslip_v2_pto.rbs +2 -2
  231. data/sig/mindee/product/fr/payslip/payslip_v2_salary_detail.rbs +3 -3
  232. data/sig/mindee/product/fr/payslip/payslip_v3.rbs +1 -1
  233. data/sig/mindee/product/fr/payslip/payslip_v3_bank_account_detail.rbs +2 -2
  234. data/sig/mindee/product/fr/payslip/payslip_v3_document.rbs +1 -1
  235. data/sig/mindee/product/fr/payslip/payslip_v3_employee.rbs +2 -2
  236. data/sig/mindee/product/fr/payslip/payslip_v3_employer.rbs +2 -2
  237. data/sig/mindee/product/fr/payslip/payslip_v3_employment.rbs +2 -2
  238. data/sig/mindee/product/fr/payslip/payslip_v3_page.rbs +2 -2
  239. data/sig/mindee/product/fr/payslip/payslip_v3_paid_time_off.rbs +3 -3
  240. data/sig/mindee/product/fr/payslip/payslip_v3_pay_detail.rbs +2 -2
  241. data/sig/mindee/product/fr/payslip/payslip_v3_pay_period.rbs +2 -2
  242. data/sig/mindee/product/fr/payslip/payslip_v3_salary_detail.rbs +3 -3
  243. data/sig/mindee/product/ind/indian_passport/indian_passport_v1.rbs +1 -1
  244. data/sig/mindee/product/ind/indian_passport/indian_passport_v1_document.rbs +1 -1
  245. data/sig/mindee/product/ind/indian_passport/indian_passport_v1_page.rbs +2 -2
  246. data/sig/mindee/product/international_id/international_id_v2.rbs +1 -1
  247. data/sig/mindee/product/international_id/international_id_v2_document.rbs +1 -1
  248. data/sig/mindee/product/international_id/international_id_v2_page.rbs +2 -2
  249. data/sig/mindee/product/invoice/invoice_v4.rbs +1 -1
  250. data/sig/mindee/product/invoice/invoice_v4_document.rbs +5 -5
  251. data/sig/mindee/product/invoice/invoice_v4_line_item.rbs +3 -3
  252. data/sig/mindee/product/invoice/invoice_v4_page.rbs +2 -2
  253. data/sig/mindee/product/invoice_splitter/invoice_splitter_v1.rbs +1 -1
  254. data/sig/mindee/product/invoice_splitter/invoice_splitter_v1_document.rbs +1 -1
  255. data/sig/mindee/product/invoice_splitter/invoice_splitter_v1_invoice_page_group.rbs +3 -3
  256. data/sig/mindee/product/invoice_splitter/invoice_splitter_v1_page.rbs +2 -2
  257. data/sig/mindee/product/multi_receipts_detector/multi_receipts_detector_v1.rbs +1 -1
  258. data/sig/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_document.rbs +1 -1
  259. data/sig/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_page.rbs +2 -2
  260. data/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1.rbs +1 -1
  261. data/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_added_sugar.rbs +2 -2
  262. data/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_calorie.rbs +2 -2
  263. data/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_cholesterol.rbs +2 -2
  264. data/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_dietary_fiber.rbs +2 -2
  265. data/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_document.rbs +1 -1
  266. data/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrient.rbs +3 -3
  267. data/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_page.rbs +2 -2
  268. data/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_protein.rbs +2 -2
  269. data/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_saturated_fat.rbs +2 -2
  270. data/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_serving_size.rbs +2 -2
  271. data/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_sodium.rbs +2 -2
  272. data/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_carbohydrate.rbs +2 -2
  273. data/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_fat.rbs +2 -2
  274. data/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_sugar.rbs +2 -2
  275. data/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_trans_fat.rbs +2 -2
  276. data/sig/mindee/product/passport/passport_v1.rbs +1 -1
  277. data/sig/mindee/product/passport/passport_v1_document.rbs +1 -1
  278. data/sig/mindee/product/passport/passport_v1_page.rbs +2 -2
  279. data/sig/mindee/product/receipt/receipt_v5.rbs +1 -1
  280. data/sig/mindee/product/receipt/receipt_v5_document.rbs +1 -1
  281. data/sig/mindee/product/receipt/receipt_v5_line_item.rbs +3 -3
  282. data/sig/mindee/product/receipt/receipt_v5_page.rbs +2 -2
  283. data/sig/mindee/product/resume/resume_v1.rbs +1 -1
  284. data/sig/mindee/product/resume/resume_v1_certificate.rbs +3 -3
  285. data/sig/mindee/product/resume/resume_v1_document.rbs +1 -1
  286. data/sig/mindee/product/resume/resume_v1_education.rbs +3 -3
  287. data/sig/mindee/product/resume/resume_v1_language.rbs +3 -3
  288. data/sig/mindee/product/resume/resume_v1_page.rbs +2 -2
  289. data/sig/mindee/product/resume/resume_v1_professional_experience.rbs +3 -3
  290. data/sig/mindee/product/resume/resume_v1_social_networks_url.rbs +3 -3
  291. data/sig/mindee/product/universal/universal.rbs +5 -5
  292. data/sig/mindee/product/universal/universal_document.rbs +1 -1
  293. data/sig/mindee/product/universal/universal_page.rbs +2 -2
  294. data/sig/mindee/product/universal/universal_prediction.rbs +5 -5
  295. data/sig/mindee/product/us/bank_check/bank_check_v1.rbs +1 -1
  296. data/sig/mindee/product/us/bank_check/bank_check_v1_document.rbs +1 -1
  297. data/sig/mindee/product/us/bank_check/bank_check_v1_page.rbs +2 -2
  298. data/sig/mindee/product/us/healthcare_card/healthcare_card_v1.rbs +1 -1
  299. data/sig/mindee/product/us/healthcare_card/healthcare_card_v1_copay.rbs +3 -3
  300. data/sig/mindee/product/us/healthcare_card/healthcare_card_v1_document.rbs +1 -1
  301. data/sig/mindee/product/us/healthcare_card/healthcare_card_v1_page.rbs +2 -2
  302. data/sig/mindee/product/us/us_mail/us_mail_v2.rbs +1 -1
  303. data/sig/mindee/product/us/us_mail/us_mail_v2_document.rbs +1 -1
  304. data/sig/mindee/product/us/us_mail/us_mail_v2_page.rbs +2 -2
  305. data/sig/mindee/product/us/us_mail/us_mail_v2_recipient_address.rbs +3 -3
  306. data/sig/mindee/product/us/us_mail/us_mail_v2_sender_address.rbs +2 -2
  307. data/sig/mindee/product/us/us_mail/us_mail_v3.rbs +1 -1
  308. data/sig/mindee/product/us/us_mail/us_mail_v3_document.rbs +1 -1
  309. data/sig/mindee/product/us/us_mail/us_mail_v3_page.rbs +2 -2
  310. data/sig/mindee/product/us/us_mail/us_mail_v3_recipient_address.rbs +3 -3
  311. data/sig/mindee/product/us/us_mail/us_mail_v3_sender_address.rbs +2 -2
  312. data/sig/mindee/product/us/w9/w9_v1.rbs +1 -1
  313. data/sig/mindee/product/us/w9/w9_v1_document.rbs +1 -1
  314. data/sig/mindee/product/us/w9/w9_v1_page.rbs +2 -2
  315. data/sig/mindee/version.rbs +2 -2
  316. metadata +63 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 32670ffa1c3f59d5dfb573f0543ef36e80e79341acacdcb5722249425e775fa9
4
- data.tar.gz: 6e3c47dad7eeacae2b6d06277deda1e2e9e90903e83883263021e306920e99f0
3
+ metadata.gz: c88f4c2b47bf3a97cd519d1c658f12a874ed930c8e86d5ff208c0c44d4174cca
4
+ data.tar.gz: 191850ef611da7ca60fac4827f6c530348adf2d07d4a7790dd46a6abb335e906
5
5
  SHA512:
6
- metadata.gz: 6324e2e4f0b75435fcb5baade6dbad8fb693de5cc74fff3171f53598d791486a4043826bea965ee79c58cf3988d0d69c449240f3607ec2a201c79b14f0dcdb2d
7
- data.tar.gz: 6394379b7ea271aba332256587ba406b03c3230a8647fed74d57ef474436e9b0b729be902cc60d7ee8be1ae9913f2173673c62c8f7e31383802c25bffd2d112a
6
+ metadata.gz: cbf412b01eb4c6a324f6548232ce24e7ed0bd6f20b12d3803a47218e971805b77c32989e644077809aaf3ec404946461deaf4e440385812228ece7d8d839d6b6
7
+ data.tar.gz: 381aebed32ebee1cbd763f361c46bf76eff8fd6592f1d9652ccb79ca5515a804e20c8a36459c56af189e5af883ec9b02c2f69a921dde46d15ad6bb1b7224267d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Mindee Ruby API Library Changelog
2
2
 
3
+ ## v4.7.0-rc1 - 2025-08-13
4
+ ### Changes
5
+ * :sparkles: add support for client V2 & associated features
6
+
7
+ ### Fixes
8
+ * :recycle: add many missing internal types
9
+ * :bug: fix invalid types for many V1 features
10
+ * :bug: fix V1 errors sometimes having the wrong code
11
+ * :bug: fix many presumably immutable fields having non-readonly parameters
12
+ * :bug: fix broken `resources` accessor in `ApiRequest` object
13
+
14
+
15
+ ## v4.6.0 - 2025-06-03
16
+ ### Changes
17
+ * :sparkles: add support for address fields
18
+
19
+
3
20
  ## v4.5.0 - 2025-05-27
4
21
  ### Changes
5
22
  * :sparkles: add support for Financial Document v1.14
data/README.md CHANGED
@@ -4,240 +4,39 @@
4
4
 
5
5
  Quickly and easily connect to Mindee's API services using Ruby.
6
6
 
7
- ## Requirements
7
+ ## Mindee API Versions
8
+ This client library has support for both Mindee platform versions.
8
9
 
9
- The following Ruby versions are tested and supported: 3.0, 3.1, 3.2, 3.3, 3.4
10
+ ### Latest - V2
11
+ This is the new platform located here:
10
12
 
11
- ## Quick Start
13
+ https://app.mindee.com
12
14
 
13
- Here's the TL;DR of getting started.
15
+ It uses **API version 2**.
14
16
 
15
- First, get an [API Key](https://developers.mindee.com/docs/create-api-key)
17
+ Consult the
18
+ **[Latest Documentation](https://docs.mindee.com/integrations/client-libraries-sdk)**
16
19
 
17
- Install by adding this line to your application's Gemfile:
18
20
 
19
- ```ruby
20
- gem 'mindee'
21
- ```
21
+ ### Legacy - V1
22
+ This is the legacy platform located here:
22
23
 
23
- And then execute:
24
+ https://platform.mindee.com/
24
25
 
25
- ```sh
26
- bundle install
27
- ```
26
+ It uses **API version 1**.
28
27
 
29
- Finally, Ruby away!
28
+ Consult the
29
+ **[Legacy Documentation](https://developers.mindee.com/docs/ruby-getting-started)**
30
30
 
31
- ### Environment Variables
31
+ ## Additional Information
32
32
 
33
- This library offers customizable features through environment variables. While there may be instances where you need to
34
- rely on them, it's crucial to exercise caution when modifying them to avoid unintended consequences.
33
+ **[Source Code](https://github.com/mindee/mindee-api-ruby)**
35
34
 
36
- If you're unsure whether you need to adjust these variables, it's advisable to refrain from doing so unless you have a
37
- specific reason. Accidentally overwriting them can lead to unexpected behavior.
35
+ **[Reference Documentation](https://mindee.github.io/mindee-api-ruby/)**
38
36
 
39
- Before making any changes, we recommend reviewing the following information to understand the purpose and potential
40
- impact of each environment variable:
37
+ **[Feedback](https://feedback.mindee.com/)**
41
38
 
42
- * `MINDEE_API_KEY`:
43
- * **Description**: Your personal Mindee API Key as shown on the platform. Be careful not to show this publicly!
44
- * **Default Value**: `nil`
45
- * `MINDEE_BASE_URL`:
46
- * **Description**: The default base URL of the API endpoint. Use this variable to specify the root URL for API requests. Modify as needed for proxy configurations or changes in API endpoint location.
47
- * **Default Value**: `https://api.mindee.net/v1`
48
- * `MINDEE_REQUEST_TIMEOUT`:
49
- * **Description**: The default timeout for HTTP requests (in seconds).
50
- * **Default Value**: `120`
51
- * `MINDEE_LOG_LEVEL`:
52
- * **Description**: The default logging level for the mindee logger.
53
- * **Default Value**: `WARN`
39
+ ### License
40
+ Copyright © Mindee
54
41
 
55
- ### Loading a File and Parsing It
56
-
57
- #### Global Documents
58
-
59
- ```ruby
60
- require 'mindee'
61
-
62
- # Init a new client
63
- mindee_client = Mindee::Client.new(api_key: 'my-api-key')
64
-
65
- # Load a file from disk
66
- input_source = mindee_client.source_from_path('/path/to/the/file.ext')
67
- result = mindee_client.parse(
68
- input_source,
69
- Mindee::Product::Invoice::InvoiceV4
70
- )
71
-
72
- # Print a full summary of the parsed data in RST format
73
- puts result.document
74
- ```
75
-
76
- **Note:** Files can also be loaded from:
77
-
78
- A URL (`https`):
79
-
80
- ```rb
81
- input_source = mindee_client.source_from_url("https://my-url")
82
- ```
83
-
84
- A bytes input stream:
85
-
86
- ```rb
87
- input_source = mindee_client.source_from_bytes('/path/to/the/file.ext', "name-of-my-file.ext")
88
- ```
89
-
90
- A base64 encoded string:
91
-
92
- ```rb
93
- input_source = mindee_client.source_from_b64string('/path/to/the/file.ext', "name-of-my-file.ext")
94
- ```
95
-
96
- A ruby `file` object:
97
-
98
- ```rb
99
- input_source = mindee_client.source_from_file(input_file, "name-of-my-file.ext")
100
- ```
101
-
102
- #### Region-Specific Documents
103
-
104
- ```ruby
105
- require 'mindee'
106
-
107
- # Init a new client
108
- mindee_client = Mindee::Client.new(api_key: 'my-api-key')
109
-
110
- # Load a file from disk
111
- input_source = mindee_client.source_from_path('/path/to/the/file.ext')
112
-
113
- result = mindee_client.parse(
114
- input_source,
115
- Mindee::Product::EU::LicensePlate::LicensePlateV1
116
- )
117
-
118
- # Print a full summary of the parsed data in RST format
119
- puts result.document
120
- ```
121
-
122
- ### Universal - All Other Documents
123
-
124
- The Universal product acts as a catch-all for every and any API if it doesn't have an assigned product name.
125
-
126
- ```ruby
127
- require 'mindee'
128
-
129
- # Init a new client and configure your custom document
130
- mindee_client = Mindee::Client.new(api_key: 'my-api-key')
131
- endpoint = mindee_client.create_endpoint(
132
- endpoint_name: 'my-endpoint',
133
- account_name: 'my-account'
134
- )
135
-
136
- # Load a file from disk
137
- input_source = mindee_client.source_from_path('/path/to/the/file.ext')
138
-
139
- result = mindee_client.parse(
140
- input_source,
141
- Mindee::Product::Universal::Universal,
142
- endpoint: endpoint
143
- )
144
-
145
- # Print a full summary of the parsed data in RST format
146
- puts result.document
147
-
148
- # Looping over all prediction values
149
- result.document.inference.prediction.fields.each do |field_name, field_data|
150
- puts field_name
151
- puts field_data.values
152
- puts field_data.to_s
153
- end
154
- ```
155
-
156
-
157
- ## Enqueueing and Parse a Webhook Response
158
-
159
- This is an optional way of handling asynchronous APIs.
160
-
161
- ```rb
162
- require 'mindee'
163
-
164
- # Init a new client
165
- mindee_client = Mindee::Client.new(api_key: 'my-api-key')
166
-
167
- # Load a file from disk
168
- input_source = mindee_client.source_from_path('/path/to/the/file.ext')
169
-
170
-
171
- # Send the file to the server
172
- enqueue_response = mindee_client.enqueue(
173
- input_source,
174
- Mindee::Product::InternationalId::InternationalIdV2
175
- )
176
-
177
- job_id = enqueue_response.job.id
178
-
179
- # Load the JSON string sent by the Mindee webhook POST callback.
180
- # Reading the callback data will vary greatly depending on your HTTP server.
181
- # This is therefore beyond the scope of this example.
182
-
183
- local_response = Mindee::Input::LocalResponse.new(request.body.string)
184
-
185
- # You can also use a File object as the input.
186
- # FILE_PATH = File.join('path', 'to', 'file.json').freeze
187
- # local_response = Mindee::Input::LocalResponse.new(FILE_PATH);
188
-
189
- # Optional: verify the HMAC signature.
190
- unless local_response.valid_hmac_signature?(my_secret_key, 'invalid signature')
191
- raise "Invalid HMAC signature!"
192
- end
193
-
194
-
195
- # Deserialize the response:
196
- result = mindee_client.load_prediction(
197
- Mindee::Product::InternationalId::InternationalIdV2,
198
- local_response
199
- )
200
-
201
- # Print a full summary of the parsed data in RST format
202
- puts result.document
203
- ```
204
-
205
-
206
- ## CLI Tool
207
-
208
- A command-line interface tool is available to quickly test documents:
209
-
210
- ```sh
211
- ruby ./bin/mindee.rb <product_name> path/to/your/file.ext
212
- ```
213
-
214
- Using the ruby bundler:
215
-
216
- ```sh
217
- bundle exec ruby ./bin/mindee.rb <product_name> path/to/your/file.ext
218
- ```
219
-
220
- Where possible values for `<product_name>` can be displayed by running the command with no arguments.
221
-
222
- ## Further Reading
223
-
224
- There's more to it than that for those that need more features, or want to
225
- customize the experience.
226
-
227
- * [Ruby Overview](https://developers.mindee.com/docs/ruby-getting-started)
228
- * [Common file operations](https://developers.mindee.com/docs/ruby-common-file-operations)
229
- * [Global products](https://developers.mindee.com/docs/ruby-global-products)
230
- * [Localized products](https://developers.mindee.com/docs/ruby-localized-products)
231
-
232
- You can also take a look at the
233
- [Reference Documentation](https://mindee.github.io/mindee-api-ruby/).
234
-
235
- ## License
236
-
237
- Copyright © Mindee, SA
238
-
239
- Available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
240
-
241
- ## Questions?
242
-
243
- [Join our Slack](https://join.slack.com/t/mindee-community/shared_invite/zt-2d0ds7dtz-DPAF81ZqTy20chsYpQBW5g)
42
+ Available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,28 @@
1
+ require 'mindee'
2
+
3
+ input_path = '/path/to/the/file.ext'
4
+ api_key = 'MY_API_KEY'
5
+ model_id = 'MY_MODEL_ID'
6
+
7
+ # Init a new client
8
+ mindee_client = Mindee::ClientV2.new(api_key: api_key)
9
+
10
+ # Set inference parameters
11
+ params = Mindee::Input::InferenceParameters.new(
12
+ # ID of the model, required.
13
+ model_id,
14
+ # If set to `True`, will enable Retrieval-Augmented Generation.
15
+ rag: false,
16
+ )
17
+
18
+ # Load a file from disk
19
+ input_source = Mindee::Input::Source::PathInputSource.new(input_path)
20
+
21
+ # Send for processing
22
+ response = mindee_client.enqueue_and_get_inference(
23
+ input_source,
24
+ params # Note: this parameter can also be provided as a Hash.
25
+ )
26
+
27
+ # Print a brief summary of the parsed data
28
+ puts response.inference
@@ -224,6 +224,21 @@ A typical `Field` object will have the following attributes:
224
224
  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.
225
225
 
226
226
 
227
+ ### AddressField
228
+ Aside from the basic `BaseField` attributes, the address field `AddressField` also implements the following:
229
+
230
+ * **street_number** (`String`): String representation of the street number. Can be `nil`.
231
+ * **street_name** (`String`): Name of the street. Can be `nil`.
232
+ * **po_box** (`String`): String representation of the PO Box number. Can be `nil`.
233
+ * **address_complement** (`String`): Address complement. Can be `nil`.
234
+ * **city** (`String`): City name. Can be `nil`.
235
+ * **postal_code** (`String`): String representation of the postal code. Can be `nil`.
236
+ * **state** (`String`): State name. Can be `nil`.
237
+ * **country** (`String`): Country name. Can be `nil`.
238
+
239
+ Note: The `value` field of an AddressField should be a concatenation of the rest of the values.
240
+
241
+
227
242
  ### Amount Field
228
243
  The amount field `AmountField` only has one constraint: its **value** is a `Float` (or `nil`).
229
244
 
@@ -304,7 +319,7 @@ A `FinancialDocumentV1LineItem` implements the following attributes:
304
319
  The following fields are extracted for Financial Document V1:
305
320
 
306
321
  ## Billing Address
307
- **billing_address** ([StringField](#string-field)): The customer's address used for billing.
322
+ **billing_address** ([AddressField](#address-field)): The customer's address used for billing.
308
323
 
309
324
  ```rb
310
325
  puts result.document.inference.prediction.billing_address.value
@@ -331,7 +346,7 @@ puts result.document.inference.prediction.category.value
331
346
  ```
332
347
 
333
348
  ## Customer Address
334
- **customer_address** ([StringField](#string-field)): The address of the customer.
349
+ **customer_address** ([AddressField](#address-field)): The address of the customer.
335
350
 
336
351
  ```rb
337
352
  puts result.document.inference.prediction.customer_address.value
@@ -466,7 +481,7 @@ end
466
481
  ```
467
482
 
468
483
  ## Shipping Address
469
- **shipping_address** ([StringField](#string-field)): The customer's address used for shipping.
484
+ **shipping_address** ([AddressField](#address-field)): The customer's address used for shipping.
470
485
 
471
486
  ```rb
472
487
  puts result.document.inference.prediction.shipping_address.value
@@ -497,7 +512,7 @@ puts result.document.inference.prediction.subcategory.value
497
512
  ```
498
513
 
499
514
  ## Supplier Address
500
- **supplier_address** ([StringField](#string-field)): The address of the supplier or merchant.
515
+ **supplier_address** ([AddressField](#address-field)): The address of the supplier or merchant.
501
516
 
502
517
  ```rb
503
518
  puts result.document.inference.prediction.supplier_address.value
@@ -216,6 +216,21 @@ A typical `Field` object will have the following attributes:
216
216
  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.
217
217
 
218
218
 
219
+ ### AddressField
220
+ Aside from the basic `BaseField` attributes, the address field `AddressField` also implements the following:
221
+
222
+ * **street_number** (`String`): String representation of the street number. Can be `nil`.
223
+ * **street_name** (`String`): Name of the street. Can be `nil`.
224
+ * **po_box** (`String`): String representation of the PO Box number. Can be `nil`.
225
+ * **address_complement** (`String`): Address complement. Can be `nil`.
226
+ * **city** (`String`): City name. Can be `nil`.
227
+ * **postal_code** (`String`): String representation of the postal code. Can be `nil`.
228
+ * **state** (`String`): State name. Can be `nil`.
229
+ * **country** (`String`): Country name. Can be `nil`.
230
+
231
+ Note: The `value` field of an AddressField should be a concatenation of the rest of the values.
232
+
233
+
219
234
  ### Amount Field
220
235
  The amount field `AmountField` only has one constraint: its **value** is a `Float` (or `nil`).
221
236
 
@@ -296,7 +311,7 @@ A `InvoiceV4LineItem` implements the following attributes:
296
311
  The following fields are extracted for Invoice V4:
297
312
 
298
313
  ## Billing Address
299
- **billing_address** ([StringField](#string-field)): The customer billing address.
314
+ **billing_address** ([AddressField](#address-field)): The customer billing address.
300
315
 
301
316
  ```rb
302
317
  puts result.document.inference.prediction.billing_address.value
@@ -322,7 +337,7 @@ puts result.document.inference.prediction.category.value
322
337
  ```
323
338
 
324
339
  ## Customer Address
325
- **customer_address** ([StringField](#string-field)): The address of the customer.
340
+ **customer_address** ([AddressField](#address-field)): The address of the customer.
326
341
 
327
342
  ```rb
328
343
  puts result.document.inference.prediction.customer_address.value
@@ -441,7 +456,7 @@ end
441
456
  ```
442
457
 
443
458
  ## Shipping Address
444
- **shipping_address** ([StringField](#string-field)): Customer's delivery address.
459
+ **shipping_address** ([AddressField](#address-field)): Customer's delivery address.
445
460
 
446
461
  ```rb
447
462
  puts result.document.inference.prediction.shipping_address.value
@@ -472,7 +487,7 @@ puts result.document.inference.prediction.subcategory.value
472
487
  ```
473
488
 
474
489
  ## Supplier Address
475
- **supplier_address** ([StringField](#string-field)): The address of the supplier or merchant.
490
+ **supplier_address** ([AddressField](#address-field)): The address of the supplier or merchant.
476
491
 
477
492
  ```rb
478
493
  puts result.document.inference.prediction.supplier_address.value
data/lib/mindee/client.rb CHANGED
@@ -2,38 +2,17 @@
2
2
 
3
3
  require_relative 'input'
4
4
  require_relative 'http'
5
- require_relative 'product'
5
+ require_relative 'logging'
6
+ require_relative 'page_options'
6
7
  require_relative 'parsing/common/api_response'
7
8
  require_relative 'parsing/common/job'
8
9
  require_relative 'parsing/common/workflow_response'
9
- require_relative 'logging'
10
+ require_relative 'product'
10
11
 
11
12
  # Default owner for products.
12
13
  OTS_OWNER = 'mindee'
13
14
 
14
15
  module Mindee
15
- # Class for page options in parse calls.
16
- #
17
- # @!attribute page_indexes [Array[Integer]] Zero-based list of page indexes.
18
- # @!attribute operation [:KEEP_ONLY, :REMOVE] Operation to apply on the document, given the specified page indexes:
19
- # * `:KEEP_ONLY` - keep only the specified pages, and remove all others.
20
- # * `:REMOVE` - remove the specified pages, and keep all others.
21
- # @!attribute on_min_pages [Integer, nil] Apply the operation only if the document has at least this many pages.
22
- class PageOptions
23
- attr_accessor :page_indexes, :operation, :on_min_pages
24
-
25
- def initialize(params: {})
26
- params ||= {}
27
- params = params.transform_keys(&:to_sym)
28
- @page_indexes = params.fetch(
29
- :page_indexes,
30
- [] # : Array[Integer]
31
- )
32
- @operation = params.fetch(:operation, :KEEP_ONLY)
33
- @on_min_pages = params.fetch(:on_min_pages, nil)
34
- end
35
- end
36
-
37
16
  # Class for configuration options in parse calls.
38
17
  #
39
18
  # @!attribute all_words [bool] Whether to include the full text for each page.
@@ -89,8 +68,9 @@ module Mindee
89
68
  # * `:KEEP_ONLY` - keep only the specified pages, and remove all others.
90
69
  # * `:REMOVE` - remove the specified pages, and keep all others.
91
70
  # * `:on_min_pages` Apply the operation only if the document has at least this many pages.
71
+ # @!attribute close_file [bool, nil] Whether to close the file after sending it. Defaults to true.
92
72
  class WorkflowOptions
93
- attr_accessor :document_alias, :priority, :full_text, :public_url, :page_options, :rag
73
+ attr_accessor :document_alias, :priority, :full_text, :public_url, :page_options, :rag, :close_file
94
74
 
95
75
  def initialize(params: {})
96
76
  params = params.transform_keys(&:to_sym)
@@ -102,6 +82,7 @@ module Mindee
102
82
  raw_page_options = params.fetch(:page_options, nil)
103
83
  raw_page_options = PageOptions.new(params: raw_page_options) unless raw_page_options.is_a?(PageOptions)
104
84
  @page_options = raw_page_options
85
+ @close_file = params.fetch(:close_file, true)
105
86
  end
106
87
  end
107
88
 
@@ -326,7 +307,7 @@ module Mindee
326
307
  process_pdf_if_required(input_source, opts)
327
308
  end
328
309
 
329
- workflow_endpoint = Mindee::HTTP::WorkflowEndpoint.new(workflow_id, api_key: @api_key)
310
+ workflow_endpoint = Mindee::HTTP::WorkflowEndpoint.new(workflow_id, api_key: @api_key.to_s)
330
311
  logger.debug("Sending document to workflow '#{workflow_id}'")
331
312
 
332
313
  prediction, raw_http = workflow_endpoint.execute_workflow(
@@ -455,11 +436,11 @@ module Mindee
455
436
  account_name = fix_account_name(account_name)
456
437
  version = fix_version(product_class, version)
457
438
 
458
- HTTP::Endpoint.new(account_name, endpoint_name, version, api_key: @api_key)
439
+ HTTP::Endpoint.new(account_name, endpoint_name, version, api_key: @api_key.to_s)
459
440
  end
460
441
 
461
442
  def fix_endpoint_name(product_class, endpoint_name)
462
- endpoint_name.nil? || endpoint_name.empty? ? product_class.endpoint_name : endpoint_name
443
+ endpoint_name.nil? || endpoint_name.empty? ? product_class.endpoint_name.to_s : endpoint_name.to_s
463
444
  end
464
445
 
465
446
  def fix_account_name(account_name)
@@ -474,11 +455,11 @@ module Mindee
474
455
  def fix_version(product_class, version)
475
456
  return version unless version.nil? || version.empty?
476
457
 
477
- if product_class.endpoint_version.nil? || product_class.endpoint_version.empty?
458
+ if product_class.endpoint_version.nil? || product_class.endpoint_version.to_s.empty?
478
459
  logger.debug('No version provided for a custom build, will attempt to poll version 1 by default.')
479
460
  return '1'
480
461
  end
481
- product_class.endpoint_version
462
+ product_class.endpoint_version || ''
482
463
  end
483
464
 
484
465
  # If needed, converts the parsing options provided as a hash into a proper ParseOptions object.
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'input'
4
+ require_relative 'http'
5
+ require_relative 'product'
6
+ require_relative 'parsing/common/api_response'
7
+ require_relative 'parsing/common/job'
8
+ require_relative 'parsing/common/workflow_response'
9
+ require_relative 'logging'
10
+
11
+ module Mindee
12
+ # Mindee V2 API Client.
13
+ class ClientV2
14
+ # @return [HTTP::MindeeApiV2]
15
+ private attr_reader :mindee_api
16
+
17
+ # @param api_key [String]
18
+ def initialize(api_key: '')
19
+ @mindee_api = Mindee::HTTP::MindeeApiV2.new(api_key: api_key)
20
+ end
21
+
22
+ # Retrieves an inference.
23
+ # @param inference_id [String]
24
+ # @return [Mindee::Parsing::V2::InferenceResponse]
25
+ def get_inference(inference_id)
26
+ @mindee_api.req_get_inference(inference_id)
27
+ end
28
+
29
+ # Retrieves an inference.
30
+ # @param job_id [String]
31
+ # @return [Mindee::Parsing::V2::JobResponse]
32
+ def get_job(job_id)
33
+ @mindee_api.req_get_job(job_id)
34
+ end
35
+
36
+ # Enqueue a document for async parsing.
37
+ # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource]
38
+ # The source of the input document (local file or URL).
39
+ # @param params [Hash, InferenceParameters]
40
+ # @return [Mindee::Parsing::V2::JobResponse]
41
+ def enqueue_inference(input_source, params)
42
+ normalized_params = normalize_inference_parameters(params)
43
+ logger.debug("Enqueueing document to model '#{normalized_params.model_id}'.")
44
+
45
+ @mindee_api.req_post_inference_enqueue(input_source, normalized_params)
46
+ end
47
+
48
+ # Enqueue a document for async parsing and automatically try to retrieve it.
49
+ # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource]
50
+ # The source of the input document (local file or URL).
51
+ # @param params [Hash, InferenceParameters] Parameters for the inference.
52
+ # @return [Mindee::Parsing::V2::InferenceResponse]
53
+ def enqueue_and_get_inference(input_source, params)
54
+ normalized_params = normalize_inference_parameters(params)
55
+ normalized_params.validate_async_params
56
+ enqueue_response = enqueue_inference(input_source, normalized_params)
57
+
58
+ if enqueue_response.job.id.nil? || enqueue_response.job.id.empty?
59
+ logger.error("Failed enqueueing:\n#{enqueue_response.raw_http}")
60
+ raise Mindee::Errors::MindeeError, 'Enqueueing of the document failed.'
61
+ end
62
+
63
+ job_id = enqueue_response.job.id
64
+ logger.debug("Successfully enqueued document with job id: #{job_id}.")
65
+
66
+ sleep(normalized_params.polling_options.initial_delay_sec)
67
+ retry_counter = 1
68
+ poll_results = get_job(job_id)
69
+
70
+ while retry_counter < normalized_params.polling_options.max_retries
71
+ if poll_results.job.status == 'Failed'
72
+ break
73
+ elsif poll_results.job.status == 'Processed'
74
+ return get_inference(poll_results.job.id)
75
+ end
76
+
77
+ logger.debug(
78
+ "Successfully enqueued inference with job id: #{job_id}.\n" \
79
+ "Attempt n°#{retry_counter}/#{normalized_params.polling_options.max_retries}.\n" \
80
+ "Job status: #{poll_results.job.status}."
81
+ )
82
+
83
+ sleep(normalized_params.polling_options.delay_sec)
84
+ poll_results = get_job(job_id)
85
+ retry_counter += 1
86
+ end
87
+
88
+ error = poll_results.job.error
89
+ unless error.nil?
90
+ err_to_raise = Mindee::Errors::MindeeHTTPErrorV2.new(error)
91
+ # NOTE: purposefully decoupled from the line above, otherwise rubocop thinks `error` is a `message` param.
92
+ raise err_to_raise
93
+ end
94
+
95
+ sec_count = normalized_params.polling_options.delay_sec * retry_counter
96
+ raise Mindee::Errors::MindeeError,
97
+ "Asynchronous parsing request timed out after #{sec_count} seconds"
98
+ end
99
+
100
+ # If needed, converts the parsing options provided as a hash into a proper InferenceParameters object.
101
+ # @param params [Hash, InferenceParameters] Params.
102
+ # @return [InferenceParameters]
103
+ def normalize_inference_parameters(params)
104
+ return params if params.is_a?(Input::InferenceParameters)
105
+
106
+ Input::InferenceParameters.from_hash(params: params)
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'mindee_error'
4
+
5
+ module Mindee
6
+ module Errors
7
+ # API V2 HttpError
8
+ class MindeeHTTPErrorV2 < MindeeError
9
+ # @return [Integer]
10
+ attr_reader :status
11
+ # @return [String]
12
+ attr_reader :detail
13
+
14
+ # @param http_error [Hash, Parsing::V2::ErrorResponse]
15
+ def initialize(http_error)
16
+ if http_error.is_a?(Parsing::V2::ErrorResponse)
17
+ http_error = { 'detail' => http_error.detail,
18
+ 'status' => http_error.status }
19
+ end
20
+ @status = http_error['status']
21
+ @detail = http_error['detail']
22
+ super("HTTP error: #{@status} - #{@detail}")
23
+ end
24
+ end
25
+ end
26
+ end
data/lib/mindee/errors.rb CHANGED
@@ -2,4 +2,5 @@
2
2
 
3
3
  require_relative 'errors/mindee_error'
4
4
  require_relative 'errors/mindee_http_error'
5
+ require_relative 'errors/mindee_http_error_v2'
5
6
  require_relative 'errors/mindee_input_error'