Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ Install the package using Maven:
<dependency>
<groupId>com.veryfi</groupId>
<artifactId>veryfi-java</artifactId>
<version>2.0.0</version>
<version>2.1.0</version>
</dependency>
```
Install the package using Gradle:
```bash
implementation group: 'com.veryfi', name: 'veryfi-java', version: '2.0.0'
implementation group: 'com.veryfi', name: 'veryfi-java', version: '2.1.0'
```

## Getting Started
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.veryfi</groupId>
<artifactId>veryfi-java</artifactId>
<version>2.0.0</version>
<version>2.1.0</version>
<packaging>jar</packaging>
<name>veryfi-java</name>
<description>
Expand Down
40 changes: 40 additions & 0 deletions src/main/java/veryfi/Base64Helper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package veryfi;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Base64;

public class Base64Helper {

public static String getBase64FileContent(String filePath) throws IOException {
String fileName = filePath.replaceAll("^.*[/\\\\]", "");
File file = new File(filePath);
return getBase64FileContent(file);
}

public static String getBase64FileContent(File file) throws IOException {
String fileData = "";
byte[] fileContent = Files.readAllBytes(file.toPath());
fileData = Base64.getEncoder().encodeToString(fileContent);
return getUriPrefix(file) + fileData;
}

public static String getUriPrefix(File file) {
String extension = getFileExtension(file);
if (extension.isEmpty())
extension = "png";
return "data:image/" + extension + ";base64,";
}

protected static String getFileExtension(File file) {
String fileName = file.getName();
int dotIndex = fileName.lastIndexOf('.');
if (dotIndex > 0 && dotIndex < fileName.length() - 1) {
return fileName.substring(dotIndex + 1);
} else {
return "";
}
}

}
372 changes: 360 additions & 12 deletions src/main/java/veryfi/Client.java

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/main/java/veryfi/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private Constants() {
/**
* header for HttpRequest
*/
public static final String USER_AGENT_JAVA = "Java Veryfi-Java/2.0.0";
public static final String USER_AGENT_JAVA = "Java Veryfi-Java/2.1.0";
/**
* header for HttpRequest
*/
Expand Down
27 changes: 19 additions & 8 deletions src/main/java/veryfi/NetworkClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,22 @@ public void setHttpClient(HttpClient httpClient) {
this.httpClient = httpClient;
}

/**
* Creates the JSON Object for the parameters of the request
*
* @param fileName Name of the file to upload to the Veryfi API
* @param fileData Base64 encoded file data
* @param parameters Additional request parameters
* @return the JSON object of the parameters of the request
*/
protected JSONObject addFileToParameters(String fileName, String fileData, JSONObject parameters) {
if (parameters == null)
parameters = new JSONObject();
parameters.put(FILE_NAME, fileName);
parameters.put(FILE_DATA, fileData);
return parameters;
}

/**
* Creates the JSON Object for the parameters of the request
*
Expand All @@ -242,18 +258,13 @@ public void setHttpClient(HttpClient httpClient) {
protected JSONObject addFileToParameters(String filePath, JSONObject parameters) {
String fileName = filePath.replaceAll("^.*[/\\\\]", "");
File file = new File(filePath);
String base64EncodedString = "";
String fileData = "";
try {
byte[] fileContent = Files.readAllBytes(file.toPath());
base64EncodedString = Base64.getEncoder().encodeToString(fileContent);
fileData = Base64Helper.getBase64FileContent(file);
} catch (Exception e) {
logger.severe("addFileToParameters: " + e.getMessage());
}
if (parameters == null)
parameters = new JSONObject();
parameters.put(FILE_NAME, fileName);
parameters.put(FILE_DATA, base64EncodedString);
return parameters;
return addFileToParameters(fileName, fileData, parameters);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/veryfi/enums/Endpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ public enum Endpoint {
w2s("/partner/w2s/"),
w9s("/partner/w9s/"),
w8BenE("/partner/w-8ben-e/"),
contracts("/partner/contracts/");
contracts("/partner/contracts/"),
classify("/partner/classify/"),
split("/partner/documents-set/");

public final String path;

Expand Down
30 changes: 30 additions & 0 deletions src/main/java/veryfi/services/AnyDocumentServices.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,36 @@ protected CompletableFuture<String> processAnyDocumentAsync(String filePath, Str
return requestAsync(HttpMethod.POST, Endpoint.anyDocuments.path, parameters);
}

/**
* Process a Any Document and extract all the fields from it. https://docs.veryfi.com/api/anydocs/process-A-doc/
*
* @param fileName Name of the file to upload to the Veryfi API
* @param fileData Base64 encoded file data
* @param blueprintName The name of the extraction blueprints.
* @param parameters Additional request parameters.
* @return the data extracted from the Any Document {@link String}
*/
protected String processAnyDocument(String fileName, String fileData, String blueprintName, JSONObject parameters) {
parameters = addFileToParameters(fileName, fileData, parameters);
parameters.put("blueprint_name", blueprintName);
return request(HttpMethod.POST, Endpoint.anyDocuments.path, parameters);
}

/**
* Process a Any Document and extract all the fields from it. https://docs.veryfi.com/api/anydocs/process-A-doc/
*
* @param fileName Name of the file to upload to the Veryfi API
* @param fileData Base64 encoded file data
* @param blueprintName The name of the extraction blueprints.
* @param parameters Additional request parameters.
* @return the data extracted from the Any Document {@link CompletableFuture<String>}
*/
protected CompletableFuture<String> processAnyDocumentAsync(String fileName, String fileData, String blueprintName, JSONObject parameters) {
parameters = addFileToParameters(fileName, fileData, parameters);
parameters.put("blueprint_name", blueprintName);
return requestAsync(HttpMethod.POST, Endpoint.anyDocuments.path, parameters);
}

/**
* Process Any Document from url and extract all the fields from it. https://docs.veryfi.com/api/anydocs/process-A-doc/
*
Expand Down
28 changes: 27 additions & 1 deletion src/main/java/veryfi/services/BankStatementServices.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected CompletableFuture<String> getBankStatementAsync(String documentId) {
* Process a Bank Statement and extract all the fields from it. https://docs.veryfi.com/api/bank-statements/process-a-bank-statement/
*
* @param filePath Path on disk to a file to submit for data extraction.
* @param parameters Additional request parameters.
* @param parameters Additional request parameters.
* @return the data extracted from the Bank Statement {@link String}
*/
protected String processBankStatement(String filePath, JSONObject parameters) {
Expand All @@ -126,6 +126,32 @@ protected CompletableFuture<String> processBankStatementAsync(String filePath, J
return requestAsync(HttpMethod.POST, Endpoint.bankStatements.path, parameters);
}

/**
* Process a Bank Statement and extract all the fields from it. https://docs.veryfi.com/api/bank-statements/process-a-bank-statement/
*
* @param fileName Name of the file to upload to the Veryfi API
* @param fileData Base64 encoded file data
* @param parameters Additional request parameters
* @return the data extracted from the Bank Statement {@link String}
*/
protected String processBankStatement(String fileName, String fileData, JSONObject parameters) {
parameters = addFileToParameters(fileName, fileData, parameters);
return request(HttpMethod.POST, Endpoint.bankStatements.path, parameters);
}

/**
* Process a Bank Statement and extract all the fields from it. https://docs.veryfi.com/api/bank-statements/process-a-bank-statement/
*
* @param fileName Name of the file to upload to the Veryfi API
* @param fileData Base64 encoded file data
* @param parameters Additional request parameters
* @return the data extracted from the Bank Statement {@link CompletableFuture<String>}
*/
protected CompletableFuture<String> processBankStatementAsync(String fileName, String fileData, JSONObject parameters) {
parameters = addFileToParameters(fileName, fileData, parameters);
return requestAsync(HttpMethod.POST, Endpoint.bankStatements.path, parameters);
}

/**
* Process Bank Statement from url and extract all the fields from it. https://docs.veryfi.com/api/bank-statements/process-a-bank-statement/
*
Expand Down
28 changes: 27 additions & 1 deletion src/main/java/veryfi/services/BusinessCardsServices.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected CompletableFuture<String> getBusinessCardAsync(String documentId) {
* Process a Business Card and extract all the fields from it. https://docs.veryfi.com/api/business-cards/process-a-business-card/
*
* @param filePath Path on disk to a file to submit for data extraction.
* @param parameters Additional request parameters.
* @param parameters Additional request parameters.
* @return the data extracted from the Business Card {@link String}
*/
protected String processBusinessCard(String filePath, JSONObject parameters) {
Expand All @@ -126,6 +126,32 @@ protected CompletableFuture<String> processBusinessCardAsync(String filePath, JS
return requestAsync(HttpMethod.POST, Endpoint.businessCards.path, parameters);
}

/**
* Process a Business Card and extract all the fields from it. https://docs.veryfi.com/api/business-cards/process-a-business-card/
*
* @param fileName Name of the file to upload to the Veryfi API
* @param fileData Base64 encoded file data
* @param parameters Additional request parameters.
* @return the data extracted from the Business Card {@link String}
*/
protected String processBusinessCard(String fileName, String fileData, JSONObject parameters) {
parameters = addFileToParameters(fileName, fileData, parameters);
return request(HttpMethod.POST, Endpoint.businessCards.path, parameters);
}

/**
* Process a Business Card and extract all the fields from it. https://docs.veryfi.com/api/business-cards/process-a-business-card/
*
* @param fileName Name of the file to upload to the Veryfi API
* @param fileData Base64 encoded file data
* @param parameters Additional request parameters.
* @return the data extracted from the Business Card {@link CompletableFuture<String>}
*/
protected CompletableFuture<String> processBusinessCardAsync(String fileName, String fileData, JSONObject parameters) {
parameters = addFileToParameters(fileName, fileData, parameters);
return requestAsync(HttpMethod.POST, Endpoint.businessCards.path, parameters);
}

/**
* Process Business Card from url and extract all the fields from it. https://docs.veryfi.com/api/business-cards/process-a-business-card/
*
Expand Down
28 changes: 27 additions & 1 deletion src/main/java/veryfi/services/CheckServices.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected CompletableFuture<String> getCheckAsync(String documentId) {
* Process a Check and extract all the fields from it. https://docs.veryfi.com/api/checks/process-a-check/
*
* @param filePath Path on disk to a file to submit for data extraction.
* @param parameters Additional request parameters.
* @param parameters Additional request parameters.
* @return the data extracted from the Check {@link String}
*/
protected String processCheck(String filePath, JSONObject parameters) {
Expand All @@ -126,6 +126,32 @@ protected CompletableFuture<String> processCheckAsync(String filePath, JSONObjec
return requestAsync(HttpMethod.POST, Endpoint.checks.path, parameters);
}

/**
* Process a Check and extract all the fields from it. https://docs.veryfi.com/api/checks/process-a-check/
*
* @param fileName Name of the file to upload to the Veryfi API
* @param fileData Base64 encoded file data
* @param parameters Additional request parameters
* @return the data extracted from the Check {@link String}
*/
protected String processCheck(String fileName, String fileData, JSONObject parameters) {
parameters = addFileToParameters(fileName, fileData, parameters);
return request(HttpMethod.POST, Endpoint.checks.path, parameters);
}

/**
* Process a Check and extract all the fields from it. https://docs.veryfi.com/api/checks/process-a-check/
*
* @param fileName Name of the file to upload to the Veryfi API
* @param fileData Base64 encoded file data
* @param parameters Additional request parameters
* @return the data extracted from the Check {@link CompletableFuture<String>}
*/
protected CompletableFuture<String> processCheckAsync(String fileName, String fileData, JSONObject parameters) {
parameters = addFileToParameters(fileName, fileData, parameters);
return requestAsync(HttpMethod.POST, Endpoint.checks.path, parameters);
}

/**
* Process Check from url and extract all the fields from it. https://docs.veryfi.com/api/checks/process-a-check/
*
Expand Down
Loading
Loading