Skip to content

Commit 3b54424

Browse files
sebastianMindeeianardee
authored andcommitted
♻️ reworked entire project structure & syntax (#39)
1 parent 0e5190f commit 3b54424

File tree

165 files changed

+4547
-3322
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

165 files changed

+4547
-3322
lines changed

README.md

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ require 'mindee'
3333
mindee_client = Mindee::Client.new(api_key: 'my-api-key')
3434

3535
# 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)
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+
)
3841

3942
# Print a full summary of the parsed data in RST format
4043
puts result.document
@@ -48,8 +51,12 @@ require 'mindee'
4851
mindee_client = Mindee::Client.new(api_key: 'my-api-key')
4952

5053
# Load a file from disk and parse it
51-
doc = mindee_client.doc_from_path('/path/to/the/file.ext')
52-
result = doc.parse(Mindee::Prediction::EU::LicensePlateV1)
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+
)
5360

5461
# Print a full summary of the parsed data in RST format
5562
puts result.document
@@ -60,14 +67,20 @@ puts result.document
6067
require 'mindee'
6168

6269
# 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'
6674
)
6775

6876
# Load a file from disk and parse it
69-
doc = mindee_client.doc_from_path('/path/to/the/file.ext')
70-
result = mindee_client.parse(doc, Mindee::Prediction::CustomV1, endpoint_name: 'my-endpoint')
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+
)
7184

7285
# Print a full summary of the parsed data in RST format
7386
puts result.document

bin/mindee.rb

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,51 @@
88
DOCUMENTS = {
99
"custom" => {
1010
help: "Custom document type from API builder",
11-
prediction: Mindee::Prediction::CustomV1,
11+
prediction: Mindee::Product::Custom::CustomV1,
1212
},
1313
"proof-of-address" => {
1414
help: 'Proof of Address',
15-
prediction: Mindee::Prediction::ProofOfAddressV1,
15+
prediction: Mindee::Product::ProofOfAddress::ProofOfAddressV1,
1616
},
1717
"financial-document" => {
1818
help: 'Financial Document',
19-
prediction: Mindee::Prediction::FinancialDocumentV1,
19+
prediction: Mindee::Product::FinancialDocument::FinancialDocumentV1,
2020
},
2121
"invoice" => {
2222
help: 'Invoice',
23-
prediction: Mindee::Prediction::InvoiceV4,
23+
prediction: Mindee::Product::Invoice::InvoiceV4,
2424
},
2525
"receipt" => {
2626
help: "Expense Receipt",
27-
prediction: Mindee::Prediction::ReceiptV5,
27+
prediction: Mindee::Product::Receipt::ReceiptV5,
2828
},
2929
"passport" => {
3030
help: "Passport",
31-
prediction: Mindee::Prediction::PassportV1,
31+
prediction: Mindee::Product::Passport::PassportV1,
3232
},
3333
"eu-license-plate" => {
3434
help: "EU License Plate",
35-
prediction: Mindee::Prediction::EU::LicensePlateV1,
35+
prediction: Mindee::Product::EU::LicensePlate::LicensePlateV1,
3636
},
3737
"fr-bank-account-details" => {
3838
help: "FR Bank Account Details",
39-
prediction: Mindee::Prediction::FR::BankAccountDetailsV1,
39+
prediction: Mindee::Product::FR::BankAccountDetails::BankAccountDetailsV1,
4040
},
4141
"fr-carte-vitale" => {
4242
help: "FR Carte Vitale",
43-
prediction: Mindee::Prediction::FR::CarteVitaleV1,
43+
prediction: Mindee::Product::FR::CarteVitale::CarteVitaleV1,
4444
},
4545
"fr-id-card" => {
4646
help: "FR ID Card",
47-
prediction: Mindee::Prediction::FR::IdCardV1,
47+
prediction: Mindee::Product::FR::IdCard::IdCardV1,
4848
},
4949
"us-bank-check" => {
5050
help: "US Bank Check",
51-
prediction: Mindee::Prediction::US::BankCheckV1,
51+
prediction: Mindee::Product::US::BankCheck::BankCheckV1,
5252
},
5353
"invoice-splitter" => {
5454
help: "US Bank Check",
55-
prediction: Mindee::Prediction::InvoiceSplitterV1,
55+
prediction: Mindee::Product::InvoiceSplitter::InvoiceSplitterV1,
5656
},
5757
}
5858

@@ -127,9 +127,6 @@ def custom_subcommand(options)
127127
end
128128
doc_type = ARGV[0]
129129
file_path = ARGV[1]
130-
mindee_client.add_endpoint(
131-
options[:account_name], doc_type, version: options[:version] || '1',
132-
)
133130
else
134131
if ARGV.length != 1
135132
$stderr.puts 'No file specified.'
@@ -145,8 +142,8 @@ def custom_subcommand(options)
145142
on_min_pages: 0,
146143
}
147144
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)
150147
if options[:print_full]
151148
puts result.document
152149
else

docs/code_samples/bank_account_details_v1.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ require 'mindee'
33
# Init a new client
44
mindee_client = Mindee::Client.new(api_key: 'my-api-key')
55

6-
# Load a file from disk and parse it
7-
doc = mindee_client.doc_from_path('/path/to/the/file.ext')
8-
result = mindee_client.parse(doc, 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+
)
914

1015
# Print a full summary of the parsed data in RST format
1116
puts result.document

docs/code_samples/bank_check_v1.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ require 'mindee'
33
# Init a new client
44
mindee_client = Mindee::Client.new(api_key: 'my-api-key')
55

6-
# Load a file from disk and parse it
7-
doc = mindee_client.doc_from_path('/path/to/the/file.ext')
8-
result = mindee_client.parse(doc, 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+
)
914

1015
# Print a full summary of the parsed data in RST format
1116
puts result.document

docs/code_samples/carte_vitale_v1.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@ require 'mindee'
33
# Init a new client
44
mindee_client = Mindee::Client.new(api_key: 'my-api-key')
55

6-
# Load a file from disk and parse it
7-
doc = mindee_client.doc_from_path('/path/to/the/file.ext')
8-
result = mindee_client.parse(doc, 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+
)
914

1015
# Print a full summary of the parsed data in RST format
1116
puts result.document
1217

1318
# Print the document-level parsed data
14-
# puts result.document.inference.prediction
19+
# puts result.document.inference.prediction

docs/code_samples/custom_v1.txt

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
require 'mindee'
22

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'
7-
)
3+
# Init a new client
4+
mindee_client = Mindee::Client.new(api_key: 'my-api-key')
85

96
# Load a file from disk and parse it
10-
doc = mindee_client.doc_from_path('/path/to/the/file.ext')
11-
result = mindee_client.parse(doc, Mindee::Prediction::CustomV1, endpoint_name: 'my-endpoint')
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'
13+
)
14+
15+
# Send our document
16+
result = mindee_client.parse(
17+
input_source,
18+
Mindee::Product::Custom::CustomV1,
19+
endpoint: custom_endpoint
20+
)
1221

1322
# Print a full summary of the parsed data in RST format
1423
puts result.document

docs/code_samples/default.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,23 @@ require 'uri'
22
require 'net/http'
33
require 'net/https'
44

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")
611
file = '/path/to/the/file.ext'
712

813
http = Net::HTTP.new(url.host, url.port)
914
http.use_ssl = true
1015

1116
request = Net::HTTP::Post.new(url)
12-
request['Authorization'] = 'Token my-api-key'
17+
request['Authorization'] = "Token #{api_key}"
1318
request.set_form([['document', File.open(file)]], 'multipart/form-data')
1419

1520
response = http.request(request)
21+
if !response.kind_of? Net::HTTPSuccess
22+
raise response.msg
23+
end
1624
puts response.read_body

docs/code_samples/expense_receipts_v4.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ require 'mindee'
44
mindee_client = Mindee::Client.new(api_key: 'my-api-key')
55

66
# Load a file from disk and parse it
7-
doc = mindee_client.doc_from_path('/path/to/the/file.ext')
8-
result = mindee_client.parse(doc, Mindee::Prediction::ReceiptV4)
7+
input_source = mindee_client.source_from_path('/path/to/the/file.ext')
8+
9+
# Send our document
10+
result = mindee_client.parse(
11+
input_source,
12+
Mindee::Product::Receipt::ReceiptV4
13+
)
914

1015
# Print a full summary of the parsed data in RST format
1116
puts result.document

docs/code_samples/expense_receipts_v5.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
require 'mindee'
22

3-
# Init a new client, specifying an API key
3+
# Init a new client
44
mindee_client = Mindee::Client.new(api_key: 'my-api-key')
55

66
# Load a file from disk and parse it
7-
doc = mindee_client.doc_from_path('/path/to/the/file.ext')
8-
result = mindee_client.parse(doc, Mindee::Prediction::ReceiptV5)
7+
input_source = mindee_client.source_from_path('/path/to/the/file.ext')
8+
9+
# Send our document
10+
result = mindee_client.parse(
11+
input_source,
12+
Mindee::Product::Receipt::ReceiptV5
13+
)
914

1015
# Print a full summary of the parsed data in RST format
1116
puts result.document

docs/code_samples/financial_document_v1.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ require 'mindee'
44
mindee_client = Mindee::Client.new(api_key: 'my-api-key')
55

66
# Load a file from disk and parse it
7-
doc = mindee_client.doc_from_path('/path/to/the/file.ext')
8-
result = mindee_client.parse(doc, Mindee::Prediction::FinancialDocumentV1)
7+
input_source = mindee_client.source_from_path('/path/to/the/file.ext')
8+
9+
# Send our document
10+
result = mindee_client.parse(
11+
input_source,
12+
Mindee::Product::FinancialDocument::FinancialDocumentV1
13+
)
914

1015
# Print a full summary of the parsed data in RST format
1116
puts result.document

0 commit comments

Comments
 (0)