Package veryfi

Class ClientImpl

java.lang.Object
veryfi.ClientImpl
All Implemented Interfaces:
Client

public class ClientImpl extends Object implements Client
Veryfi API client for Java.
  • Field Details

    • logger

      private final Logger logger
    • clientId

      private final String clientId
    • clientSecret

      private final String clientSecret
    • username

      private final String username
    • apiKey

      private final String apiKey
    • apiVersion

      private final int apiVersion
    • baseUrl

      private String baseUrl
    • timeOut

      private int timeOut
    • httpClient

      private HttpClient httpClient
  • Constructor Details

    • ClientImpl

      public ClientImpl(String clientId, String clientSecret, String username, String apiKey, int apiVersion)
      Creates an instance of ClientImpl.
      Parameters:
      clientId - the String provided by Veryfi.
      clientSecret - the String provided by Veryfi.
      username - the String provided by Veryfi.
      apiKey - the String provided by Veryfi.
      apiVersion - the int api version to use Veryfi.
  • Method Details

    • getUrl

      private String getUrl()
      Returns a String API Base URL with API Version.
      Returns:
      the url String
    • request

      private String request(HttpMethod httpVerb, String endpointName, org.json.JSONObject requestArguments)
      Submit the HTTP request.
      Parameters:
      httpVerb - HTTP Method
      endpointName - Endpoint name such as 'documents', 'users', etc.
      requestArguments - JSON payload to send to Veryfi
      Returns:
      A JSON of the response data.
    • requestAsync

      private CompletableFuture<String> requestAsync(HttpMethod httpVerb, String endpointName, org.json.JSONObject requestArguments)
      Submit the HTTP request.
      Parameters:
      httpVerb - HTTP Method
      endpointName - Endpoint name such as 'documents', 'users', etc.
      requestArguments - JSON payload to send to Veryfi
      Returns:
      A JSON of the response data.
    • getHttpRequest

      private HttpRequest getHttpRequest(HttpMethod httpVerb, String endpointName, org.json.JSONObject requestArguments)
      Creates the HTTP request Object.
      Parameters:
      httpVerb - HTTP Method
      endpointName - Endpoint name such as 'documents', 'users', etc.
      requestArguments - JSON payload to send to Veryfi
      Returns:
      request Object for the HttpClient HttpRequest
    • getApiKey

      private String getApiKey()
      Returns a String ApiKey for the headers of the request.
      Returns:
      the ApiKey String
    • getHeaders

      private List<String> getHeaders(org.json.JSONObject requestArguments)
      Prepares the headers needed for a request.
      Parameters:
      requestArguments - JSON payload to send to Veryfi JSONObject
      Returns:
      List of the headers List<String>
    • generateSignature

      private String generateSignature(Long timeStamp, org.json.JSONObject payloadParams)
      Generate unique signature for payload params.
      Parameters:
      timeStamp - Unix Long timestamp
      payloadParams - JSON params to be sent to API request
      Returns:
      Unique signature generated using the client_secret and the payload
    • getDocuments

      public String getDocuments()
      Returns a json string String with the list of documents.
      Specified by:
      getDocuments in interface Client
      Returns:
      the url String
    • getDocumentsAsync

      public CompletableFuture<String> getDocumentsAsync()
      Returns a json string CompletableFuture<String> list of documents.
      Specified by:
      getDocumentsAsync in interface Client
      Returns:
      the list of previously processed documents String
    • getDocument

      public String getDocument(String documentId)
      Returns a json string String document information
      Specified by:
      getDocument in interface Client
      Parameters:
      documentId - ID of the document you'd like to retrieve.
      Returns:
      the data extracted from the Document String
    • getDocumentAsync

      public CompletableFuture<String> getDocumentAsync(String documentId)
      Returns a json string CompletableFuture<String> document information.
      Specified by:
      getDocumentAsync in interface Client
      Parameters:
      documentId - ID of the document you'd like to retrieve.
      Returns:
      the data extracted from the Document String
    • getProcessDocumentArguments

      public org.json.JSONObject getProcessDocumentArguments(String filePath, List<String> categories, boolean deleteAfterProcessing, org.json.JSONObject parameters)
      Creates the JSON Object for the parameters of the request
      Parameters:
      filePath - Path on disk to a file to submit for data extraction
      categories - List of categories Veryfi can use to categorize the document
      deleteAfterProcessing - Delete this document from Veryfi after data has been extracted
      parameters - Additional request parameters
      Returns:
      the JSON object of the parameters of the request
    • processDocument

      public String processDocument(String filePath, List<String> categories, boolean deleteAfterProcessing, org.json.JSONObject parameters)
      Process a document and extract all the fields from it
      Specified by:
      processDocument in interface Client
      Parameters:
      filePath - Path on disk to a file to submit for data extraction
      categories - List of categories Veryfi can use to categorize the document
      deleteAfterProcessing - Delete this document from Veryfi after data has been extracted
      parameters - Additional request parameters
      Returns:
      the data extracted from the Document String
    • processDocumentAsync

      public CompletableFuture<String> processDocumentAsync(String filePath, List<String> categories, boolean deleteAfterProcessing, org.json.JSONObject parameters)
      Process a document and extract all the fields from it
      Specified by:
      processDocumentAsync in interface Client
      Parameters:
      filePath - Path on disk to a file to submit for data extraction
      categories - List of categories Veryfi can use to categorize the document
      deleteAfterProcessing - Delete this document from Veryfi after data has been extracted
      parameters - Additional request parameters
      Returns:
      the data extracted from the Document CompletableFuture<String>
    • getProcessDocumentUrlArguments

      public org.json.JSONObject getProcessDocumentUrlArguments(String fileUrl, List<String> fileUrls, List<String> categories, boolean deleteAfterProcessing, int maxPagesToProcess, boolean boostMode, String externalId, org.json.JSONObject parameters)
      Creates the JSON object of the parameters of the request
      Parameters:
      fileUrl - Required if file_urls isn't specified. Publicly accessible URL to a file, e.g. "https://cdn.example.com/receipt.jpg".
      fileUrls - Required if file_url isn't specifies. List of publicly accessible URLs to multiple files, e.g. ["https://cdn.example.com/receipt1.jpg", "https://cdn.example.com/receipt2.jpg"]
      categories - List of categories to use when categorizing the document
      deleteAfterProcessing - Delete this document from Veryfi after data has been extracted
      maxPagesToProcess - When sending a long document to Veryfi for processing, this parameter controls how many pages of the document will be read and processed, starting from page 1.
      boostMode - Flag that tells Veryfi whether boost mode should be enabled. When set to 1, Veryfi will skip data enrichment steps, but will process the document faster. Default value for this flag is 0
      externalId - Optional custom document identifier. Use this if you would like to assign your own ID to documents
      parameters - Additional request parameters
      Returns:
      JSON object of the request arguments
    • processDocumentUrl

      public String processDocumentUrl(String fileUrl, List<String> fileUrls, List<String> categories, boolean deleteAfterProcessing, int maxPagesToProcess, boolean boostMode, String externalId, org.json.JSONObject parameters)
      Process Document from url and extract all the fields from it.
      Specified by:
      processDocumentUrl in interface Client
      Parameters:
      fileUrl - Required if file_urls isn't specified. Publicly accessible URL to a file, e.g. "https://cdn.example.com/receipt.jpg".
      fileUrls - Required if file_url isn't specifies. List of publicly accessible URLs to multiple files, e.g. ["https://cdn.example.com/receipt1.jpg", "https://cdn.example.com/receipt2.jpg"]
      categories - List of categories to use when categorizing the document
      deleteAfterProcessing - Delete this document from Veryfi after data has been extracted
      maxPagesToProcess - When sending a long document to Veryfi for processing, this parameter controls how many pages of the document will be read and processed, starting from page 1.
      boostMode - Flag that tells Veryfi whether boost mode should be enabled. When set to 1, Veryfi will skip data enrichment steps, but will process the document faster. Default value for this flag is 0
      externalId - Optional custom document identifier. Use this if you would like to assign your own ID to documents
      parameters - Additional request parameters
      Returns:
      the data extracted from the Document String
    • processDocumentUrlAsync

      public CompletableFuture<String> processDocumentUrlAsync(String fileUrl, List<String> fileUrls, List<String> categories, boolean deleteAfterProcessing, int maxPagesToProcess, boolean boostMode, String externalId, org.json.JSONObject parameters)
      Process Document from url and extract all the fields from it.
      Specified by:
      processDocumentUrlAsync in interface Client
      Parameters:
      fileUrl - Required if file_urls isn't specified. Publicly accessible URL to a file, e.g. "https://cdn.example.com/receipt.jpg".
      fileUrls - Required if file_url isn't specifies. List of publicly accessible URLs to multiple files, e.g. ["https://cdn.example.com/receipt1.jpg", "https://cdn.example.com/receipt2.jpg"]
      categories - List of categories to use when categorizing the document
      deleteAfterProcessing - Delete this document from Veryfi after data has been extracted
      maxPagesToProcess - When sending a long document to Veryfi for processing, this parameter controls how many pages of the document will be read and processed, starting from page 1.
      boostMode - Flag that tells Veryfi whether boost mode should be enabled. When set to 1, Veryfi will skip data enrichment steps, but will process the document faster. Default value for this flag is 0
      externalId - Optional custom document identifier. Use this if you would like to assign your own ID to documents
      parameters - Additional request parameters
      Returns:
      the data extracted from the Document CompletableFuture<String>
    • deleteDocument

      public String deleteDocument(String documentId)
      Delete Document from Veryfi
      Specified by:
      deleteDocument in interface Client
      Parameters:
      documentId - ID of the document you'd like to delete.
      Returns:
      the response data. String
    • deleteDocumentAsync

      public CompletableFuture<String> deleteDocumentAsync(String documentId)
      Delete Document from Veryfi
      Specified by:
      deleteDocumentAsync in interface Client
      Parameters:
      documentId - ID of the document you'd like to delete.
      Returns:
      the response data. CompletableFuture<String>
    • updateDocument

      public String updateDocument(String documentId, org.json.JSONObject parameters)
      Update data for a previously processed document, including almost any field like `vendor`, `date`, `notes` etc.
      Specified by:
      updateDocument in interface Client
      Parameters:
      documentId - ID of the document you'd like to update.
      parameters - Additional request parameters
      Returns:
      A document json with updated fields, if fields are writable. Otherwise, a document with unchanged fields. String
    • updateDocumentAsync

      public CompletableFuture<String> updateDocumentAsync(String documentId, org.json.JSONObject parameters)
      Update data for a previously processed document, including almost any field like `vendor`, `date`, `notes` etc.
      Specified by:
      updateDocumentAsync in interface Client
      Parameters:
      documentId - ID of the document you'd like to update.
      parameters - Additional request parameters
      Returns:
      A document json with updated fields, if fields are writable. Otherwise, a document with unchanged fields. CompletableFuture<String>
    • getLineItems

      public String getLineItems(String documentId)
      Retrieve all line items for a document.
      Specified by:
      getLineItems in interface Client
      Parameters:
      documentId - ID of the document you'd like to retrieve.
      Returns:
      List of line items extracted from the document. String
    • getLineItemsAsync

      public CompletableFuture<String> getLineItemsAsync(String documentId)
      Retrieve all line items for a document.
      Specified by:
      getLineItemsAsync in interface Client
      Parameters:
      documentId - ID of the document you'd like to retrieve.
      Returns:
      List of line items extracted from the document. CompletableFuture<String>
    • getLineItem

      public String getLineItem(String documentId, String lineItemId)
      Retrieve a line item for existing document by ID.
      Specified by:
      getLineItem in interface Client
      Parameters:
      documentId - ID of the document you'd like to retrieve.
      lineItemId - ID of the line item you'd like to retrieve.
      Returns:
      Line item extracted from the document. String
    • getLineItemAsync

      public CompletableFuture<String> getLineItemAsync(String documentId, String lineItemId)
      Retrieve a line item for existing document by ID.
      Specified by:
      getLineItemAsync in interface Client
      Parameters:
      documentId - ID of the document you'd like to retrieve.
      lineItemId - ID of the line item you'd like to retrieve.
      Returns:
      Line item extracted from the document. CompletableFuture<String>
    • addLineItem

      public String addLineItem(String documentId, AddLineItem payload) throws NotValidModelException
      Add a new line item on an existing document.
      Specified by:
      addLineItem in interface Client
      Parameters:
      documentId - ID of the document you'd like to update.
      payload - line item object to add.
      Returns:
      Added line item data. String
      Throws:
      NotValidModelException - when the model is not valid it throws this exception.
    • addLineItemAsync

      public CompletableFuture<String> addLineItemAsync(String documentId, AddLineItem payload) throws NotValidModelException
      Add a new line item on an existing document.
      Specified by:
      addLineItemAsync in interface Client
      Parameters:
      documentId - ID of the document you'd like to update.
      payload - line item object to add.
      Returns:
      Added line item data. CompletableFuture<String>
      Throws:
      NotValidModelException - when the model is not valid it throws this exception.
    • updateLineItem

      public String updateLineItem(String documentId, String lineItemId, UpdateLineItem payload) throws NotValidModelException
      Update an existing line item on an existing document.
      Specified by:
      updateLineItem in interface Client
      Parameters:
      documentId - ID of the document you'd like to update.
      lineItemId - ID of the line item you'd like to update.
      payload - line item object to update.
      Returns:
      Line item data with updated fields, if fields are writable. Otherwise line item data with unchanged fields. String
      Throws:
      NotValidModelException - when the model is not valid it throws this exception.
    • updateLineItemAsync

      public CompletableFuture<String> updateLineItemAsync(String documentId, String lineItemId, UpdateLineItem payload) throws NotValidModelException
      Update an existing line item on an existing document.
      Specified by:
      updateLineItemAsync in interface Client
      Parameters:
      documentId - ID of the document you'd like to update.
      lineItemId - ID of the line item you'd like to update.
      payload - line item object to update.
      Returns:
      Line item data with updated fields, if fields are writable. Otherwise line item data with unchanged fields. CompletableFuture<String>
      Throws:
      NotValidModelException - when the model is not valid it throws this exception.
    • deleteLineItems

      public String deleteLineItems(String documentId)
      Delete all line items on an existing document.
      Specified by:
      deleteLineItems in interface Client
      Parameters:
      documentId - ID of the document you'd like to delete.
      Returns:
      the response data. String
    • deleteLineItemsAsync

      public CompletableFuture<String> deleteLineItemsAsync(String documentId)
      Delete all line items on an existing document.
      Specified by:
      deleteLineItemsAsync in interface Client
      Parameters:
      documentId - ID of the document you'd like to delete.
      Returns:
    • deleteLineItem

      public String deleteLineItem(String documentId, String lineItemId)
      Delete an existing line item on an existing document.
      Specified by:
      deleteLineItem in interface Client
      Parameters:
      documentId - ID of the document you'd like to delete.
      lineItemId - ID of the line item you'd like to delete.
      Returns:
      the response data. String
    • deleteLineItemAsync

      public CompletableFuture<String> deleteLineItemAsync(String documentId, String lineItemId)
      Delete an existing line item on an existing document.
      Specified by:
      deleteLineItemAsync in interface Client
      Parameters:
      documentId - ID of the document you'd like to delete.
      lineItemId - ID of the line item you'd like to delete.
      Returns:
      the response data. CompletableFuture<String>
    • setTimeOut

      public void setTimeOut(int timeOut)
      Define new time out for the requests in seconds
      Specified by:
      setTimeOut in interface Client
      Parameters:
      timeOut - of the http requests in seconds
    • setBaseUrl

      public void setBaseUrl(String baseUrl)
      By default, the base URL is https://api.veryfi.com/api/;
      Specified by:
      setBaseUrl in interface Client
      Parameters:
      baseUrl - for the Veryfi API
    • setHttpClient

      public void setHttpClient(HttpClient httpClient)
      Description copied from interface: Client
      By default is https://api.veryfi.com/api/;
      Specified by:
      setHttpClient in interface Client
      Parameters:
      httpClient - for the Veryfi API