mindee 2.2.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +2 -0
  4. data/.yardopts +1 -0
  5. data/CHANGELOG.md +31 -0
  6. data/README.md +29 -16
  7. data/bin/mindee.rb +23 -26
  8. data/docs/code_samples/bank_account_details_v1.txt +10 -5
  9. data/docs/code_samples/bank_account_details_v2.txt +19 -0
  10. data/docs/code_samples/bank_check_v1.txt +10 -5
  11. data/docs/code_samples/carte_vitale_v1.txt +10 -5
  12. data/docs/code_samples/custom_v1.txt +19 -10
  13. data/docs/code_samples/default.txt +10 -2
  14. data/docs/code_samples/expense_receipts_v4.txt +10 -5
  15. data/docs/code_samples/expense_receipts_v5.txt +11 -6
  16. data/docs/code_samples/financial_document_v1.txt +10 -5
  17. data/docs/code_samples/idcard_fr_v1.txt +10 -5
  18. data/docs/code_samples/invoice_splitter_v1_async.txt +66 -0
  19. data/docs/code_samples/invoices_v4.txt +10 -5
  20. data/docs/code_samples/license_plates_v1.txt +10 -5
  21. data/docs/code_samples/passport_v1.txt +10 -5
  22. data/docs/code_samples/proof_of_address_v1.txt +10 -5
  23. data/docs/ruby-api-builder.md +30 -31
  24. data/docs/ruby-getting-started.md +64 -23
  25. data/docs/ruby-invoice-ocr.md +70 -59
  26. data/docs/ruby-passport-ocr.md +49 -40
  27. data/docs/ruby-receipt-ocr.md +45 -32
  28. data/lib/mindee/client.rb +150 -148
  29. data/lib/mindee/geometry/min_max.rb +23 -0
  30. data/lib/mindee/geometry/point.rb +35 -0
  31. data/lib/mindee/geometry/polygon.rb +23 -0
  32. data/lib/mindee/geometry/quadrilateral.rb +45 -0
  33. data/lib/mindee/geometry/utils.rb +81 -0
  34. data/lib/mindee/geometry.rb +5 -116
  35. data/lib/mindee/http/endpoint.rb +123 -16
  36. data/lib/mindee/http.rb +3 -0
  37. data/lib/mindee/input/sources.rb +87 -73
  38. data/lib/mindee/parsing/common/api_response.rb +109 -0
  39. data/lib/mindee/parsing/common/document.rb +48 -0
  40. data/lib/mindee/parsing/common/error.rb +24 -0
  41. data/lib/mindee/parsing/common/inference.rb +43 -0
  42. data/lib/mindee/parsing/common/ocr/mvision_v1.rb +34 -0
  43. data/lib/mindee/parsing/common/ocr/ocr.rb +169 -0
  44. data/lib/mindee/parsing/common/ocr.rb +3 -0
  45. data/lib/mindee/parsing/common/orientation.rb +26 -0
  46. data/lib/mindee/parsing/common/page.rb +40 -0
  47. data/lib/mindee/parsing/common/prediction.rb +15 -0
  48. data/lib/mindee/parsing/common/product.rb +19 -0
  49. data/lib/mindee/parsing/common.rb +10 -0
  50. data/lib/mindee/parsing/custom/classification_field.rb +28 -0
  51. data/lib/mindee/parsing/custom/list_field.rb +76 -0
  52. data/lib/mindee/parsing/custom.rb +4 -0
  53. data/lib/mindee/parsing/standard/amount_field.rb +26 -0
  54. data/lib/mindee/parsing/standard/base_field.rb +104 -0
  55. data/lib/mindee/parsing/standard/classification_field.rb +16 -0
  56. data/lib/mindee/parsing/standard/company_registration_field.rb +21 -0
  57. data/lib/mindee/parsing/standard/date_field.rb +34 -0
  58. data/lib/mindee/parsing/standard/locale_field.rb +50 -0
  59. data/lib/mindee/parsing/standard/payment_details_field.rb +42 -0
  60. data/lib/mindee/parsing/standard/position_field.rb +44 -0
  61. data/lib/mindee/parsing/standard/tax_field.rb +108 -0
  62. data/lib/mindee/parsing/standard/text_field.rb +16 -0
  63. data/lib/mindee/parsing/standard.rb +12 -0
  64. data/lib/mindee/parsing.rb +3 -2
  65. data/lib/mindee/{input → pdf}/pdf_processing.rb +4 -32
  66. data/lib/mindee/pdf/pdf_tools.rb +34 -0
  67. data/lib/mindee/pdf.rb +3 -0
  68. data/lib/mindee/product/.rubocop.yml +5 -0
  69. data/lib/mindee/product/custom/custom_v1.rb +35 -0
  70. data/lib/mindee/product/custom/custom_v1_document.rb +60 -0
  71. data/lib/mindee/product/custom/custom_v1_page.rb +32 -0
  72. data/lib/mindee/product/eu/license_plate/license_plate_v1.rb +38 -0
  73. data/lib/mindee/product/eu/license_plate/license_plate_v1_document.rb +37 -0
  74. data/lib/mindee/product/eu/license_plate/license_plate_v1_page.rb +34 -0
  75. data/lib/mindee/product/financial_document/financial_document_v1.rb +36 -0
  76. data/lib/mindee/product/financial_document/financial_document_v1_document.rb +188 -0
  77. data/lib/mindee/product/financial_document/financial_document_v1_line_item.rb +90 -0
  78. data/lib/mindee/product/financial_document/financial_document_v1_page.rb +32 -0
  79. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v1.rb +38 -0
  80. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v1_document.rb +43 -0
  81. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v1_page.rb +34 -0
  82. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v2.rb +38 -0
  83. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_bban.rb +71 -0
  84. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_document.rb +58 -0
  85. data/lib/mindee/product/fr/bank_account_details/bank_account_details_v2_page.rb +34 -0
  86. data/lib/mindee/product/fr/carte_vitale/carte_vitale_v1.rb +38 -0
  87. data/lib/mindee/product/fr/carte_vitale/carte_vitale_v1_document.rb +52 -0
  88. data/lib/mindee/product/fr/carte_vitale/carte_vitale_v1_page.rb +34 -0
  89. data/lib/mindee/product/fr/id_card/id_card_v1.rb +38 -0
  90. data/lib/mindee/product/fr/id_card/id_card_v1_document.rb +82 -0
  91. data/lib/mindee/product/fr/id_card/id_card_v1_page.rb +48 -0
  92. data/lib/mindee/product/invoice/invoice_v4.rb +37 -0
  93. data/lib/mindee/product/invoice/invoice_v4_document.rb +212 -0
  94. data/lib/mindee/product/invoice/invoice_v4_line_item.rb +66 -0
  95. data/lib/mindee/product/invoice/invoice_v4_page.rb +32 -0
  96. data/lib/mindee/product/invoice_splitter/invoice_splitter_v1.rb +36 -0
  97. data/lib/mindee/product/invoice_splitter/invoice_splitter_v1_document.rb +65 -0
  98. data/lib/mindee/product/invoice_splitter/invoice_splitter_v1_page.rb +32 -0
  99. data/lib/mindee/product/passport/passport_v1.rb +36 -0
  100. data/lib/mindee/{parsing/prediction/fr/id_card/id_card_v1.rb → product/passport/passport_v1_document.rb} +45 -45
  101. data/lib/mindee/product/passport/passport_v1_page.rb +32 -0
  102. data/lib/mindee/product/proof_of_address/proof_of_address_v1.rb +36 -0
  103. data/lib/mindee/product/proof_of_address/proof_of_address_v1_document.rb +83 -0
  104. data/lib/mindee/product/proof_of_address/proof_of_address_v1_page.rb +32 -0
  105. data/lib/mindee/product/receipt/receipt_v4.rb +36 -0
  106. data/lib/mindee/product/receipt/receipt_v4_document.rb +86 -0
  107. data/lib/mindee/product/receipt/receipt_v4_page.rb +32 -0
  108. data/lib/mindee/product/receipt/receipt_v5.rb +36 -0
  109. data/lib/mindee/product/receipt/receipt_v5_document.rb +138 -0
  110. data/lib/mindee/product/receipt/receipt_v5_line_item.rb +69 -0
  111. data/lib/mindee/product/receipt/receipt_v5_page.rb +32 -0
  112. data/lib/mindee/product/us/bank_check/bank_check_v1.rb +38 -0
  113. data/lib/mindee/product/us/bank_check/bank_check_v1_document.rb +73 -0
  114. data/lib/mindee/product/us/bank_check/bank_check_v1_page.rb +34 -0
  115. data/lib/mindee/product.rb +16 -0
  116. data/lib/mindee/version.rb +2 -1
  117. data/lib/mindee.rb +3 -1
  118. metadata +87 -38
  119. data/docs/code_samples/shipping_containers_v1.txt +0 -14
  120. data/lib/mindee/document_config.rb +0 -60
  121. data/lib/mindee/parsing/document.rb +0 -31
  122. data/lib/mindee/parsing/error.rb +0 -22
  123. data/lib/mindee/parsing/inference.rb +0 -53
  124. data/lib/mindee/parsing/page.rb +0 -46
  125. data/lib/mindee/parsing/prediction/base.rb +0 -30
  126. data/lib/mindee/parsing/prediction/common_fields/amount.rb +0 -21
  127. data/lib/mindee/parsing/prediction/common_fields/base.rb +0 -72
  128. data/lib/mindee/parsing/prediction/common_fields/company_registration.rb +0 -17
  129. data/lib/mindee/parsing/prediction/common_fields/date.rb +0 -30
  130. data/lib/mindee/parsing/prediction/common_fields/locale.rb +0 -45
  131. data/lib/mindee/parsing/prediction/common_fields/payment_details.rb +0 -33
  132. data/lib/mindee/parsing/prediction/common_fields/position.rb +0 -39
  133. data/lib/mindee/parsing/prediction/common_fields/tax.rb +0 -44
  134. data/lib/mindee/parsing/prediction/common_fields/text.rb +0 -12
  135. data/lib/mindee/parsing/prediction/common_fields.rb +0 -11
  136. data/lib/mindee/parsing/prediction/custom/custom_v1.rb +0 -58
  137. data/lib/mindee/parsing/prediction/custom/fields.rb +0 -91
  138. data/lib/mindee/parsing/prediction/eu/license_plate/license_plate_v1.rb +0 -34
  139. data/lib/mindee/parsing/prediction/financial_document/financial_document_v1.rb +0 -237
  140. data/lib/mindee/parsing/prediction/financial_document/financial_document_v1_line_item.rb +0 -58
  141. data/lib/mindee/parsing/prediction/fr/bank_account_details/bank_account_details_v1.rb +0 -40
  142. data/lib/mindee/parsing/prediction/fr/carte_vitale/carte_vitale_v1.rb +0 -49
  143. data/lib/mindee/parsing/prediction/invoice/invoice_v4.rb +0 -212
  144. data/lib/mindee/parsing/prediction/invoice/invoice_v4_line_item.rb +0 -58
  145. data/lib/mindee/parsing/prediction/passport/passport_v1.rb +0 -121
  146. data/lib/mindee/parsing/prediction/proof_of_address/proof_of_address_v1.rb +0 -80
  147. data/lib/mindee/parsing/prediction/receipt/receipt_v4.rb +0 -87
  148. data/lib/mindee/parsing/prediction/receipt/receipt_v5.rb +0 -136
  149. data/lib/mindee/parsing/prediction/receipt/receipt_v5_line_item.rb +0 -37
  150. data/lib/mindee/parsing/prediction/shipping_container/shipping_container_v1.rb +0 -38
  151. data/lib/mindee/parsing/prediction/us/bank_check/bank_check_v1.rb +0 -70
  152. data/lib/mindee/parsing/prediction.rb +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e72f138a729f4c2296fb6fa1913ae54b55b7e25e49134d20bc91c7a6a90c7ae
4
- data.tar.gz: cf14c3229afc27d75017c2a184ef661fafdae38d22af046d5aed4651ad3aeb31
3
+ metadata.gz: c81762ec2e42847a182b6b864355ba0268ad22995c24b361e54fd5380f8191f3
4
+ data.tar.gz: 771736fbe9d28b5d7a91c7cfee9a687da116f176c8226f866ab8bf175cab7b7f
5
5
  SHA512:
6
- metadata.gz: 89dc112d3507a28af8fbc91f38715cc504772fbd4a47808b36ee138da1368966bad4a8629f4cc4de2a70a381635f599fe8f7105c11d432879bb949b17b1c3304
7
- data.tar.gz: 24cd2c56da98a224aa6193d2bb0ba3d2dc7d0b397efcc7e2cd720d4e9d80a93c26b5adcc085ed1dd28d36e2619eb30cd86804ecb69dc3fc9901712cc830236ba
6
+ metadata.gz: 145a65bda997dc06a3ffafee6123d38195f66e6907c74097efca1a7d5bec9c8d70c041a7a58428e24be22a4850ff36e994a92024252735a815180032fe89f7a5
7
+ data.tar.gz: 605b1a9b1ffa2c0948581632eeca05e6462ce7f2280281740255183659648c7feb56ace62ec466cb69716f199a6a6467d4c5f1fa27e304fd83899b9a4dcfb2d9
data/.gitignore CHANGED
@@ -18,6 +18,7 @@
18
18
  _test.rb
19
19
  /vendor
20
20
  /mindee-*/
21
+ local-test
21
22
 
22
23
  # Used by dotenv library to load environment variables.
23
24
  .env
data/.rubocop.yml CHANGED
@@ -6,6 +6,8 @@ AllCops:
6
6
  - 'tmp/**/*'
7
7
  - '.git/**/*'
8
8
  - 'bin/*'
9
+ - _test.rb
10
+
9
11
  TargetRubyVersion: 2.6
10
12
  SuggestExtensions: false
11
13
 
data/.yardopts CHANGED
@@ -1,3 +1,4 @@
1
1
  --markup markdown
2
2
  --main README.md
3
+ --fail-on-warning
3
4
  --output-dir docs/_build
data/CHANGELOG.md CHANGED
@@ -1,5 +1,36 @@
1
1
  # Mindee Ruby API Library Changelog
2
2
 
3
+ ## v3.0.0 - 2023-06-29
4
+ ### ¡Breaking Changes!
5
+
6
+ * :boom: update `Client` creation & document upload
7
+ * :boom: update custom `Endpoint` creation syntax
8
+ * :art: improve product class syntax & structure
9
+ * :recycle: harmonize naming with other client libraries
10
+ * :art: moved most parsing modules into their own respective modules
11
+ * :art: separated common, standard & custom parsing features into their own modules
12
+
13
+ ### Changes
14
+
15
+ * :sparkles: add support for asynchronous endpoints
16
+ * :sparkles: add support for Invoice Splitter V1
17
+ * :sparkles: add support for OCR Full-text parsing on compatible APIs
18
+ * :sparkles: add support for FR Bank Account Details V2
19
+ * :sparkles: allow for the implementation of pages to differ from main document
20
+ * :sparkles: add url input source
21
+ * :coffin: remove Shipping Containers
22
+ * :recycle: moved all products into the `Product` module (from `Parsing`)
23
+ * :recycle: better implementation of geometric operations
24
+ * :pencil2: document all previously non-documented class
25
+ * :recycle: match file hierarchy with module nesting
26
+ * :recycle: rewrite tutorials to match new syntax
27
+
28
+ ### Fixes
29
+
30
+ * :bug: fix: pages now use the proper `orientation` property
31
+ * :zap: optimize: only a single endpoint is now created on document upload
32
+
33
+
3
34
  ## v2.2.1 - 2023-05-22
4
35
  ### Fixes
5
36
  * :bug: added base attribute to tax field
data/README.md CHANGED
@@ -32,12 +32,15 @@ require 'mindee'
32
32
  # Init a new client
33
33
  mindee_client = Mindee::Client.new(api_key: 'my-api-key')
34
34
 
35
- # Load a file from disk and parse it
36
- result = mindee_client.doc_from_path('/path/to/the/file.ext')
37
- .parse(Mindee::Prediction::InvoiceV4)
35
+ # Load a file from disk
36
+ input_source = mindee_client.source_from_path('/path/to/the/file.ext')
37
+ result = mindee_client.parse(
38
+ input_source,
39
+ Mindee::Product::Invoice::InvoiceV4
40
+ )
38
41
 
39
42
  # Print a full summary of the parsed data in RST format
40
- puts result
43
+ puts result.document
41
44
  ```
42
45
 
43
46
  #### Region-Specific Documents
@@ -47,12 +50,16 @@ require 'mindee'
47
50
  # Init a new client
48
51
  mindee_client = Mindee::Client.new(api_key: 'my-api-key')
49
52
 
50
- # Load a file from disk and parse it
51
- result = mindee_client.doc_from_path('/path/to/the/file.ext')
52
- .parse(Mindee::Prediction::EU::LicensePlateV1)
53
+ # Load a file from disk
54
+ input_source = mindee_client.source_from_path('/path/to/the/file.ext')
55
+
56
+ result = mindee_client.parse(
57
+ input_source,
58
+ Mindee::Product::EU::LicensePlate::LicensePlateV1
59
+ )
53
60
 
54
61
  # Print a full summary of the parsed data in RST format
55
- puts result
62
+ puts result.document
56
63
  ```
57
64
 
58
65
  ### Custom Document (API Builder)
@@ -60,20 +67,26 @@ puts result
60
67
  require 'mindee'
61
68
 
62
69
  # Init a new client and configure your custom document
63
- mindee_client = Mindee::Client.new(api_key: 'my-api-key').add_endpoint(
64
- 'my-account',
65
- 'my-endpoint'
70
+ mindee_client = Mindee::Client.new(api_key: 'my-api-key')
71
+ endpoint = mindee_client.create_endpoint(
72
+ endpoint_name: 'my-endpoint',
73
+ account_name: 'my-account'
66
74
  )
67
75
 
68
- # Load a file from disk and parse it
69
- result = mindee_client.doc_from_path('/path/to/the/file.ext')
70
- .parse(Mindee::Prediction::CustomV1, endpoint_name: 'my-endpoint')
76
+ # Load a file from disk
77
+ input_source = mindee_client.source_from_path('/path/to/the/file.ext')
78
+
79
+ result = mindee_client.parse(
80
+ input_source,
81
+ Mindee::Product::Custom::CustomV1,
82
+ endpoint: endpoint
83
+ )
71
84
 
72
85
  # Print a full summary of the parsed data in RST format
73
- puts result
86
+ puts result.document
74
87
 
75
88
  # Looping over all prediction values
76
- result.inference.prediction.fields.each do |field_name, field_data|
89
+ result.document.inference.prediction.fields.each do |field_name, field_data|
77
90
  puts field_name
78
91
  puts field_data.values
79
92
  puts field_data.to_s
data/bin/mindee.rb CHANGED
@@ -8,51 +8,51 @@ require 'mindee'
8
8
  DOCUMENTS = {
9
9
  "custom" => {
10
10
  help: "Custom document type from API builder",
11
- prediction: Mindee::Prediction::CustomV1,
11
+ prediction: Mindee::Product::Custom::CustomV1,
12
12
  },
13
13
  "proof-of-address" => {
14
14
  help: 'Proof of Address',
15
- prediction: Mindee::Prediction::ProofOfAddressV1,
15
+ prediction: Mindee::Product::ProofOfAddress::ProofOfAddressV1,
16
16
  },
17
17
  "financial-document" => {
18
18
  help: 'Financial Document',
19
- prediction: Mindee::Prediction::FinancialDocumentV1,
19
+ prediction: Mindee::Product::FinancialDocument::FinancialDocumentV1,
20
20
  },
21
21
  "invoice" => {
22
22
  help: 'Invoice',
23
- prediction: Mindee::Prediction::InvoiceV4,
23
+ prediction: Mindee::Product::Invoice::InvoiceV4,
24
24
  },
25
25
  "receipt" => {
26
26
  help: "Expense Receipt",
27
- prediction: Mindee::Prediction::ReceiptV5,
27
+ prediction: Mindee::Product::Receipt::ReceiptV5,
28
28
  },
29
29
  "passport" => {
30
30
  help: "Passport",
31
- prediction: Mindee::Prediction::PassportV1,
32
- },
33
- "shipping-container" => {
34
- help: "Shipping Container",
35
- prediction: Mindee::Prediction::ShippingContainerV1,
31
+ prediction: Mindee::Product::Passport::PassportV1,
36
32
  },
37
33
  "eu-license-plate" => {
38
34
  help: "EU License Plate",
39
- prediction: Mindee::Prediction::EU::LicensePlateV1,
35
+ prediction: Mindee::Product::EU::LicensePlate::LicensePlateV1,
40
36
  },
41
37
  "fr-bank-account-details" => {
42
38
  help: "FR Bank Account Details",
43
- prediction: Mindee::Prediction::FR::BankAccountDetailsV1,
39
+ prediction: Mindee::Product::FR::BankAccountDetails::BankAccountDetailsV1,
44
40
  },
45
41
  "fr-carte-vitale" => {
46
42
  help: "FR Carte Vitale",
47
- prediction: Mindee::Prediction::FR::CarteVitaleV1,
43
+ prediction: Mindee::Product::FR::CarteVitale::CarteVitaleV1,
48
44
  },
49
45
  "fr-id-card" => {
50
46
  help: "FR ID Card",
51
- prediction: Mindee::Prediction::FR::IdCardV1,
47
+ prediction: Mindee::Product::FR::IdCard::IdCardV1,
52
48
  },
53
49
  "us-bank-check" => {
54
50
  help: "US Bank Check",
55
- prediction: Mindee::Prediction::US::BankCheckV1,
51
+ prediction: Mindee::Product::US::BankCheck::BankCheckV1,
52
+ },
53
+ "invoice-splitter" => {
54
+ help: "US Bank Check",
55
+ prediction: Mindee::Product::InvoiceSplitter::InvoiceSplitterV1,
56
56
  },
57
57
  }
58
58
 
@@ -67,8 +67,8 @@ def ots_subcommand(command, options)
67
67
  opt.on('-k [KEY]', '--key [KEY]', 'API key for the endpoint') do |v|
68
68
  options[:api_key] = v
69
69
  end
70
- opt.on('-w', '--with-words', 'Include words in response') do |v|
71
- options[:include_words] = v
70
+ opt.on('-w', '--all-words', 'Include words in response') do |v|
71
+ options[:all_words] = v
72
72
  end
73
73
  opt.on('-c', '--cut-pages', "Cut document pages") do |v|
74
74
  options[:cut_pages] = v
@@ -79,8 +79,8 @@ end
79
79
  def custom_subcommand(options)
80
80
  OptionParser.new do |opt|
81
81
  opt.banner = "Usage: custom [options] ENDPOINT_NAME FILE"
82
- opt.on('-w', '--with-words', 'Include words in response') do |v|
83
- options[:include_words] = v
82
+ opt.on('-w', '--all-words', 'Include words in response') do |v|
83
+ options[:all_words] = v
84
84
  end
85
85
  opt.on('-c', '--cut-pages', "Don't cut document pages") do |v|
86
86
  options[:cut_pages] = v
@@ -127,9 +127,6 @@ if command == 'custom'
127
127
  end
128
128
  doc_type = ARGV[0]
129
129
  file_path = ARGV[1]
130
- mindee_client.add_endpoint(
131
- options[:account_name], doc_type, version: options[:version] || '1',
132
- )
133
130
  else
134
131
  if ARGV.length != 1
135
132
  $stderr.puts 'No file specified.'
@@ -145,10 +142,10 @@ default_cutting = {
145
142
  on_min_pages: 0,
146
143
  }
147
144
  page_options = options[:cut_pages].nil? ? nil : default_cutting
148
- doc = mindee_client.doc_from_path(file_path)
149
- result = doc.parse(DOCUMENTS[command][:prediction], endpoint_name: doc_type, page_options: page_options)
145
+ input_source = mindee_client.source_from_path(file_path)
146
+ result = mindee_client.parse(input_source, DOCUMENTS[command][:prediction], page_options: page_options)
150
147
  if options[:print_full]
151
- puts result
148
+ puts result.document
152
149
  else
153
- puts result.inference.prediction
150
+ puts result.document.inference.prediction
154
151
  end
@@ -3,12 +3,17 @@ require 'mindee'
3
3
  # Init a new client
4
4
  mindee_client = Mindee::Client.new(api_key: 'my-api-key')
5
5
 
6
- # Load a file from disk and parse it
7
- result = mindee_client.doc_from_path('/path/to/the/file.ext')
8
- .parse(Mindee::Prediction::FR::BankAccountDetailsV1)
6
+ # Load a file from disk
7
+ input_source = mindee_client.source_from_path('/path/to/the/file.ext')
8
+
9
+ # Parse the file
10
+ result = mindee_client.parse(
11
+ input_source,
12
+ Mindee::Product::FR::BankAccountDetails::BankAccountDetailsV1
13
+ )
9
14
 
10
15
  # Print a full summary of the parsed data in RST format
11
- puts result
16
+ puts result.document
12
17
 
13
18
  # Print the document-level parsed data
14
- # puts result.inference.prediction
19
+ # puts result.document.inference.prediction
@@ -0,0 +1,19 @@
1
+ require 'mindee'
2
+
3
+ # Init a new client
4
+ mindee_client = Mindee::Client.new(api_key: 'my-api-key')
5
+
6
+ # Load a file from disk
7
+ input_source = mindee_client.source_from_path('/path/to/the/file.ext')
8
+
9
+ # Parse the file
10
+ result = mindee_client.parse(
11
+ input_source,
12
+ Mindee::Product::FR::BankAccountDetails::BankAccountDetailsV2
13
+ )
14
+
15
+ # Print a full summary of the parsed data in RST format
16
+ puts result.document
17
+
18
+ # Print the document-level parsed data
19
+ # puts result.document.inference.prediction
@@ -3,12 +3,17 @@ require 'mindee'
3
3
  # Init a new client
4
4
  mindee_client = Mindee::Client.new(api_key: 'my-api-key')
5
5
 
6
- # Load a file from disk and parse it
7
- result = mindee_client.doc_from_path('/path/to/the/file.ext')
8
- .parse(Mindee::Prediction::US::BankCheckV1)
6
+ # Load a file from disk
7
+ input_source = mindee_client.source_from_path('/path/to/the/file.ext')
8
+
9
+ # Parse the file
10
+ result = mindee_client.parse(
11
+ input_source,
12
+ Mindee::Product::US::BankCheck::BankCheckV1
13
+ )
9
14
 
10
15
  # Print a full summary of the parsed data in RST format
11
- puts result
16
+ puts result.document
12
17
 
13
18
  # Print the document-level parsed data
14
- # puts result.inference.prediction
19
+ # puts result.document.inference.prediction
@@ -3,12 +3,17 @@ require 'mindee'
3
3
  # Init a new client
4
4
  mindee_client = Mindee::Client.new(api_key: 'my-api-key')
5
5
 
6
- # Load a file from disk and parse it
7
- result = mindee_client.doc_from_path('/path/to/the/file.ext')
8
- .parse(Mindee::Prediction::FR::CarteVitaleV1)
6
+ # Load a file from disk
7
+ input_source = mindee_client.source_from_path('/path/to/the/file.ext')
8
+
9
+ # Parse the file
10
+ result = mindee_client.parse(
11
+ input_source,
12
+ Mindee::Product::FR::CarteVitale::CarteVitaleV1
13
+ )
9
14
 
10
15
  # Print a full summary of the parsed data in RST format
11
- puts result
16
+ puts result.document
12
17
 
13
18
  # Print the document-level parsed data
14
- # puts result.inference.prediction
19
+ # puts result.document.inference.prediction
@@ -1,23 +1,32 @@
1
1
  require 'mindee'
2
2
 
3
- # Init a new client and configure your custom document
4
- mindee_client = Mindee::Client.new(api_key: 'my-api-key').add_endpoint(
5
- 'my-account',
6
- 'my-endpoint'
3
+ # Init a new client
4
+ mindee_client = Mindee::Client.new(api_key: 'my-api-key')
5
+
6
+ # Load a file from disk
7
+ input_source = mindee_client.source_from_path('/path/to/the/file.ext')
8
+
9
+ # Initialize a custom endpoint for this product
10
+ custom_endpoint = mindee_client.create_endpoint(
11
+ account_name: 'my-account',
12
+ endpoint_name: 'my-endpoint'
7
13
  )
8
14
 
9
- # Load a file from disk and parse it
10
- result = mindee_client.doc_from_path('/path/to/the/file.ext')
11
- .parse(Mindee::Prediction::CustomV1, endpoint_name: 'my-endpoint')
15
+ # Parse the file
16
+ result = mindee_client.parse(
17
+ input_source,
18
+ Mindee::Product::Custom::CustomV1,
19
+ endpoint: custom_endpoint
20
+ )
12
21
 
13
22
  # Print a full summary of the parsed data in RST format
14
- puts result
23
+ puts result.document
15
24
 
16
25
  # Print the document-level parsed data
17
- # puts result.inference.prediction
26
+ # puts result.document.inference.prediction
18
27
 
19
28
  # Looping over all prediction values
20
- result.inference.prediction.fields.each do |field_name, field_data|
29
+ result.document.inference.prediction.fields.each do |field_name, field_data|
21
30
  puts field_name
22
31
  puts field_data.values
23
32
  puts field_data.to_s
@@ -2,15 +2,23 @@ require 'uri'
2
2
  require 'net/http'
3
3
  require 'net/https'
4
4
 
5
- url = URI('https://api.mindee.net/v1/products/mindee/my-endpoint/my-version/predict')
5
+ api_key = "my-api-key"
6
+ account = "my-account"
7
+ endpoint = "my-endpoint"
8
+ version = "my-version"
9
+
10
+ url = URI("https://api.mindee.net/v1/products/#{account}/#{endpoint}/v#{version}/predict")
6
11
  file = '/path/to/the/file.ext'
7
12
 
8
13
  http = Net::HTTP.new(url.host, url.port)
9
14
  http.use_ssl = true
10
15
 
11
16
  request = Net::HTTP::Post.new(url)
12
- request['Authorization'] = 'Token my-api-key'
17
+ request['Authorization'] = "Token #{api_key}"
13
18
  request.set_form([['document', File.open(file)]], 'multipart/form-data')
14
19
 
15
20
  response = http.request(request)
21
+ if !response.kind_of? Net::HTTPSuccess
22
+ raise response.msg
23
+ end
16
24
  puts response.read_body
@@ -3,12 +3,17 @@ require 'mindee'
3
3
  # Init a new client
4
4
  mindee_client = Mindee::Client.new(api_key: 'my-api-key')
5
5
 
6
- # Load a file from disk and parse it
7
- result = mindee_client.doc_from_path('/path/to/the/file.ext')
8
- .parse(Mindee::Prediction::ReceiptV4)
6
+ # Load a file from disk
7
+ input_source = mindee_client.source_from_path('/path/to/the/file.ext')
8
+
9
+ # Parse the file
10
+ result = mindee_client.parse(
11
+ input_source,
12
+ Mindee::Product::Receipt::ReceiptV4
13
+ )
9
14
 
10
15
  # Print a full summary of the parsed data in RST format
11
- puts result
16
+ puts result.document
12
17
 
13
18
  # Print the document-level parsed data
14
- # puts result.inference.prediction
19
+ # puts result.document.inference.prediction
@@ -1,14 +1,19 @@
1
1
  require 'mindee'
2
2
 
3
- # Init a new client, specifying an API key
3
+ # Init a new client
4
4
  mindee_client = Mindee::Client.new(api_key: 'my-api-key')
5
5
 
6
- # Load a file from disk and parse it
7
- result = mindee_client.doc_from_path('/path/to/the/file.ext')
8
- .parse(Mindee::Prediction::ReceiptV5)
6
+ # Load a file from disk
7
+ input_source = mindee_client.source_from_path('/path/to/the/file.ext')
8
+
9
+ # Parse the file
10
+ result = mindee_client.parse(
11
+ input_source,
12
+ Mindee::Product::Receipt::ReceiptV5
13
+ )
9
14
 
10
15
  # Print a full summary of the parsed data in RST format
11
- puts result
16
+ puts result.document
12
17
 
13
18
  # Print the document-level parsed data
14
- # puts result.inference.prediction
19
+ # puts result.document.inference.prediction
@@ -3,12 +3,17 @@ require 'mindee'
3
3
  # Init a new client
4
4
  mindee_client = Mindee::Client.new(api_key: 'my-api-key')
5
5
 
6
- # Load a file from disk and parse it
7
- result = mindee_client.doc_from_path('/path/to/the/file.ext')
8
- .parse(Mindee::Prediction::FinancialDocumentV1)
6
+ # Load a file from disk
7
+ input_source = mindee_client.source_from_path('/path/to/the/file.ext')
8
+
9
+ # Parse the file
10
+ result = mindee_client.parse(
11
+ input_source,
12
+ Mindee::Product::FinancialDocument::FinancialDocumentV1
13
+ )
9
14
 
10
15
  # Print a full summary of the parsed data in RST format
11
- puts result
16
+ puts result.document
12
17
 
13
18
  # Print the document-level parsed data
14
- # puts result.inference.prediction
19
+ # puts result.document.inference.prediction
@@ -3,12 +3,17 @@ require 'mindee'
3
3
  # Init a new client
4
4
  mindee_client = Mindee::Client.new(api_key: 'my-api-key')
5
5
 
6
- # Load a file from disk and parse it
7
- result = mindee_client.doc_from_path('/path/to/the/file.ext')
8
- .parse(Mindee::Prediction::FR::IdCardV1)
6
+ # Load a file from disk
7
+ input_source = mindee_client.source_from_path('/path/to/the/file.ext')
8
+
9
+ # Parse the file
10
+ result = mindee_client.parse(
11
+ input_source,
12
+ Mindee::Product::FR::IdCard::IdCardV1
13
+ )
9
14
 
10
15
  # Print a full summary of the parsed data in RST format
11
- puts result
16
+ puts result.document
12
17
 
13
18
  # Print the document-level parsed data
14
- # puts result.inference.prediction
19
+ # puts result.document.inference.prediction
@@ -0,0 +1,66 @@
1
+ require 'mindee'
2
+
3
+ # Init a new client
4
+ mindee_client = Mindee::Client.new(api_key: 'my-api-key')
5
+
6
+ # Load a file from disk
7
+ input_source = mindee_client.source_from_path('/path/to/the/file.ext')
8
+
9
+ # Put the document class in a local variable to keep the code DRY
10
+ doc_class = Mindee::Product::InvoiceSplitter::InvoiceSplitterV1
11
+
12
+ # Limit the amount of API calls to retrieve your document
13
+ MAX_RETRIES = 10
14
+
15
+ # How many seconds to wait in-between tries
16
+ INTERVAL_SECS = 6
17
+
18
+ # Counter to keep track of how many times we try to retrieve the document
19
+ times_tried = 1
20
+
21
+ queue_result = mindee_client.enqueue(
22
+ input_source,
23
+ doc_class
24
+ )
25
+
26
+ # Get the id of the queue (job)
27
+ queue_id = queue_result.job.id
28
+
29
+ # Recursive function that tries to retrieve the completed document.
30
+ # If the document is not "complete", try again
31
+ def get_doc_from_async_queue(
32
+ queue_id,
33
+ mindee_client,
34
+ doc_class,
35
+ times_tried=0,
36
+ interval_secs=INTERVAL_SECS,
37
+ max_retries=MAX_RETRIES
38
+ )
39
+ # Have we exceeded our retry count?
40
+ if times_tried >= max_retries
41
+ raise "Maximum retries reached #{times_tried}"
42
+ end
43
+
44
+ # Wait for a few seconds before fetching
45
+ sleep interval_secs
46
+
47
+ # Fetch and parse the result, using the same type
48
+ parsed_result = mindee_client.parse_queued(queue_id, doc_class)
49
+
50
+ # Check whether the result is ready
51
+ if parsed_result.job.status == Mindee::Parsing::Common::JobStatus::COMPLETED
52
+ # Print a brief summary of the parsed data
53
+ puts parsed_result.document
54
+ return
55
+ # Otherwise, try again...
56
+ else
57
+ get_doc_from_async_queue(
58
+ queue_id, mindee_client,
59
+ doc_class,
60
+ times_tried+1
61
+ )
62
+ end
63
+ end
64
+
65
+ # Start the recursion...
66
+ get_doc_from_async_queue(queue_id, mindee_client, doc_class)
@@ -3,12 +3,17 @@ require 'mindee'
3
3
  # Init a new client
4
4
  mindee_client = Mindee::Client.new(api_key: 'my-api-key')
5
5
 
6
- # Load a file from disk and parse it
7
- result = mindee_client.doc_from_path('/path/to/the/file.ext')
8
- .parse(Mindee::Prediction::InvoiceV4)
6
+ # Load a file from disk
7
+ input_source = mindee_client.source_from_path('/path/to/the/file.ext')
8
+
9
+ # Parse the file
10
+ result = mindee_client.parse(
11
+ input_source,
12
+ Mindee::Product::Invoice::InvoiceV4
13
+ )
9
14
 
10
15
  # Print a full summary of the parsed data in RST format
11
- puts result
16
+ puts result.document
12
17
 
13
18
  # Print the document-level parsed data
14
- # puts result.inference.prediction
19
+ # puts result.document.inference.prediction
@@ -3,12 +3,17 @@ require 'mindee'
3
3
  # Init a new client
4
4
  mindee_client = Mindee::Client.new(api_key: 'my-api-key')
5
5
 
6
- # Load a file from disk and parse it
7
- result = mindee_client.doc_from_path('/path/to/the/file.ext')
8
- .parse(Mindee::Prediction::EU::LicensePlateV1)
6
+ # Load a file from disk
7
+ input_source = mindee_client.source_from_path('/path/to/the/file.ext')
8
+
9
+ # Parse the file
10
+ result = mindee_client.parse(
11
+ input_source,
12
+ Mindee::Product::EU::LicensePlate::LicensePlateV1
13
+ )
9
14
 
10
15
  # Print a full summary of the parsed data in RST format
11
- puts result
16
+ puts result.document
12
17
 
13
18
  # Print the document-level parsed data
14
- # puts result.inference.prediction
19
+ # puts result.document.inference.prediction
@@ -3,12 +3,17 @@ require 'mindee'
3
3
  # Init a new client
4
4
  mindee_client = Mindee::Client.new(api_key: 'my-api-key')
5
5
 
6
- # Load a file from disk and parse it
7
- result = mindee_client.doc_from_path('/path/to/the/file.ext')
8
- .parse(Mindee::Prediction::PassportV1)
6
+ # Load a file from disk
7
+ input_source = mindee_client.source_from_path('/path/to/the/file.ext')
8
+
9
+ # Parse the file
10
+ result = mindee_client.parse(
11
+ input_source,
12
+ Mindee::Product::Passport::PassportV1
13
+ )
9
14
 
10
15
  # Print a full summary of the parsed data in RST format
11
- puts result
16
+ puts result.document
12
17
 
13
18
  # Print the document-level parsed data
14
- # puts result.inference.prediction
19
+ # puts result.document.inference.prediction