ultraocr

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package ultraocr implements utilities to help on the UltraOCR API usage.

Package ultraocr implements utilities to help on the UltraOCR API usage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchStatusJobs

type BatchStatusJobs struct {
	JobID     string `json:"job_ksuid"`
	CreatedAt string `json:"created_at"`
	ResultURL string `json:"result_url"`
	Status    string `json:"status"`
	Error     string `json:"error,omitempty"`
}

type BatchStatusResponse

type BatchStatusResponse struct {
	BatchID   string            `json:"batch_ksuid"`
	CreatedAt string            `json:"created_at"`
	Service   string            `json:"service"`
	Status    string            `json:"status"`
	Error     string            `json:"error,omitempty"`
	Jobs      []BatchStatusJobs `json:"jobs"`
}

type Client

type Client struct {
	BaseURL      string
	AuthBaseURL  string
	Token        string
	ClientID     string
	ClientSecret string
	AutoRefresh  bool
	Expires      int
	Timeout      int
	Interval     int
	ExpiresAt    time.Time
	HttpClient   HttpClient
}

func NewClient

func NewClient() Client

NewClient Creates a client to use UltraOCR utilities.

func (*Client) Authenticate

func (client *Client) Authenticate(ctx context.Context, clientID, clientSecret string, expires int) error

Authenticate Generates a token on UltraOCR and save the token to use on future requests. Requires the Client informations (ID and Secret) and the token expiration time (in minutes).

func (*Client) CreateAndWaitBatch

func (client *Client) CreateAndWaitBatch(ctx context.Context,
	service,
	filePath string,
	metadata []map[string]any,
	params map[string]string,
	waitJobs bool,
) (BatchStatusResponse, error)

CreateAndWaitJob Creates and wait a batch to be done. Have a timeout and an interval configured on the Client. Requires the service, file path and required metadata and query params.

func (*Client) CreateAndWaitJob

func (client *Client) CreateAndWaitJob(ctx context.Context,
	service,
	filePath,
	facematchFilePath,
	extraFilePath string,
	metadata map[string]any,
	params map[string]string,
) (JobResultResponse, error)

CreateAndWaitJob Creates and wait a job to be done. Have a timeout and an interval configured on the Client. Requires the service, files paths and required metadata and query params.

func (*Client) GenerateSignedUrl

func (client *Client) GenerateSignedUrl(
	ctx context.Context,
	service,
	resource string,
	metadata any,
	params map[string]string,
) (SignedUrlResponse, error)

GenerateSignedUrl Generates a signed url to upload the document image to be processed. Requires the service (document type), the resource (job or batch) and the required metadata and query params.

func (*Client) GetBatchStatus

func (client *Client) GetBatchStatus(ctx context.Context, ID string) (BatchStatusResponse, error)

GetBatchStatus Gets the batch status. Requires the batch ID.

func (*Client) GetJobResult

func (client *Client) GetJobResult(ctx context.Context, batchID, jobID string) (JobResultResponse, error)

GetBatchStatus Gets the job result. Requires the batch and job ID.

func (*Client) GetJobs

func (client *Client) GetJobs(ctx context.Context, start, end string) ([]JobResultResponse, error)

GetJobs Gets the jobs in a time interval. Requires the start and end time in 2006-01-02 format.

func (*Client) SendBatch

func (client *Client) SendBatch(ctx context.Context,
	service,
	filePath string,
	metadata []map[string]any,
	params map[string]string,
) (CreatedResponse, error)

SendBatch Sends a batch. Requires the service, the file path and the required metadata and query params.

func (*Client) SendBatchBase64

func (client *Client) SendBatchBase64(ctx context.Context,
	service,
	file string,
	metadata []map[string]any,
	params map[string]string,
) (CreatedResponse, error)

SendBatchBase64 Sends a batch on base64 format. Requires the service, the file on base64 format and the required metadata and query params.

func (*Client) SendJob

func (client *Client) SendJob(ctx context.Context,
	service,
	filePath,
	facematchFilePath,
	extraFilePath string,
	metadata map[string]any,
	params map[string]string,
) (CreatedResponse, error)

SendJob Sends a job. Requires the service, the files (facematch and extra file if requested on params) paths and the required metadata and query params.

func (*Client) SendJobBase64

func (client *Client) SendJobBase64(ctx context.Context,
	service,
	file,
	facematchFile,
	extraFile string,
	metadata map[string]any,
	params map[string]string,
) (CreatedResponse, error)

SendJobBase64 Sends a job on base64 format. Requires the service, the files (facematch and extra file if requested on params) on base64 format and the required metadata and query params.

func (*Client) SendJobSingleStep

func (client *Client) SendJobSingleStep(
	ctx context.Context,
	service,
	file,
	facematchFile,
	extraFile string,
	metadata map[string]any,
	params map[string]string,
) (CreatedResponse, error)

SendJobSingleStep Sends a job in single step, with 6MB body limit. Requires the service, the files (facematch and extra file if requested on params) on base64 format and the required metadata and query params.

func (*Client) SetAuthBaseURL

func (client *Client) SetAuthBaseURL(url string)

SetAuthBaseURL Changes the Client Authentication Base URL.

func (*Client) SetAutoRefresh

func (client *Client) SetAutoRefresh(clientID, clientSecret string, expires int)

SetAutoRefresh Changes Client to auto refresh token.

func (*Client) SetBaseURL

func (client *Client) SetBaseURL(url string)

SetBaseURL Changes the Client Base URL.

func (*Client) SetHttpClient

func (client *Client) SetHttpClient(httpClient HttpClient)

SetHttpClient Changes the Client HTTP Client.

func (*Client) SetInterval

func (client *Client) SetInterval(interval int)

SetInterval Changes the Client interval (in seconds) between requests on wait job and batch done.

func (*Client) SetTimeout

func (client *Client) SetTimeout(timeout int)

SetTimeout Changes the Client (timeout in seconds) on wait job and batch done.

func (Client) UploadFile

func (client Client) UploadFile(ctx context.Context, url string, path string) error

UploadFileBase64 Upload a file given a path. Requires the s3 URL and the file path.

func (Client) UploadFileBase64

func (client Client) UploadFileBase64(ctx context.Context, url string, data string) error

UploadFileBase64 Upload a file on base64 format. Requires the s3 URL and the data on base64 (string).

func (*Client) WaitForBatchDone

func (client *Client) WaitForBatchDone(ctx context.Context, ID string, waitJobs bool) (BatchStatusResponse, error)

WaitForBatchDone Waits for the batch status be done or error. Have a timeout and an interval configured on the Client. Requires the batch and an info if the utility will also wait the jobs to be done.

func (*Client) WaitForJobDone

func (client *Client) WaitForJobDone(ctx context.Context, batchID, jobID string) (JobResultResponse, error)

WaitForJobDone Waits for the job status be done or error. Have a timeout and an interval configured on the Client. Requires the batch and job ID.

type CreatedResponse

type CreatedResponse struct {
	Id        string `json:"id"`
	StatusURL string `json:"status_url"`
}

type GetJobsResponse

type GetJobsResponse struct {
	Jobs          []JobResultResponse `json:"jobs"`
	NextPageToken string              `json:"nextPageToken"`
}

type HttpClient

type HttpClient interface {
	Do(req *http.Request) (*http.Response, error)
}

type JobResultResponse

type JobResultResponse struct {
	Result           Result      `json:"result,omitempty"`
	JobID            string      `json:"job_ksuid"`
	CreatedAt        string      `json:"created_at"`
	Service          string      `json:"service"`
	Status           string      `json:"status"`
	Error            string      `json:"error,omitempty"`
	ProcessTime      string      `json:"process_time,omitempty"`
	Filename         string      `json:"filename,omitempty"`
	ValidationStatus string      `json:"validation_status,omitempty"`
	ClientData       interface{} `json:"client_data,omitempty"`
	Validation       interface{} `json:"validation,omitempty"`
}

type Response

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

type Result

type Result struct {
	Document interface{} `json:"Document,omitempty"`
	Quantity int         `json:"Quantity,omitempty"`
	Time     string      `json:"Time,omitempty"`
}

type SignedUrlResponse

type SignedUrlResponse struct {
	Expires   int               `json:"exp"`
	Id        string            `json:"id"`
	StatusURL string            `json:"status_url"`
	URLs      map[string]string `json:"urls"`
}

Directories

Path Synopsis
Package common implements constants and errors.
Package common implements constants and errors.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳