import com.mindee.MindeeClient;
import com.mindee.input.LocalInputSource;
import com.mindee.input.LocalResponse;
import com.mindee.input.WebhookSource;
import com.mindee.product.internationalid.InternationalIdV2;
import java.io.IOException;
public class SimpleMindeeClient {
public static void main(String[] args) throws IOException {
// Init a new client
MindeeClient mindeeClient = new MindeeClient("my-api-key");
// Load a file from disk
LocalInputSource localInputSource = new LocalInputSource(
"/path/to/the/file.ext"
);
// Enqueue the file
String jobId = client.enqueue(InternationalIdV2.class, localInputSource)
.getJob().getId();
// Load the JSON string sent by the Mindee webhook POST callback.
//
// Reading the callback data will vary greatly depending on your HTTP server.
// This is therefore beyond the scope of this example.
String jsonData = myHttpServer.getPostBodyAsString();
LocalResponse localResponse = new LocalResponse(jsonData);
// Verify the HMAC signature.
// You'll need to get the "X-Mindee-Hmac-Signature" custom HTTP header.
String hmacSignature = myHttpServer.getHeader("X-Mindee-Hmac-Signature");
boolean isValid = localResponse.isValidHmacSignature(
"obviously-fake-secret-key", hmacSignature
);
if (!isValid) {
throw new MyException("Bad HMAC signature! Is someone trying to do evil?");
}
// You can also use a File object as the input.
//LocalResponse localResponse = new LocalResponse(new File("/path/to/file.json"));
// Deserialize the response into Java objects
AsyncPredictResponse<InternationalIdV2> response = mindeeClient.loadPrediction(
InternationalIdV2.class,
localResponse
);
// Print a summary of the parsed data
System.out.println(response.getDocument().toString());
}
}