client

package
v0.0.0-...-5b64428 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2020 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const ApiAddress = "https://api.aluma.io"

Variables

View Source
var ErrDocSlotsFull = errors.New("all document slots are full")
View Source
var TotalDocumentSlots = 30
View Source
var Version = "version-local"

Functions

func CreateDocumentFor

func CreateDocumentFor(contents io.Reader, creator DocumentCreator,
	deleter DocumentDeleter,
	fn func(Document) error) error

CreateDocumentFor is a helper function that creates a document with a specified DocumentCreator, runs a provided function with the newly-created document, and then deletes the document. It does not accept a context.Context as it assumes the user would want neither the creation nor deletion to be interrupted, since that could lead to 'leaked' documents in aluma.

func GetFreeDocSlots

func GetFreeDocSlots(ctx context.Context, getter DocumentGetter, totalSlots int) (int,
	error)

GetFreeDocSlots is a helper function to retrieve the number of available document slots in aluma, and return an error if there are none.

func NewTokenRetriever

func NewTokenRetriever(httpClient net.HttpDoer, apiUrl string) auth.TokenRetriever

Types

type ApiClient

type ApiClient struct {
	Classifiers  *ClassifiersClient
	Documents    *DocumentsClient
	Extractors   *ExtractorsClient
	Modules      *ModulesClient
	ReadProfiles *ReadProfilesClient
}

func NewApiClient

func NewApiClient(httpClient net.HttpDoer,
	apiUrl string,
	clientId string,
	clientSecret string,
	httpLogSink io.Writer) *ApiClient

type AuthorisingDoer

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

func NewAuthorisingDoer

func NewAuthorisingDoer(retriever auth.TokenRetriever, httpDoer net.HttpDoer, clientId string, clientSecret string) *AuthorisingDoer

func (*AuthorisingDoer) Do

func (ad *AuthorisingDoer) Do(request *http.Request) (*http.Response, error)

type Classifier

type Classifier struct {
	Name string
}

type ClassifierList

type ClassifierList []Classifier

func (ClassifierList) Any

func (classifiers ClassifierList) Any() bool

func (ClassifierList) Contains

func (classifiers ClassifierList) Contains(item string) bool

type ClassifiersClient

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

func NewClassifiersClient

func NewClassifiersClient(baseUrl string, requestSender net.HttpDoer) *ClassifiersClient

func (*ClassifiersClient) Create

func (client *ClassifiersClient) Create(ctx context.Context, name string) error

func (*ClassifiersClient) Delete

func (client *ClassifiersClient) Delete(ctx context.Context, name string) error

func (*ClassifiersClient) GetAll

func (client *ClassifiersClient) GetAll(ctx context.Context) (ClassifierList, error)

func (*ClassifiersClient) Train

func (client *ClassifiersClient) Train(ctx context.Context, name string, samplesArchive io.Reader) error

func (*ClassifiersClient) Upload

func (client *ClassifiersClient) Upload(ctx context.Context, name string, contents io.Reader) error

type CreateDocumentRequest

type CreateDocumentRequest struct {
	FileContents []byte
}

type CreateReadProfileRequest

type CreateReadProfileRequest struct {
	Languages []string `json:"languages"`
}

type Document

type Document struct {
	Id       string
	Size     int
	Sha256   string
	FileType string
}

type DocumentClassifier

type DocumentClassifier interface {
	Classify(ctx context.Context, documentId string, classifierName string, args ReadProfileArgs) (*results.ClassificationResult, error)
}

type DocumentCreator

type DocumentCreator interface {
	Create(ctx context.Context, fileContents io.Reader) (Document, error)
}

type DocumentDeleter

type DocumentDeleter interface {
	Delete(ctx context.Context, documentId string) error
}

type DocumentExtractor

type DocumentExtractor interface {
	Extract(ctx context.Context, documentId string, extractorName string, args ReadProfileArgs) (*results.ExtractionResult, error)
	ExtractForRedaction(ctx context.Context, documentId string, extractorName string, args ReadProfileArgs) (*results.ExtractForRedactionResult, error)
}

type DocumentGetter

type DocumentGetter interface {
	GetAll(ctx context.Context) (DocumentList, error)
}

type DocumentList

type DocumentList []Document

type DocumentReader

type DocumentReader interface {
	Read(ctx context.Context, documentId string, args ReadProfileArgs) error
	ReadResult(ctx context.Context, documentId string, mode ReadMode, args ReadProfileArgs) (io.ReadCloser, error)
}

type DocumentRedactor

type DocumentRedactor interface {
	Redact(ctx context.Context, documentId string, redactRequest request.RedactedPdfRequest) (io.ReadCloser, error)
}

type DocumentsClient

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

func NewDocumentsClient

func NewDocumentsClient(baseUrl string, httpDoer net.HttpDoer) *DocumentsClient

func (*DocumentsClient) Classify

func (client *DocumentsClient) Classify(ctx context.Context, documentId string, classifierName string, args ReadProfileArgs) (*results.ClassificationResult, error)

func (*DocumentsClient) Create

func (client *DocumentsClient) Create(ctx context.Context, fileContents io.Reader) (Document,
	error)

func (*DocumentsClient) Delete

func (client *DocumentsClient) Delete(ctx context.Context, documentId string) error

func (*DocumentsClient) Extract

func (client *DocumentsClient) Extract(ctx context.Context, documentId string, extractorName string, args ReadProfileArgs) (*results.ExtractionResult, error)

func (*DocumentsClient) ExtractForRedaction

func (client *DocumentsClient) ExtractForRedaction(ctx context.Context,
	documentId string,
	extractorName string,
	args ReadProfileArgs) (*results.ExtractForRedactionResult, error)

ExtractForRedaction performs extracton on a document, and returns the results in a format the "get redacted pdf" http endpoint will accept, namely "application/vnd.waives.requestformats.redact+json".

func (*DocumentsClient) GetAll

func (client *DocumentsClient) GetAll(ctx context.Context) (DocumentList, error)

func (*DocumentsClient) Read

func (client *DocumentsClient) Read(ctx context.Context, documentId string, args ReadProfileArgs) error

func (*DocumentsClient) ReadResult

func (client *DocumentsClient) ReadResult(ctx context.Context,
	documentId string, mode ReadMode, args ReadProfileArgs) (io.ReadCloser, error)

func (*DocumentsClient) Redact

func (client *DocumentsClient) Redact(ctx context.Context,
	documentId string, redactRequest request.RedactedPdfRequest) (io.ReadCloser, error)

Redact requests a redacted PDF of the given document.

type Extractor

type Extractor struct {
	Name string
}

type ExtractorList

type ExtractorList []Extractor

func (ExtractorList) Contains

func (e ExtractorList) Contains(item string) bool

type ExtractorTemplate

type ExtractorTemplate struct {
	Modules []ModuleTemplate `json:"modules"`
}

func NewModulesTemplateFromJson

func NewModulesTemplateFromJson(stream io.Reader) (*ExtractorTemplate, error)

type ExtractorsClient

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

func NewExtractorsClient

func NewExtractorsClient(baseUrl string, requestSender net.HttpDoer) *ExtractorsClient

func (*ExtractorsClient) Create

func (client *ExtractorsClient) Create(ctx context.Context, name string, config io.Reader) error

func (*ExtractorsClient) CreateFromJson

func (client *ExtractorsClient) CreateFromJson(ctx context.Context, name string, jsonTemplate io.Reader) error

func (*ExtractorsClient) CreateFromModules

func (client *ExtractorsClient) CreateFromModules(ctx context.Context, name string, modules ExtractorTemplate) error

func (*ExtractorsClient) Delete

func (client *ExtractorsClient) Delete(ctx context.Context, name string) error

func (*ExtractorsClient) GetAll

func (client *ExtractorsClient) GetAll(ctx context.Context) (ExtractorList, error)

type FieldAliasTemplate

type FieldAliasTemplate struct {
	Field string `json:"field"`
	Alias string `json:"alias"`
}

type FileClassifier

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

func NewFileClassifier

func NewFileClassifier(creator DocumentCreator, classifier DocumentClassifier,
	deleter DocumentDeleter) *FileClassifier

func (*FileClassifier) Classify

func (f *FileClassifier) Classify(ctx context.Context, fileContents io.Reader,
	classifierName string, args ReadProfileArgs) (*results.ClassificationResult, error)

type FileExtractor

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

func NewFileExtractor

func NewFileExtractor(creator DocumentCreator, extractor DocumentExtractor, deleter DocumentDeleter) *FileExtractor

func (*FileExtractor) Extract

func (f *FileExtractor) Extract(ctx context.Context, fileContents io.Reader, extractorName string, args ReadProfileArgs) (*results.ExtractionResult, error)

Extract creates a document, performs extraction, deletes the doc, then returns the extraction result.

type FileReader

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

Helper struct which creates a document from a file, performs a read, downloads the read result, then deletes the document.

func NewFileReader

func NewFileReader(creator DocumentCreator, reader DocumentReader, deleter DocumentDeleter) *FileReader

func (*FileReader) Read

func (f *FileReader) Read(ctx context.Context, fileContents io.Reader, mode ReadMode, args ReadProfileArgs) (io.ReadCloser, error)

Read creates a document from fileContents, performs a read, then returns the read results in the format according to mode.

type FileRedactor

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

func NewFileRedactor

func NewFileRedactor(creator DocumentCreator, extractor DocumentExtractor,
	redactor DocumentRedactor,
	deleter DocumentDeleter) *FileRedactor

func (*FileRedactor) Redact

func (f *FileRedactor) Redact(ctx context.Context, fileContents io.Reader,
	extractorName string, args ReadProfileArgs) (io.ReadCloser, error)

Redact creates a document from the fileContents, performs extraction on it, then redacts it with the results of the extraction.

type LoggingDoer

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

LoggingDoer is an HttpDoer decorator that logs all HTTP requests and responses to the specified io.Writer. It indents any json request / response bodies, and redacts any non-json bodies.

func NewLoggingDoer

func NewLoggingDoer(httpDoer net.HttpDoer, out io.Writer) *LoggingDoer

func (*LoggingDoer) Do

func (d *LoggingDoer) Do(request *http.Request) (*http.Response, error)

type Module

type Module struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Summary     string `json:"summary"`
	Description string `json:"description"`
	Fields      []struct {
		Name        string      `json:"name"`
		Description interface{} `json:"description"`
	} `json:"fields"`
	Parameters []struct {
		ID          string `json:"id"`
		Name        string `json:"name"`
		Type        string `json:"type"`
		Description string `json:"description"`
		Required    bool   `json:"required"`
	} `json:"parameters"`
}

type ModuleList

type ModuleList []Module

func (ModuleList) Find

func (l ModuleList) Find(id string) *Module

Find performs a case-insensitive search for the provided ID string, and returns the Module if found and nil if not.

type ModuleTemplate

type ModuleTemplate struct {
	ID           string                 `json:"id"`
	Arguments    map[string]interface{} `json:"arguments,omitempty"`
	FieldAliases []FieldAliasTemplate   `json:"field_aliases,omitempty"`
}

type ModulesClient

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

func NewModulesClient

func NewModulesClient(baseUrl string, requestSender net.HttpDoer) *ModulesClient

func (*ModulesClient) GetAll

func (m *ModulesClient) GetAll(ctx context.Context) (ModuleList, error)

type ReadDocumentRequest

type ReadDocumentRequest struct {
	ProfileName string `json:"read_profile"`
}

type ReadMode

type ReadMode int
const (
	ReadPDF ReadMode = iota
	ReadText
	ReadWvdoc
)

func (ReadMode) IsBinary

func (mode ReadMode) IsBinary() bool

type ReadProfile

type ReadProfile struct {
	Name      string
	Languages []string
}

type ReadProfileArgs

type ReadProfileArgs struct {
	// If UseReadProfile set, use profile called ProfileName.
	// Otherwise, use the default profile (i.e. don't specify a profile in HTTP requests)
	UseReadProfile bool
	ProfileName    string
}

type ReadProfileCreator

type ReadProfileCreator interface {
	Create(ctx context.Context, name string, languages []string) (ReadProfile, error)
}

type ReadProfileDeleter

type ReadProfileDeleter interface {
	Delete(ctx context.Context, name string) error
}

type ReadProfileGetter

type ReadProfileGetter interface {
	GetAll(ctx context.Context) (ReadProfileList, error)
}

type ReadProfileGetterDeleter

type ReadProfileGetterDeleter interface {
	ReadProfileGetter
	ReadProfileDeleter
}

type ReadProfileList

type ReadProfileList []ReadProfile

func (*ReadProfileList) Contains

func (l *ReadProfileList) Contains(name string) bool

type ReadProfilesClient

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

func NewReadProfilesClient

func NewReadProfilesClient(baseUrl string, httpDoer net.HttpDoer) *ReadProfilesClient

func (*ReadProfilesClient) Create

func (client *ReadProfilesClient) Create(ctx context.Context, name string, languages []string) (ReadProfile, error)

func (*ReadProfilesClient) Delete

func (client *ReadProfilesClient) Delete(ctx context.Context, name string) error

func (*ReadProfilesClient) GetAll

func (client *ReadProfilesClient) GetAll(ctx context.Context) (ReadProfileList, error)

type ResponseCheckingDoer

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

func NewResponseCheckingdoer

func NewResponseCheckingdoer(checker net.ResponseChecker, wrappedSender net.HttpDoer) *ResponseCheckingDoer

func (*ResponseCheckingDoer) Do

func (requestSender *ResponseCheckingDoer) Do(request *http.Request) (*http.Response, error)

type TrainClassifierRequest

type TrainClassifierRequest struct {
	ClassifierName string
	SamplesFile    string
}

Directories

Path Synopsis
matchers
Code generated by pegomock.
Code generated by pegomock.

Jump to

Keyboard shortcuts

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