veryfi

package
v1.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2022 License: MIT Imports: 17 Imported by: 1

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base64EncodeFile

func Base64EncodeFile(filePath string) (string, error)

Base64EncodeFile encodes a file using base64.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client implements a Veryfi API Client.

Example (ManageDocument)
package main

import (
	"fmt"
	"log"
	"time"

	"github.com/veryfi/veryfi-go/veryfi"
	"github.com/veryfi/veryfi-go/veryfi/scheme"
)

func main() {
	timeout, err := time.ParseDuration("10s")
	if err != nil {
		log.Fatal(err)
	}

	// Initialize a Veryfi Client for v8 API.
	client, err := veryfi.NewClientV8(&veryfi.Options{
		ClientID: "YOUR_CLIENT_ID",
		Username: "YOUR_USERNAME",
		APIKey:   "YOUR_API_KEY",
		HTTP: veryfi.HTTPOptions{
			Timeout: timeout,
			Retry: veryfi.RetryOptions{
				Count: 1,
			},
		},
	})
	if err != nil {
		log.Fatal(err)
	}

	// Specify what documents to update/delete.
	documentID := "YOUR_DOCUMENT_ID"
	deleteDocumentID := "YOUR_DOCUMENT_ID"

	// Update a document.
	_, err = client.UpdateDocument(documentID, scheme.DocumentUpdateOptions{
		Vendor: scheme.VendorUpdateOptions{
			Name:    "Hoanh An",
			Address: "NY",
		},
	})
	if err != nil {
		log.Fatal(err)
	}

	// Search documents.
	docs, err := client.SearchDocuments(scheme.DocumentSearchOptions{
		Tag: "example",
	})
	if err != nil {
		log.Fatal(err)
	}
	for _, doc := range *docs {
		fmt.Println(doc)
	}

	// Get a document.
	_, err = client.GetDocument(documentID, scheme.DocumentGetOptions{
		ReturnAuditTrail: "1",
	})
	if err != nil {
		log.Fatal(err)
	}

	// Delete a document.
	err = client.DeleteDocument(deleteDocumentID)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Successfully deleted %s\n", deleteDocumentID)
}
Output:

Example (ManageLineItem)
package main

import (
	"fmt"
	"log"
	"time"

	"github.com/veryfi/veryfi-go/veryfi"
	"github.com/veryfi/veryfi-go/veryfi/scheme"
)

func main() {
	timeout, err := time.ParseDuration("10s")
	if err != nil {
		log.Fatal(err)
	}

	// Initialize a Veryfi Client for v8 API.
	client, err := veryfi.NewClientV8(&veryfi.Options{
		ClientID: "YOUR_CLIENT_ID",
		Username: "YOUR_USERNAME",
		APIKey:   "YOUR_API_KEY",
		HTTP: veryfi.HTTPOptions{
			Timeout: timeout,
			Retry: veryfi.RetryOptions{
				Count: 1,
			},
		},
	})
	if err != nil {
		log.Fatal(err)
	}

	// Specify what documents and line items to update/delete.
	documentID := "YOUR_DOCUMENT_ID"
	lineItemID := "YOUR_LINE_ITEM_ID"
	deleteLineItemID := "YOUR_LINE_ITEM_ID"

	// Add a line item.
	resp, err := client.AddLineItem(documentID, scheme.LineItemOptions{
		Order:       1,
		Description: "Example",
		Total:       1.0,
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("ID: %v\t Description: %v\t Total: %v\n", resp.ID, resp.Description, resp.Total)

	// Get all line items.
	items, err := client.GetLineItems(documentID)
	if err != nil {
		log.Fatal(err)
	}
	for _, item := range items.LineItems {
		fmt.Printf("ID: %v\t Description: %v\t Total: %v\n", item.ID, item.Description, item.Total)
	}

	// Get a line item.
	resp, err = client.GetLineItem(documentID, lineItemID)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("ID: %v\t Description: %v\t Total: %v\n", resp.ID, resp.Description, resp.Total)

	// Update a line item.
	resp, err = client.UpdateLineItem(documentID, lineItemID, scheme.LineItemOptions{
		Order:       6,
		Description: "Example",
		Total:       6.6,
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("ID: %v\t Description: %v\t Total: %v\n", resp.ID, resp.Description, resp.Total)

	// Delete a line item.
	err = client.DeleteLineItem(documentID, deleteLineItemID)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Successfully deleted %s\n", deleteLineItemID)
}
Output:

Example (ManageTag)
package main

import (
	"fmt"
	"log"
	"time"

	"github.com/veryfi/veryfi-go/veryfi"
	"github.com/veryfi/veryfi-go/veryfi/scheme"
)

func main() {
	timeout, err := time.ParseDuration("10s")
	if err != nil {
		log.Fatal(err)
	}

	// Initialize a Veryfi Client for v8 API.
	client, err := veryfi.NewClientV8(&veryfi.Options{
		ClientID: "YOUR_CLIENT_ID",
		Username: "YOUR_USERNAME",
		APIKey:   "YOUR_API_KEY",
		HTTP: veryfi.HTTPOptions{
			Timeout: timeout,
			Retry: veryfi.RetryOptions{
				Count: 1,
			},
		},
	})
	if err != nil {
		log.Fatal(err)
	}

	// Specify what documents and tag to update/delete.
	documentID := "YOUR_DOCUMENT_ID"
	deleteTagID := "YOUR_TAG_ID"

	// Add a tag.
	resp, err := client.AddTag(documentID, scheme.TagOptions{
		Name: "example3",
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("ID: %v\t Name: %v\n", resp.ID, resp.Name)

	// Get all tags.
	tags, err := client.GetTags(documentID)
	if err != nil {
		log.Fatal(err)
	}
	for _, tag := range tags.Tags {
		fmt.Printf("ID: %v\t Name: %v\n", tag.ID, tag.Name)
	}

	// Get all global tags.
	tags, err = client.GetGlobalTags()
	if err != nil {
		log.Fatal(err)
	}
	for _, tag := range tags.Tags {
		fmt.Printf("ID: %v\t Name: %v\n", tag.ID, tag.Name)
	}

	// Delete a tag.
	err = client.DeleteTag(documentID, deleteTagID)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Successfully deleted %s\n", deleteTagID)

	// Delete a tag globally.
	err = client.DeleteGlobalTag(deleteTagID)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Successfully deleted %s\n", deleteTagID)
}
Output:

Example (ProcessDocument)
package main

import (
	"fmt"
	"log"
	"time"

	"github.com/veryfi/veryfi-go/veryfi"
	"github.com/veryfi/veryfi-go/veryfi/scheme"
)

func main() {
	timeout, err := time.ParseDuration("10s")
	if err != nil {
		log.Fatal(err)
	}

	// Initialize a Veryfi Client for v8 API.
	client, err := veryfi.NewClientV8(&veryfi.Options{
		ClientID: "YOUR_CLIENT_ID",
		Username: "YOUR_USERNAME",
		APIKey:   "YOUR_API_KEY",
		HTTP: veryfi.HTTPOptions{
			Timeout: timeout,
			Retry: veryfi.RetryOptions{
				Count: 1,
			},
		},
	})
	if err != nil {
		log.Fatal(err)
	}

	// Specify your document's filepath.
	testfile := "YOUR_TEST_FILEPATH"

	// Method 1: Process an uploaded document.
	resp, err := client.ProcessDocumentUpload(scheme.DocumentUploadOptions{
		FilePath: testfile,
		DocumentSharedOptions: scheme.DocumentSharedOptions{
			FileName: "invoice1.png",
			Tags:     []string{"example", "test", "upload"},
		},
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Method 1 - ID: %v\tTotal: %v %v\n", resp.ID, resp.Total, resp.CurrencyCode)

	// Method 2: Process a document via an URL.
	resp, err = client.ProcessDocumentURL(scheme.DocumentURLOptions{
		FileURL: "YOUR_INVOICE_URL",
		DocumentSharedOptions: scheme.DocumentSharedOptions{
			Tags: []string{"example", "test", "url"},
		},
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Method 2 - ID: %v\tTotal: %v %v\n", resp.ID, resp.Total, resp.CurrencyCode)
}
Output:

func NewClientV8 added in v1.2.0

func NewClientV8(opts *Options) (*Client, error)

NewClientV8 returns a new instance of a client for v8 API.

func (*Client) AddLineItem

func (c *Client) AddLineItem(documentID string, opts scheme.LineItemOptions) (*scheme.LineItem, error)

AddLineItem returns a added line item for a processed document.

func (*Client) AddTag

func (c *Client) AddTag(documentID string, opts scheme.TagOptions) (*scheme.Tag, error)

AddTag returns an added tag for a processed document.

func (*Client) Config

func (c *Client) Config() *Options

Config returns the client configuration options.

func (*Client) DeleteDocument

func (c *Client) DeleteDocument(documentID string) error

DeleteDocument deletes a processed document.

func (*Client) DeleteGlobalTag

func (c *Client) DeleteGlobalTag(tagID string) error

DeleteGlobalTag deletes a tag from all documents.

func (*Client) DeleteLineItem

func (c *Client) DeleteLineItem(documentID string, lineItemID string) error

DeleteLineItem deletes a line item in a document.

func (*Client) DeleteTag

func (c *Client) DeleteTag(documentID string, tagID string) error

DeleteTag deletes a tag from a document.

func (*Client) GetDocument

func (c *Client) GetDocument(documentID string, opts scheme.DocumentGetOptions) (*scheme.Document, error)

GetDocument returns a processed document with matching queries.

func (*Client) GetGlobalTags

func (c *Client) GetGlobalTags() (*scheme.Tags, error)

GetGlobalTags returns all globally existing tags.

func (*Client) GetLineItem

func (c *Client) GetLineItem(documentID string, lineItemID string) (*scheme.LineItem, error)

GetLineItem returns a line item for a processed document.

func (*Client) GetLineItems

func (c *Client) GetLineItems(documentID string) (*scheme.LineItems, error)

GetLineItems returns all line items for a processed document.

func (*Client) GetTags

func (c *Client) GetTags(documentID string) (*scheme.Tags, error)

GetTags returns all tags for a processed document.

func (*Client) ProcessDocumentURL

func (c *Client) ProcessDocumentURL(opts scheme.DocumentURLOptions) (*scheme.Document, error)

ProcessDocumentURL returns the processed document using URL.

func (*Client) ProcessDocumentUpload

func (c *Client) ProcessDocumentUpload(opts scheme.DocumentUploadOptions) (*scheme.Document, error)

ProcessDocumentUpload returns the processed document.

func (*Client) SearchDocuments

func (c *Client) SearchDocuments(opts scheme.DocumentSearchOptions) (*[]scheme.Document, error)

SearchDocuments returns a list of processed documents with matching queries.

func (*Client) SetTLSConfig added in v0.1.13

func (c *Client) SetTLSConfig(config *tls.Config)

SetTLSConfig sets the TLS configurations for underling transportation layer.

func (*Client) UpdateDocument

func (c *Client) UpdateDocument(documentID string, opts scheme.DocumentUpdateOptions) (*scheme.Document, error)

UpdateDocument updates and returns the processed document.

func (*Client) UpdateLineItem

func (c *Client) UpdateLineItem(documentID string, lineItemID string, opts scheme.LineItemOptions) (*scheme.LineItem, error)

UpdateLineItem returns an updated line item for a processed document.

type HTTPOptions

type HTTPOptions struct {
	// Timeout specifies a time limit for a http request.
	Timeout time.Duration `default:"120s"`

	// Retry specifies the options for retry mechanism.
	Retry RetryOptions
}

HTTPOptions is the config options for http protocol,

type Options

type Options struct {
	// EnvironmentURL provided by Veryfi without trailing `/` or http scheme.
	EnvironmentURL string `default:"api.veryfi.com"`

	// ClientID provided by Veryfi.
	ClientID string `default:"-"`

	// ClientSecret provided by Veryfi.
	ClientSecret string `default:"-"`

	// Username provided by Veryfi.
	Username string `default:"-"`

	// APIKey provided by Veryfi.
	APIKey string `default:"-"`

	// HTTP specifies the options for http protocol, used by a http client.
	HTTP HTTPOptions
}

Options is the root config options

type RetryOptions

type RetryOptions struct {
	// Count specifies the number of retry attempts. Zero value means no retry.
	Count uint `default:"3"`

	// WaitTime specifies the wait time before retrying request. It is
	// increased after each attempt.
	WaitTime time.Duration `default:"100ms"`

	// MaxWaitTime specifies the maximum wait time, the cap, of all retry
	// requests that are made.
	MaxWaitTime time.Duration `default:"360s"`
}

RetryOptions is the config options for backoff retry mechanism. Its strategy is to increase retry intervals after each failed attempt, until some maximum value.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL