mindee 4.6.0 → 4.7.0.pre.rc2

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 (310) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +20 -0
  3. data/README.md +21 -222
  4. data/docs/code_samples/default_v2.txt +28 -0
  5. data/lib/mindee/client.rb +11 -30
  6. data/lib/mindee/client_v2.rb +109 -0
  7. data/lib/mindee/errors/mindee_http_error_v2.rb +26 -0
  8. data/lib/mindee/errors/mindee_input_error.rb +1 -1
  9. data/lib/mindee/errors.rb +1 -0
  10. data/lib/mindee/geometry/point.rb +2 -2
  11. data/lib/mindee/geometry/quadrilateral.rb +4 -4
  12. data/lib/mindee/geometry/utils.rb +1 -0
  13. data/lib/mindee/http/api_settings_v2.rb +61 -0
  14. data/lib/mindee/http/endpoint.rb +12 -6
  15. data/lib/mindee/http/http_error_handler.rb +17 -4
  16. data/lib/mindee/http/mindee_api_v2.rb +148 -0
  17. data/lib/mindee/http/response_validation.rb +20 -1
  18. data/lib/mindee/http/workflow_endpoint.rb +2 -2
  19. data/lib/mindee/http.rb +2 -0
  20. data/lib/mindee/image/extracted_image.rb +1 -1
  21. data/lib/mindee/image/image_extractor.rb +12 -15
  22. data/lib/mindee/input/inference_parameters.rb +116 -0
  23. data/lib/mindee/input/local_response.rb +10 -1
  24. data/lib/mindee/input/polling_options.rb +26 -0
  25. data/lib/mindee/input/sources/base64_input_source.rb +2 -2
  26. data/lib/mindee/input/sources/local_input_source.rb +49 -30
  27. data/lib/mindee/input.rb +2 -0
  28. data/lib/mindee/page_options.rb +24 -0
  29. data/lib/mindee/parsing/common/api_request.rb +2 -2
  30. data/lib/mindee/parsing/common/api_response.rb +4 -0
  31. data/lib/mindee/parsing/common/execution.rb +1 -1
  32. data/lib/mindee/parsing/common/extras/extras.rb +2 -2
  33. data/lib/mindee/parsing/common/extras/rag_extra.rb +2 -0
  34. data/lib/mindee/parsing/common/ocr/ocr.rb +4 -6
  35. data/lib/mindee/parsing/common/orientation.rb +2 -2
  36. data/lib/mindee/parsing/common/product.rb +6 -1
  37. data/lib/mindee/parsing/standard/amount_field.rb +2 -2
  38. data/lib/mindee/parsing/standard/feature_field.rb +1 -1
  39. data/lib/mindee/parsing/standard/tax_field.rb +1 -1
  40. data/lib/mindee/parsing/universal/universal_list_field.rb +2 -2
  41. data/lib/mindee/parsing/universal/universal_object_field.rb +7 -4
  42. data/lib/mindee/parsing/v2/common_response.rb +18 -0
  43. data/lib/mindee/parsing/v2/error_response.rb +36 -0
  44. data/lib/mindee/parsing/v2/field/base_field.rb +60 -0
  45. data/lib/mindee/parsing/v2/field/field_confidence.rb +91 -0
  46. data/lib/mindee/parsing/v2/field/field_location.rb +36 -0
  47. data/lib/mindee/parsing/v2/field/inference_fields.rb +96 -0
  48. data/lib/mindee/parsing/v2/field/list_field.rb +88 -0
  49. data/lib/mindee/parsing/v2/field/object_field.rb +102 -0
  50. data/lib/mindee/parsing/v2/field/simple_field.rb +55 -0
  51. data/lib/mindee/parsing/v2/field.rb +9 -0
  52. data/lib/mindee/parsing/v2/inference.rb +50 -0
  53. data/lib/mindee/parsing/v2/inference_file.rb +38 -0
  54. data/lib/mindee/parsing/v2/inference_model.rb +18 -0
  55. data/lib/mindee/parsing/v2/inference_response.rb +30 -0
  56. data/lib/mindee/parsing/v2/inference_result.rb +49 -0
  57. data/lib/mindee/parsing/v2/inference_result_options.rb +21 -0
  58. data/lib/mindee/parsing/v2/job.rb +86 -0
  59. data/lib/mindee/parsing/v2/job_response.rb +30 -0
  60. data/lib/mindee/parsing/v2/job_webhook.rb +60 -0
  61. data/lib/mindee/parsing/v2/raw_text.rb +21 -0
  62. data/lib/mindee/parsing/v2.rb +15 -0
  63. data/lib/mindee/pdf/extracted_pdf.rb +5 -3
  64. data/lib/mindee/pdf/pdf_extractor.rb +11 -7
  65. data/lib/mindee/pdf/pdf_processor.rb +6 -6
  66. data/lib/mindee/pdf/pdf_tools.rb +6 -4
  67. data/lib/mindee/product/universal/universal_prediction.rb +4 -4
  68. data/lib/mindee/version.rb +2 -2
  69. data/lib/mindee.rb +6 -0
  70. data/mindee.gemspec +1 -1
  71. data/sig/custom/mini_magick.rbs +14 -7
  72. data/sig/custom/net_http.rbs +4 -4
  73. data/sig/custom/origami.rbs +9 -4
  74. data/sig/mindee/client.rbs +14 -19
  75. data/sig/mindee/client_v2.rbs +17 -0
  76. data/sig/mindee/errors/mindee_http_error.rbs +6 -5
  77. data/sig/mindee/errors/mindee_http_error_v2.rbs +12 -0
  78. data/sig/mindee/errors/mindee_input_error.rbs +3 -2
  79. data/sig/mindee/geometry/min_max.rbs +4 -3
  80. data/sig/mindee/geometry/point.rbs +5 -6
  81. data/sig/mindee/geometry/polygon.rbs +3 -3
  82. data/sig/mindee/geometry/quadrilateral.rbs +5 -8
  83. data/sig/mindee/geometry/utils.rbs +8 -8
  84. data/sig/mindee/http/api_settings_v2.rbs +23 -0
  85. data/sig/mindee/http/endpoint.rbs +12 -11
  86. data/sig/mindee/http/http_error_handler.rbs +8 -3
  87. data/sig/mindee/http/mindee_api_v2.rbs +18 -0
  88. data/sig/mindee/http/response_validation.rbs +1 -0
  89. data/sig/mindee/http/workflow_endpoint.rbs +1 -1
  90. data/sig/mindee/image/extracted_image.rbs +2 -2
  91. data/sig/mindee/image/image_compressor.rbs +1 -1
  92. data/sig/mindee/image/image_extractor.rbs +5 -5
  93. data/sig/mindee/image/image_utils.rbs +10 -10
  94. data/sig/mindee/input/inference_parameters.rbs +30 -0
  95. data/sig/mindee/input/local_response.rbs +6 -5
  96. data/sig/mindee/input/polling_options.rbs +12 -0
  97. data/sig/mindee/input/sources/base64_input_source.rbs +1 -1
  98. data/sig/mindee/input/sources/local_input_source.rbs +14 -7
  99. data/sig/mindee/input/sources/url_input_source.rbs +1 -1
  100. data/sig/mindee/logging/logger.rbs +2 -0
  101. data/sig/mindee/page_options.rbs +11 -0
  102. data/sig/mindee/parsing/common/api_request.rbs +6 -6
  103. data/sig/mindee/parsing/common/api_response.rbs +2 -2
  104. data/sig/mindee/parsing/common/document.rbs +10 -10
  105. data/sig/mindee/parsing/common/execution.rbs +15 -14
  106. data/sig/mindee/parsing/common/execution_file.rbs +3 -3
  107. data/sig/mindee/parsing/common/extras/cropper_extra.rbs +3 -2
  108. data/sig/mindee/parsing/common/extras/extras.rbs +6 -5
  109. data/sig/mindee/parsing/common/extras/full_text_ocr_extra.rbs +2 -1
  110. data/sig/mindee/parsing/common/inference.rbs +16 -9
  111. data/sig/mindee/parsing/common/job.rbs +2 -2
  112. data/sig/mindee/parsing/common/ocr/mvision_v1.rbs +2 -2
  113. data/sig/mindee/parsing/common/ocr/ocr.rbs +22 -20
  114. data/sig/mindee/parsing/common/orientation.rbs +4 -3
  115. data/sig/mindee/parsing/common/page.rbs +6 -5
  116. data/sig/mindee/parsing/common/product.rbs +4 -4
  117. data/sig/mindee/parsing/common/workflow_response.rbs +8 -4
  118. data/sig/mindee/parsing/standard/abstract_field.rbs +1 -1
  119. data/sig/mindee/parsing/standard/address_field.rbs +1 -1
  120. data/sig/mindee/parsing/standard/amount_field.rbs +6 -4
  121. data/sig/mindee/parsing/standard/base_field.rbs +1 -1
  122. data/sig/mindee/parsing/standard/boolean_field.rbs +1 -1
  123. data/sig/mindee/parsing/standard/company_registration_field.rbs +3 -2
  124. data/sig/mindee/parsing/standard/date_field.rbs +6 -6
  125. data/sig/mindee/parsing/standard/locale_field.rbs +1 -1
  126. data/sig/mindee/parsing/standard/payment_details_field.rbs +7 -6
  127. data/sig/mindee/parsing/standard/position_field.rbs +2 -2
  128. data/sig/mindee/parsing/standard/string_field.rbs +1 -1
  129. data/sig/mindee/parsing/standard/tax_field.rbs +8 -7
  130. data/sig/mindee/parsing/universal/universal_list_field.rbs +4 -5
  131. data/sig/mindee/parsing/universal/universal_object_field.rbs +17 -11
  132. data/sig/mindee/parsing/v2/common_response.rbs +11 -0
  133. data/sig/mindee/parsing/v2/error_response.rbs +16 -0
  134. data/sig/mindee/parsing/v2/field/base_field.rbs +17 -0
  135. data/sig/mindee/parsing/v2/field/field_confidence.rbs +27 -0
  136. data/sig/mindee/parsing/v2/field/field_location.rbs +16 -0
  137. data/sig/mindee/parsing/v2/field/inference_fields.rbs +19 -0
  138. data/sig/mindee/parsing/v2/field/list_field.rbs +21 -0
  139. data/sig/mindee/parsing/v2/field/object_field.rbs +21 -0
  140. data/sig/mindee/parsing/v2/field/simple_field.rbs +16 -0
  141. data/sig/mindee/parsing/v2/inference.rbs +16 -0
  142. data/sig/mindee/parsing/v2/inference_file.rbs +15 -0
  143. data/sig/mindee/parsing/v2/inference_model.rbs +11 -0
  144. data/sig/mindee/parsing/v2/inference_response.rbs +12 -0
  145. data/sig/mindee/parsing/v2/inference_result.rbs +13 -0
  146. data/sig/mindee/parsing/v2/inference_result_options.rbs +11 -0
  147. data/sig/mindee/parsing/v2/job.rbs +22 -0
  148. data/sig/mindee/parsing/v2/job_response.rbs +12 -0
  149. data/sig/mindee/parsing/v2/job_webhook.rbs +17 -0
  150. data/sig/mindee/parsing/v2/raw_text.rbs +12 -0
  151. data/sig/mindee/pdf/extracted_pdf.rbs +6 -6
  152. data/sig/mindee/pdf/pdf_compressor.rbs +4 -4
  153. data/sig/mindee/pdf/pdf_extractor.rbs +8 -7
  154. data/sig/mindee/pdf/pdf_processor.rbs +4 -4
  155. data/sig/mindee/pdf/pdf_tools.rbs +22 -16
  156. data/sig/mindee/product/barcode_reader/barcode_reader_v1.rbs +1 -1
  157. data/sig/mindee/product/barcode_reader/barcode_reader_v1_document.rbs +1 -1
  158. data/sig/mindee/product/barcode_reader/barcode_reader_v1_page.rbs +2 -2
  159. data/sig/mindee/product/bill_of_lading/bill_of_lading_v1.rbs +1 -1
  160. data/sig/mindee/product/bill_of_lading/bill_of_lading_v1_carrier.rbs +2 -2
  161. data/sig/mindee/product/bill_of_lading/bill_of_lading_v1_carrier_item.rbs +3 -3
  162. data/sig/mindee/product/bill_of_lading/bill_of_lading_v1_consignee.rbs +2 -2
  163. data/sig/mindee/product/bill_of_lading/bill_of_lading_v1_document.rbs +1 -1
  164. data/sig/mindee/product/bill_of_lading/bill_of_lading_v1_notify_party.rbs +2 -2
  165. data/sig/mindee/product/bill_of_lading/bill_of_lading_v1_page.rbs +2 -2
  166. data/sig/mindee/product/bill_of_lading/bill_of_lading_v1_shipper.rbs +2 -2
  167. data/sig/mindee/product/business_card/business_card_v1.rbs +1 -1
  168. data/sig/mindee/product/business_card/business_card_v1_document.rbs +1 -1
  169. data/sig/mindee/product/business_card/business_card_v1_page.rbs +2 -2
  170. data/sig/mindee/product/cropper/cropper_v1.rbs +1 -1
  171. data/sig/mindee/product/cropper/cropper_v1_document.rbs +1 -1
  172. data/sig/mindee/product/cropper/cropper_v1_page.rbs +2 -2
  173. data/sig/mindee/product/delivery_note/delivery_note_v1.rbs +1 -1
  174. data/sig/mindee/product/delivery_note/delivery_note_v1_document.rbs +1 -1
  175. data/sig/mindee/product/delivery_note/delivery_note_v1_page.rbs +2 -2
  176. data/sig/mindee/product/driver_license/driver_license_v1.rbs +1 -1
  177. data/sig/mindee/product/driver_license/driver_license_v1_document.rbs +1 -1
  178. data/sig/mindee/product/driver_license/driver_license_v1_page.rbs +2 -2
  179. data/sig/mindee/product/financial_document/financial_document_v1.rbs +1 -1
  180. data/sig/mindee/product/financial_document/financial_document_v1_document.rbs +1 -1
  181. data/sig/mindee/product/financial_document/financial_document_v1_line_item.rbs +3 -3
  182. data/sig/mindee/product/financial_document/financial_document_v1_page.rbs +2 -2
  183. data/sig/mindee/product/fr/bank_account_details/bank_account_details_v1.rbs +1 -1
  184. data/sig/mindee/product/fr/bank_account_details/bank_account_details_v1_document.rbs +1 -1
  185. data/sig/mindee/product/fr/bank_account_details/bank_account_details_v1_page.rbs +2 -2
  186. data/sig/mindee/product/fr/bank_account_details/bank_account_details_v2.rbs +1 -1
  187. data/sig/mindee/product/fr/bank_account_details/bank_account_details_v2_bban.rbs +2 -2
  188. data/sig/mindee/product/fr/bank_account_details/bank_account_details_v2_document.rbs +1 -1
  189. data/sig/mindee/product/fr/bank_account_details/bank_account_details_v2_page.rbs +2 -2
  190. data/sig/mindee/product/fr/bank_statement/bank_statement_v2.rbs +1 -1
  191. data/sig/mindee/product/fr/bank_statement/bank_statement_v2_document.rbs +1 -1
  192. data/sig/mindee/product/fr/bank_statement/bank_statement_v2_page.rbs +2 -2
  193. data/sig/mindee/product/fr/bank_statement/bank_statement_v2_transaction.rbs +3 -3
  194. data/sig/mindee/product/fr/carte_grise/carte_grise_v1.rbs +1 -1
  195. data/sig/mindee/product/fr/carte_grise/carte_grise_v1_document.rbs +1 -1
  196. data/sig/mindee/product/fr/carte_grise/carte_grise_v1_page.rbs +2 -2
  197. data/sig/mindee/product/fr/energy_bill/energy_bill_v1.rbs +1 -1
  198. data/sig/mindee/product/fr/energy_bill/energy_bill_v1_document.rbs +1 -1
  199. data/sig/mindee/product/fr/energy_bill/energy_bill_v1_energy_consumer.rbs +2 -2
  200. data/sig/mindee/product/fr/energy_bill/energy_bill_v1_energy_supplier.rbs +2 -2
  201. data/sig/mindee/product/fr/energy_bill/energy_bill_v1_energy_usage.rbs +3 -3
  202. data/sig/mindee/product/fr/energy_bill/energy_bill_v1_meter_detail.rbs +2 -2
  203. data/sig/mindee/product/fr/energy_bill/energy_bill_v1_page.rbs +2 -2
  204. data/sig/mindee/product/fr/energy_bill/energy_bill_v1_subscription.rbs +3 -3
  205. data/sig/mindee/product/fr/energy_bill/energy_bill_v1_taxes_and_contribution.rbs +3 -3
  206. data/sig/mindee/product/fr/health_card/health_card_v1.rbs +1 -1
  207. data/sig/mindee/product/fr/health_card/health_card_v1_document.rbs +1 -1
  208. data/sig/mindee/product/fr/health_card/health_card_v1_page.rbs +2 -2
  209. data/sig/mindee/product/fr/id_card/id_card_v1.rbs +1 -1
  210. data/sig/mindee/product/fr/id_card/id_card_v1_document.rbs +1 -1
  211. data/sig/mindee/product/fr/id_card/id_card_v1_page.rbs +2 -2
  212. data/sig/mindee/product/fr/id_card/id_card_v2.rbs +1 -1
  213. data/sig/mindee/product/fr/id_card/id_card_v2_document.rbs +1 -1
  214. data/sig/mindee/product/fr/id_card/id_card_v2_page.rbs +2 -2
  215. data/sig/mindee/product/fr/payslip/payslip_v2.rbs +1 -1
  216. data/sig/mindee/product/fr/payslip/payslip_v2_bank_account_detail.rbs +2 -2
  217. data/sig/mindee/product/fr/payslip/payslip_v2_document.rbs +1 -1
  218. data/sig/mindee/product/fr/payslip/payslip_v2_employee.rbs +2 -2
  219. data/sig/mindee/product/fr/payslip/payslip_v2_employer.rbs +2 -2
  220. data/sig/mindee/product/fr/payslip/payslip_v2_employment.rbs +2 -2
  221. data/sig/mindee/product/fr/payslip/payslip_v2_page.rbs +2 -2
  222. data/sig/mindee/product/fr/payslip/payslip_v2_pay_detail.rbs +2 -2
  223. data/sig/mindee/product/fr/payslip/payslip_v2_pay_period.rbs +2 -2
  224. data/sig/mindee/product/fr/payslip/payslip_v2_pto.rbs +2 -2
  225. data/sig/mindee/product/fr/payslip/payslip_v2_salary_detail.rbs +3 -3
  226. data/sig/mindee/product/fr/payslip/payslip_v3.rbs +1 -1
  227. data/sig/mindee/product/fr/payslip/payslip_v3_bank_account_detail.rbs +2 -2
  228. data/sig/mindee/product/fr/payslip/payslip_v3_document.rbs +1 -1
  229. data/sig/mindee/product/fr/payslip/payslip_v3_employee.rbs +2 -2
  230. data/sig/mindee/product/fr/payslip/payslip_v3_employer.rbs +2 -2
  231. data/sig/mindee/product/fr/payslip/payslip_v3_employment.rbs +2 -2
  232. data/sig/mindee/product/fr/payslip/payslip_v3_page.rbs +2 -2
  233. data/sig/mindee/product/fr/payslip/payslip_v3_paid_time_off.rbs +3 -3
  234. data/sig/mindee/product/fr/payslip/payslip_v3_pay_detail.rbs +2 -2
  235. data/sig/mindee/product/fr/payslip/payslip_v3_pay_period.rbs +2 -2
  236. data/sig/mindee/product/fr/payslip/payslip_v3_salary_detail.rbs +3 -3
  237. data/sig/mindee/product/ind/indian_passport/indian_passport_v1.rbs +1 -1
  238. data/sig/mindee/product/ind/indian_passport/indian_passport_v1_document.rbs +1 -1
  239. data/sig/mindee/product/ind/indian_passport/indian_passport_v1_page.rbs +2 -2
  240. data/sig/mindee/product/international_id/international_id_v2.rbs +1 -1
  241. data/sig/mindee/product/international_id/international_id_v2_document.rbs +1 -1
  242. data/sig/mindee/product/international_id/international_id_v2_page.rbs +2 -2
  243. data/sig/mindee/product/invoice/invoice_v4.rbs +1 -1
  244. data/sig/mindee/product/invoice/invoice_v4_document.rbs +1 -1
  245. data/sig/mindee/product/invoice/invoice_v4_line_item.rbs +3 -3
  246. data/sig/mindee/product/invoice/invoice_v4_page.rbs +2 -2
  247. data/sig/mindee/product/invoice_splitter/invoice_splitter_v1.rbs +1 -1
  248. data/sig/mindee/product/invoice_splitter/invoice_splitter_v1_document.rbs +1 -1
  249. data/sig/mindee/product/invoice_splitter/invoice_splitter_v1_invoice_page_group.rbs +3 -3
  250. data/sig/mindee/product/invoice_splitter/invoice_splitter_v1_page.rbs +2 -2
  251. data/sig/mindee/product/multi_receipts_detector/multi_receipts_detector_v1.rbs +1 -1
  252. data/sig/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_document.rbs +1 -1
  253. data/sig/mindee/product/multi_receipts_detector/multi_receipts_detector_v1_page.rbs +2 -2
  254. data/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1.rbs +1 -1
  255. data/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_added_sugar.rbs +2 -2
  256. data/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_calorie.rbs +2 -2
  257. data/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_cholesterol.rbs +2 -2
  258. data/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_dietary_fiber.rbs +2 -2
  259. data/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_document.rbs +1 -1
  260. data/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_nutrient.rbs +3 -3
  261. data/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_page.rbs +2 -2
  262. data/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_protein.rbs +2 -2
  263. data/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_saturated_fat.rbs +2 -2
  264. data/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_serving_size.rbs +2 -2
  265. data/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_sodium.rbs +2 -2
  266. data/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_carbohydrate.rbs +2 -2
  267. data/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_fat.rbs +2 -2
  268. data/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_total_sugar.rbs +2 -2
  269. data/sig/mindee/product/nutrition_facts_label/nutrition_facts_label_v1_trans_fat.rbs +2 -2
  270. data/sig/mindee/product/passport/passport_v1.rbs +1 -1
  271. data/sig/mindee/product/passport/passport_v1_document.rbs +1 -1
  272. data/sig/mindee/product/passport/passport_v1_page.rbs +2 -2
  273. data/sig/mindee/product/receipt/receipt_v5.rbs +1 -1
  274. data/sig/mindee/product/receipt/receipt_v5_document.rbs +1 -1
  275. data/sig/mindee/product/receipt/receipt_v5_line_item.rbs +3 -3
  276. data/sig/mindee/product/receipt/receipt_v5_page.rbs +2 -2
  277. data/sig/mindee/product/resume/resume_v1.rbs +1 -1
  278. data/sig/mindee/product/resume/resume_v1_certificate.rbs +3 -3
  279. data/sig/mindee/product/resume/resume_v1_document.rbs +1 -1
  280. data/sig/mindee/product/resume/resume_v1_education.rbs +3 -3
  281. data/sig/mindee/product/resume/resume_v1_language.rbs +3 -3
  282. data/sig/mindee/product/resume/resume_v1_page.rbs +2 -2
  283. data/sig/mindee/product/resume/resume_v1_professional_experience.rbs +3 -3
  284. data/sig/mindee/product/resume/resume_v1_social_networks_url.rbs +3 -3
  285. data/sig/mindee/product/universal/universal.rbs +5 -5
  286. data/sig/mindee/product/universal/universal_document.rbs +1 -1
  287. data/sig/mindee/product/universal/universal_page.rbs +2 -2
  288. data/sig/mindee/product/universal/universal_prediction.rbs +5 -5
  289. data/sig/mindee/product/us/bank_check/bank_check_v1.rbs +1 -1
  290. data/sig/mindee/product/us/bank_check/bank_check_v1_document.rbs +1 -1
  291. data/sig/mindee/product/us/bank_check/bank_check_v1_page.rbs +2 -2
  292. data/sig/mindee/product/us/healthcare_card/healthcare_card_v1.rbs +1 -1
  293. data/sig/mindee/product/us/healthcare_card/healthcare_card_v1_copay.rbs +3 -3
  294. data/sig/mindee/product/us/healthcare_card/healthcare_card_v1_document.rbs +1 -1
  295. data/sig/mindee/product/us/healthcare_card/healthcare_card_v1_page.rbs +2 -2
  296. data/sig/mindee/product/us/us_mail/us_mail_v2.rbs +1 -1
  297. data/sig/mindee/product/us/us_mail/us_mail_v2_document.rbs +1 -1
  298. data/sig/mindee/product/us/us_mail/us_mail_v2_page.rbs +2 -2
  299. data/sig/mindee/product/us/us_mail/us_mail_v2_recipient_address.rbs +3 -3
  300. data/sig/mindee/product/us/us_mail/us_mail_v2_sender_address.rbs +2 -2
  301. data/sig/mindee/product/us/us_mail/us_mail_v3.rbs +1 -1
  302. data/sig/mindee/product/us/us_mail/us_mail_v3_document.rbs +1 -1
  303. data/sig/mindee/product/us/us_mail/us_mail_v3_page.rbs +2 -2
  304. data/sig/mindee/product/us/us_mail/us_mail_v3_recipient_address.rbs +3 -3
  305. data/sig/mindee/product/us/us_mail/us_mail_v3_sender_address.rbs +2 -2
  306. data/sig/mindee/product/us/w9/w9_v1.rbs +1 -1
  307. data/sig/mindee/product/us/w9/w9_v1_document.rbs +1 -1
  308. data/sig/mindee/product/us/w9/w9_v1_page.rbs +2 -2
  309. data/sig/mindee/version.rbs +2 -2
  310. metadata +61 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c37efc128220eca42a9c5af127911697d47bd4179166d9faec47f04988221d4d
4
- data.tar.gz: da2158c80baa262b083baf4696a5d5f2d6b4226999713262419a4c98165cbd80
3
+ metadata.gz: 95c963d2c0530278f42fa3543609db9f34156d74e031c08c929be8043794425e
4
+ data.tar.gz: 92b4cfd60be3f710de9bdab714d4291b152d6d253373dcfae20428a940ad5ec9
5
5
  SHA512:
6
- metadata.gz: d5c02591130934ad5dcd7e6a87a22e753f4a3cf7bed31a0913c9f4296cc5ed4f741d085267a59d171d6e7146b34542878ae03ca920060ec9ef2e113c9bbd6f74
7
- data.tar.gz: 6ba9a4dee2c426885452d19805bfd1582ecf76f0902c420d32cc6c7521085e50a2eb5c8ec7368a820612ae425ae37bdf53487df486d29275a534c87cfbc93f3f
6
+ metadata.gz: 64be40a13e4662730c5749d5348860abf30e0c44002e4501d19a99a8c51c4afb2a83f9d901b1b3b4bbc43d255d8db3a27410b4ff5d274028092b7ec1368d830d
7
+ data.tar.gz: 5e9201f8c7d9beee93f601e0fe12758c20f55175c7c0476544bada2d1f8a7828962c848c75bb882169dea9c677649f53b3e0eba824cbdc559810f196fb3c0a75
data/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Mindee Ruby API Library Changelog
2
2
 
3
+ ## v4.7.0-rc2 - 2025-08-20
4
+ ### Changes
5
+ * :sparkles: add missing accessors for PDF fixing options in `LocalInputSource`
6
+ ### Fixes
7
+ * :recycle: update existing PDF fixing syntax
8
+ * :memo: fix typos & documentation
9
+
10
+
11
+ ## v4.7.0-rc1 - 2025-08-13
12
+ ### Changes
13
+ * :sparkles: add support for client V2 & associated features
14
+
15
+ ### Fixes
16
+ * :recycle: add many missing internal types
17
+ * :bug: fix invalid types for many V1 features
18
+ * :bug: fix V1 errors sometimes having the wrong code
19
+ * :bug: fix many presumably immutable fields having non-readonly parameters
20
+ * :bug: fix broken `resources` accessor in `ApiRequest` object
21
+
22
+
3
23
  ## v4.6.0 - 2025-06-03
4
24
  ### Changes
5
25
  * :sparkles: add support for address fields
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
+ inference_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
+ inference_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
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
@@ -16,7 +16,7 @@ module Mindee
16
16
  # @param mime_type [String]
17
17
  def initialize(mime_type)
18
18
  @invalid_mimetype = mime_type
19
- super("'#{@invalid_mimetype}' mime type not allowed, must be one of" \
19
+ super("'#{@invalid_mimetype}' mime type not allowed, must be one of " \
20
20
  "#{Mindee::Input::Source::ALLOWED_MIME_TYPES.join(', ')}")
21
21
  end
22
22
  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'
@@ -6,9 +6,9 @@ module Mindee
6
6
  # A relative set of coordinates (X, Y) on the document.
7
7
  class Point
8
8
  # @return [Float]
9
- attr_accessor :x
9
+ attr_reader :x
10
10
  # @return [Float]
11
- attr_accessor :y
11
+ attr_reader :y
12
12
 
13
13
  # rubocop:disable Naming/MethodParameterName
14
14
 
@@ -6,13 +6,13 @@ module Mindee
6
6
  # Contains exactly 4 relative vertices coordinates (Points).
7
7
  class Quadrilateral
8
8
  # @return [Mindee::Geometry::Point]
9
- attr_accessor :top_left
9
+ attr_reader :top_left
10
10
  # @return [Mindee::Geometry::Point]
11
- attr_accessor :top_right
11
+ attr_reader :top_right
12
12
  # @return [Mindee::Geometry::Point]
13
- attr_accessor :bottom_right
13
+ attr_reader :bottom_right
14
14
  # @return [Mindee::Geometry::Point]
15
- attr_accessor :bottom_left
15
+ attr_reader :bottom_left
16
16
 
17
17
  # @param top_left [Mindee::Geometry::Point]
18
18
  # @param top_right [Mindee::Geometry::Point]
@@ -83,6 +83,7 @@ module Mindee
83
83
  # @param anchor [Array<Mindee::Geometry::Point] Reference polygon
84
84
  # @param margin_left [Float] Margin tolerance on the left of the anchor
85
85
  # @param margin_right [Float] Margin tolerance on the right of the anchor
86
+ # @return bool
86
87
  def self.below?(candidate, anchor, margin_left, margin_right)
87
88
  return false if Geometry.get_min_max_y(candidate).min < Geometry.get_min_max_y(anchor).min
88
89
  if Geometry.get_min_max_x(candidate).min <
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mindee
4
+ module HTTP
5
+ # API client for version 2.
6
+ class ApiSettingsV2
7
+ # V2 API key's default environment key name.
8
+ MINDEE_V2_API_KEY_ENV_NAME = 'MINDEE_V2_API_KEY'
9
+ # V2 API key's default value.
10
+ MINDEE_V2_API_KEY_DEFAULT = nil
11
+
12
+ # V2 base URL default environment key name.
13
+ MINDEE_V2_BASE_URL_ENV_NAME = 'MINDEE_V2_BASE_URL'
14
+ # V2 base URL default value.
15
+ MINDEE_V2_BASE_URL_DEFAULT = 'https://api-v2.mindee.net/v2'
16
+
17
+ # HTTP request timeout default environment key name.
18
+ MINDEE_V2_REQUEST_TIMEOUT_ENV_NAME = 'MINDEE_V2_REQUEST_TIMEOUT'
19
+ # HTTP request timeout default value.
20
+ MINDEE_V2_TIMEOUT_DEFAULT = 120
21
+
22
+ # Default value for the user agent (same as V1).
23
+ USER_AGENT = "mindee-api-ruby@v#{Mindee::VERSION} ruby-v#{RUBY_VERSION} #{Mindee::PLATFORM}".freeze
24
+
25
+ # @return [String]
26
+ attr_reader :api_key
27
+ # @return [Integer]
28
+ attr_reader :request_timeout
29
+ # @return [String]
30
+ attr_reader :base_url
31
+ # @return [String]
32
+ attr_reader :user_agent
33
+
34
+ def initialize(api_key: nil)
35
+ @request_timeout = ENV.fetch(MINDEE_V2_REQUEST_TIMEOUT_ENV_NAME, MINDEE_V2_TIMEOUT_DEFAULT).to_i
36
+ if api_key.nil? && !ENV.fetch(MINDEE_V2_API_KEY_ENV_NAME, MINDEE_V2_API_KEY_DEFAULT).to_s.empty?
37
+ logger.debug('API key set from environment')
38
+ end
39
+ @api_key = if api_key.nil? || api_key.empty?
40
+ ENV.fetch(MINDEE_V2_API_KEY_ENV_NAME,
41
+ MINDEE_V2_API_KEY_DEFAULT)
42
+ else
43
+ api_key
44
+ end
45
+ @base_url = ENV.fetch(MINDEE_V2_BASE_URL_ENV_NAME, MINDEE_V2_BASE_URL_DEFAULT).chomp('/')
46
+ @user_agent = USER_AGENT
47
+ end
48
+
49
+ # Checks API key for a value.
50
+ # @return
51
+ # @raise [Errors::MindeeAPIError] Raises if the api key is empty or nil.
52
+ def check_api_key
53
+ return unless @api_key.nil? || @api_key.to_s.empty?
54
+
55
+ raise Errors::MindeeAPIError,
56
+ "Missing API key. check your Client Configuration.\nYou can set this using the " \
57
+ "'#{MINDEE_V2_API_KEY_ENV_NAME}' environment variable."
58
+ end
59
+ end
60
+ end
61
+ end