@@ -25,8 +25,13 @@ Where `${mindee.sdk.version}` is the version shown here:
2525## Loading a File and Parsing It
2626The ` MindeeClient ` class is the entry point for most of the helper library features.
2727
28+ ## Synchronously Parsing a File
29+ This is the easiest and fastest way to integrate into the Mindee API.
30+
31+ However, not all products are available in synchronous mode.
32+
2833### Global Documents
29- These classes are available in the ` com.mindee.product ` package:
34+ These classes are available in the ` com.mindee.product ` package:
3035
3136``` java
3237import com.mindee.MindeeClient ;
@@ -55,19 +60,24 @@ public class SimpleMindeeClient {
5560 System . out. println(response. getDocument(). toString());
5661 }
5762}
58-
5963```
6064
61- ### Region-Specific Documents
65+ ** Note for Region-Specific Documents:**
66+
6267Each region will have its own package within the general ` com.mindee.product ` package.
6368
6469For example USA-specific classes will be in the ` com.mindee.product.us ` package:
70+ ``` java
71+ import com.mindee.product.us.bankcheck.BankCheckV1 ;
72+ ```
6573
74+ ### Custom Documents (API Builder)
6675``` java
6776import com.mindee.MindeeClient ;
6877import com.mindee.input.LocalInputSource ;
6978import com.mindee.parsing.common.PredictResponse ;
70- import com.mindee.product.us.bankcheck.BankCheckV1 ;
79+ import com.mindee.product.custom.CustomV1 ;
80+ import com.mindee.http.Endpoint ;
7181import java.io.File ;
7282import java.io.IOException ;
7383
@@ -76,54 +86,113 @@ public class SimpleMindeeClient {
7686
7787 // Init a new client
7888 MindeeClient mindeeClient = new MindeeClient (" my-api-key" );
89+
90+ // Init the endpoint for the custom document
91+ Endpoint endpoint = new Endpoint (" my-endpoint" , " my-account" );
7992
8093 // Load a file from disk
8194 LocalInputSource localInputSource = new LocalInputSource (
82- " /path/to/the/file.ext "
95+ " src/main/resources/invoices/invoice1.pdf "
8396 );
8497 // Parse the file
85- Document<BankCheckV1 > response = mindeeClient. parse(
86- BankCheckV1 . class ,
87- localInputSource
98+ Document<CustomV1 > customDocument = mindeeClient. parse(
99+ localInputSource ,
100+ endpoint
88101 );
89- // Print a summary of the parsed data
90- System . out. println(response. getDocument(). toString());
91102 }
92103}
93104```
94105
95- ### Custom Documents (API Builder)
106+ ## Synchronously Parsing a File
107+ This allows for easier handling of bursts of documents sent.
108+
109+ Some products are only available asynchronously, check the example code
110+ directly on the Mindee platform.
111+
112+ ### Enqueue and Parse a File
113+ The client library will take care of handling the polling requests for you.
114+
115+ This is the easiest way to get started.
116+
96117``` java
97118import com.mindee.MindeeClient ;
98119import com.mindee.input.LocalInputSource ;
99- import com.mindee.parsing.common.PredictResponse ;
100- import com.mindee.product.custom.CustomV1 ;
101- import com.mindee.http.Endpoint ;
120+ import com.mindee.parsing.common.AsyncPredictResponse ;
121+ import com.mindee.product.internationalid.InternationalIdV2 ;
102122import java.io.File ;
103123import java.io.IOException ;
104124
125+ public class SimpleMindeeClient {
126+
127+ public static void main (String [] args ) throws IOException , InterruptedException {
128+ String apiKey = " my-api-key" ;
129+ String filePath = " /path/to/the/file.ext" ;
130+
131+ // Init a new client
132+ MindeeClient mindeeClient = new MindeeClient (apiKey);
133+
134+ // Load a file from disk
135+ LocalInputSource inputSource = new LocalInputSource (new File (filePath));
136+
137+ // Parse the file asynchronously
138+ AsyncPredictResponse<InternationalIdV2 > response = mindeeClient. enqueueAndParse(
139+ InternationalIdV2 . class,
140+ inputSource
141+ );
142+
143+ // Print a summary of the response
144+ System . out. println(response. toString());
145+ }
146+ }
147+ ```
148+
149+ ### Enqueue and Parse a Webhook Response
150+ This is an optional way of handling asynchronous APIs.
151+
152+ ``` java
153+ import com.mindee.MindeeClient ;
154+ import com.mindee.input.LocalInputSource ;
155+ import com.mindee.input.LocalResponse ;
156+ import com.mindee.input.WebhookSource ;
157+ import com.mindee.product.internationalid.InternationalIdV2 ;
158+
159+ import java.io.IOException ;
160+
105161public class SimpleMindeeClient {
106162 public static void main (String [] args ) throws IOException {
107163
108164 // Init a new client
109165 MindeeClient mindeeClient = new MindeeClient (" my-api-key" );
110-
111- // Init the endpoint for the custom document
112- Endpoint endpoint = new Endpoint (" my-endpoint" , " my-account" );
113166
114167 // Load a file from disk
115168 LocalInputSource localInputSource = new LocalInputSource (
116- " src/main/resources/invoices/invoice1.pdf "
169+ " /path/to/the/file.ext "
117170 );
118- // Parse the file
119- Document<CustomV1 > customDocument = mindeeClient. parse(
120- localInputSource,
121- endpoint
171+ // Enqueue the file
172+ String jobId = client. enqueue(InternationalIdV2 . class, localInputSource)
173+ .getJob(). getId();
174+
175+ // Load the JSON string sent by the Mindee webhook callback.
176+ //
177+ // Reading the callback data will vary greatly depending on which
178+ // HTTP server you are using, and is beyond the scope of this example.
179+ LocalResponse localResponse = new LocalResponse (" {'json': 'data'}" );
180+
181+ // You can also use a File object as the input.
182+ // LocalResponse localResponse = new LocalResponse(new File("/path/to/file.json"));
183+
184+ AsyncPredictResponse<InternationalIdV2 > response = mindeeClient. loadPrediction(
185+ InternationalIdV2 . class,
186+ new LocalResponse (webhookStream)
122187 );
188+
189+ // Print a summary of the parsed data
190+ System . out. println(response. getDocument(). toString());
123191 }
124192}
125193```
126194
195+
127196## Further Reading
128197Complete details on the working of the library are available in the following guides:
129198
0 commit comments