web

package
v0.0.1-beta Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2022 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JSONFrom

func JSONFrom(v interface{}) io.WriterTo

JSONBodyFrom returns an io.ReadCloser created from JSON marshalled from v.

func JSONTo

func JSONTo(v interface{}) io.ReaderFrom

JSONBodyTo returns a WriteCloser that when closed will unmarshal the content into the target.

Types

type All

type All []IDAndNamerFilter

All is an IDAndNamerFilter that requires all its inner filters evaluate to true.

func (All) Filter

func (a All) Filter(ian IDAndNamer) bool

Filter implements the IDAndNamerFilter interface.

type Any

type Any []IDAndNamerFilter

Any requires only one of its inner filters to evaluate to true

func (Any) Filter

func (a Any) Filter(ian IDAndNamer) bool

Filter implements the IDAndNamerFilter interface.

type Archive

type Archive struct {
	ArchiveID   int64  `json:"Id"`
	ArchiveName string `json:"Name"`
	Parent      int64  `json:"Parent"`
	Permissions int64  `json:"Permissions"`
	Properties  int64  `json:"Properties"`
}

Archive in Square 9

func (*Archive) ID

func (a *Archive) ID() ID

ID gets an ID of the resource.

func (*Archive) Name

func (a *Archive) Name() Name

Name gets the name of the resource.

func (*Archive) PathSegments

func (a *Archive) PathSegments() []string

PathSegments is used by Request to know how to insert this object int64o a URL.

type Archives

type Archives struct {
	Archives []Archive `json:"Archives"`
}

Archives is a useless outer wrapper around the response that comes from getting a list of archives from Square 9

type Body

type Body interface {
	// WriteTo the *http.Request's body before sending to the server
	WriteTo(w io.Writer) (n int64, err error)

	// ReadFrom the *http.Response back from the server.
	ReadFrom(r io.Reader) (n int64, err error)
}

Body is the body of a request or response.

type Client

type Client interface {
	// Close the client and release the license(s) it's consuming.
	Close() error

	// Session gets a session from the client and passes it into function f
	// as a parameter.  Neither the session nor any intermediate API
	// objects may be stored outside of f's scope (e.g. via closure).
	//
	// Many API objects are bound to a single session.  Calling Session
	// does not guarantee (or even try) to give you the same session, so
	// you should do all of your work that you want to do with the session
	// while you have it and only return the final result.
	Session(context.Context, func(context.Context, *Session) error) error
}

Client interacts with the Square 9 REST API.

type Database

type Database struct {
	DatabaseID   int64  `json:"Id"`
	DatabaseName string `json:"Name"`
}

Database defines a Square 9 database

func (*Database) ID

func (d *Database) ID() ID

ID gets an ID of the resource.

func (*Database) Name

func (d *Database) Name() Name

Name gets the name of the resource.

func (*Database) PathSegments

func (d *Database) PathSegments() []string

PathSegments is used by Request to know how to insert this object int64o a URL.

type Databases

type Databases struct {
	Databases []Database `json:"Databases"`
}

Databases is a useless outer wrapper around the response that comes from getting a list of databases from Square 9

type Document

type Document struct {
	DocumentID      int64 `json:"Id"`
	Hash            string
	TID             int64
	Fields          []FieldVal
	Version         int64
	RootVersionID   int64
	Username        string `json:"User_Name"`
	Hits            int64
	Permissions     uint64
	RevisionOptions int64
	FileType        string
}

Document as returned by search results

func (*Document) PathSegments

func (d *Document) PathSegments() []string

type DocumentOption

type DocumentOption string

DocumentOption is included in the call to Client.Document to specify the requested format of the document.

const (
	// FileOption Returns the requested file
	FileOption DocumentOption = "File"

	// EmailOption Returns a ready-to-email version of the document
	EmailOption DocumentOption = "Email"

	// Print64Option Returns a ready-to-print64 version of the document
	Print64Option DocumentOption = "Print64"

	// ThumbOption Returns a thumbnail of the document
	ThumbOption DocumentOption = "Thumb"

	// ZoneOption ---data missing---
	ZoneOption DocumentOption = "Zone"
)

type FieldDef

type FieldDef struct {
	FieldID   int64  `json:"ID"`
	FieldName string `json:"Name"`
	List      int64
	Type      FieldType
	Mask      string
	Size      int64
	RegEx     string
	Prop      FieldProps
	Parent    int64
	ListF1    int64
	ListF2    int64
}

FieldDef is the definition of an Archive field.

func (*FieldDef) ID

func (f *FieldDef) ID() ID

ID implements IDAndNamer

func (*FieldDef) Name

func (f *FieldDef) Name() Name

Name implements IDAndNamer

type FieldProps

type FieldProps uint64

FieldProps is a bit mask describing the properties of fields.

const (
	// Required indicates that the field is required
	Required FieldProps = 2

	// SystemFieldDateEntered indicates that the field is a system field
	// storing the date that the document was stored.
	SystemFieldDateEntered FieldProps = 4 // System Field: Date Entered

	// SystemFieldIndexedBy indicates that the field stores the username
	// of the person who indexed the document
	SystemFieldIndexedBy FieldProps = 8 // System Field: Indexed By

	// SystemFieldPageCount stores the page count of the document
	SystemFieldPageCount FieldProps = 16 // System Field: Page Count

	// MultiValueField indicates that the field accepts more than one
	// value
	MultiValueField FieldProps = 32 // Multi-Value Field

	// FieldContainsDropdownList indicates that the field has a static
	// drop-down list
	FieldContainsDropdownList FieldProps = 64 // Field contains drop-down list

	// FieldContainsDynamicList indicates that the field has a dynamic
	// drop-down list.
	FieldContainsDynamicList FieldProps = 128 // Field contains dynamic list

	// SystemFieldLastModifiedBy indicates that the field holds the name
	// of the user that last modified the document.
	SystemFieldLastModifiedBy FieldProps = 256 // System Field: Last Modified By

	// TableField indicates that the field is a member of a table.
	TableField FieldProps = 512 // Table Field

	// SystemFieldFileType holds the file type of the document
	SystemFieldFileType FieldProps = 1024 // System Field: File Type

	// SystemFieldReadOnly indicates that the field is read-only.
	SystemFieldReadOnly FieldProps = 2048 // System Field: Read-only
)

type FieldType

type FieldType int64

FieldType indicates the data type of the field.

const (
	// InvalidFieldType indicates an invalid field type
	InvalidFieldType FieldType = 0 // Invalid

	// CharacterField indicates that the field stores character data
	CharacterField FieldType = 1 // Character

	// IntegerField indicates that the field stores int64eger data
	IntegerField FieldType = 2 // Integer

	// DateTimeField indicates that the field stores date or date/time
	// data
	DateTimeField FieldType = 3 // DateTime

	// DecimalField indicates that the field stores decimal data
	DecimalField FieldType = 4 // Decimal
)

type FieldVal

type FieldVal struct {
	FieldID    int64         `json:"ID"`
	Value      string        `json:"VAL"`
	MultiValue []interface{} `json:"MVAL"`
}

FieldVal is a field value within a Document.

type File

type File struct {
	Name      string      `json:"name"`
	IsEmail   bool        `json:"isEmail"`
	EmailData interface{} `json:"oEmailData"`
	Test      interface{} `json:"test"`
}

File is a temporary file created by posting an upload to the "WebPortalCache"

type HTTPMethod

type HTTPMethod string

HTTPMethod is a type-safe HTTP method

const (
	// DELETE HTTP method
	DELETE HTTPMethod = http.MethodDelete

	// GET HTTP method
	GET HTTPMethod = http.MethodGet

	// POST HTTP method
	POST HTTPMethod = http.MethodPost
)

type ID

type ID int64

ID of a Square 9 metadata object

func (ID) Filter

func (f ID) Filter(ian IDAndNamer) bool

Filter implements the IDAndNamerFilter interface.

type IDAndNamer

type IDAndNamer interface {
	ID() ID
	Name() Name
}

IDAndNamer is implemented by most metadata objects in the Square 9 API. It lets some functionality in this wrapping API work "genericaly."

type IDAndNamerFilter

type IDAndNamerFilter interface {
	Filter(ian IDAndNamer) bool
}

IDAndNamerFilter provides a predicate for IDAndNamers so they can be filtered

type ImportDocument

type ImportDocument struct {
	Fields []ImportField `json:"fields"`
	Files  []ImportFile  `json:"files"`
}

ImportDocument is a completely different layout from the Update layout to import a document that has already been uploaded to the cache.

type ImportField

type ImportField struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

ImportField is a completely different layout from FieldVal that's used when importing a new document.

type ImportFile

type ImportFile struct {
	Name string `json:"name"`
}

ImportFile is used in ImportDocument to specify one or more files uploaded to the WebPortalCache.

type License

type License struct {
	Username     string    `json:"Username"`
	Domain       string    `json:"Domain"`
	AuthServer   string    `json:"AuthServer"`
	Type         int64     `json:"Type"`
	IPAddress    string    `json:"IPAddress"`
	DateCreated  time.Time `json:"DateCreated"`
	DateAccessed time.Time `json:"DateAccessed"`
	Token        uuid.UUID `json:"Token"`
	Reg          int64     `json:"Reg"`
}

License is returned when requesting a license from Square 9

type Name

type Name string

Name of a Square 9 metadata object

func (Name) Filter

func (f Name) Filter(ian IDAndNamer) bool

Filter implements the IDAndNamerFilter interface.

type Operator

type Operator int64
const (
	UnknownOperator Operator = iota
	Equals
)

type Prompt

type Prompt struct {
	PromptID int64 `json:"ID"`
	FieldID  int64 `json:"FID"`
	ListID   int64
	Parent   int64
	Operator Operator
	Prompt   string
	Value    string `json:"VAL"`
	Prop     int64
}

Prompt is a single prompt in a Search.

func (*Prompt) ID

func (p *Prompt) ID() ID

ID gets the ID of the prompt

func (*Prompt) Name

func (p *Prompt) Name() Name

Name gets the string prompt used in the search

type RWClient

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

RWClient maintains two client implementations: one for read-only access and another for read-write access. By default, when implementing the Client interface, the full-access implementation is used.

func NewRWClient

func NewRWClient(readOnly, fullAccess Client, defaultReadOnly bool) *RWClient

NewRWClient implements the Client interface by choosing between a read-only implementation or a read-write implementation. By default, when the RWClient implements Client directly, it uses the full access client. This can be changed with the defaultReadOnly parameter here.

func (*RWClient) FullAccess

func (c *RWClient) FullAccess() Client

FullAccess gets the FullAccess client explicitly to implement the Client interface.

func (*RWClient) ReadOnly

func (c *RWClient) ReadOnly() Client

ReadOnly gets the read-only client to implement the Client interface.

func (*RWClient) Session

func (c *RWClient) Session(ctx context.Context, f func(context.Context, *Session) error) error

Session implements the Client interface by getting the FullAccess or ReadOnly client (depending on how NewRWClient was called) and delegating to that implementation.

type ReaderBody

type ReaderBody struct {
	io.Reader
}

ReaderBody implements io.WriterTo by copying to the reader.

func (ReaderBody) WriteTo

func (b ReaderBody) WriteTo(w io.Writer) (int64, error)

WriteTo the writer by copying from the reader.

type RequestOption

type RequestOption func(r *request) error

RequestOption configures a Square 9 request.

func ContentType

func ContentType(t string) RequestOption

ContentType sets the content type of the request

func Method

func Method(m HTTPMethod) RequestOption

Method defines the HTTPMethod to use for a Request.

func Path

func Path(segments ...interface{}) RequestOption

Path defines the Request path

func RequestBody

func RequestBody(wt io.WriterTo) RequestOption

RequestBody specifies the Body to use for the request

func ResponseBody

func ResponseBody(rf io.ReaderFrom) RequestOption

ResponseBody specifies the Body to use for the response

func SecureID

func SecureID(hash string) RequestOption

SecureID configures the SecureID to use with this request. It usually comes from a "Hash" or "SecureId" field of a previously-requested object.

func Value

func Value(k string, vs ...interface{}) RequestOption

Value adds a Value (either part of the Query string or POST values, depending on the Method) to the request.

type Results

type Results struct {
	Fields []FieldDef
	Docs   []Document
	Count  int64
}

Results are returned by searches

type Search struct {
	Archives   []Archive
	SearchID   int64  `json:"Id"`
	SearchName string `json:"Name"`
	Parent     int64
	Hash       string
	Detail     []Prompt
	Props      int64
	Fuzzy      int64
	Grouping   string
	Settings   int64
}

Search in a Database.

func (*Search) ID

func (s *Search) ID() ID

ID gets the ID of the search

func (*Search) Name

func (s *Search) Name() Name

Name gets the name of the search

func (*Search) PathSegments

func (s *Search) PathSegments() []string

PathSegments is used by Request to know how to insert this object int64o a URL.

type SearchCriterion

type SearchCriterion struct {
	// Prompt ID or text for the search criterion.
	Prompt IDAndNamerFilter

	// Value to use for the search.
	Value interface{}
}

SearchCriterion is a single search parameter

type Session

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

Session is an implementation of the Client interface for a single user.

func NewSession

func NewSession(ctx context.Context, options ...SessionOption) (*Session, error)

NewSession creates a new Square 9 session.

func (*Session) Archives

func (s *Session) Archives(ctx context.Context, d *Database, f IDAndNamerFilter) (ars []Archive, err error)

Archives gets the archives in the database matching the filter.

func (*Session) Close

func (s *Session) Close() error

Close the session, releasing the license.

func (*Session) Databases

func (s *Session) Databases(ctx context.Context, f IDAndNamerFilter) (ds []Database, err error)

Databases gets the databases available via the session.

func (*Session) DeleteDocument

func (s *Session) DeleteDocument(ctx context.Context, d *Database, a *Archive, doc *Document) error

DeleteDocument deletes a document.

func (*Session) Document

func (s *Session) Document(ctx context.Context, d *Database, a *Archive, doc *Document, o DocumentOption, rf io.ReaderFrom) error

Document retrieves document data associated with the given document. This document must have been returned from a previous call to Search with the same session or else it will fail.

func (*Session) Fields

func (s *Session) Fields(ctx context.Context, d *Database, a *Archive, f IDAndNamerFilter) (fds []FieldDef, err error)

Fields gets all the fields in an Archive matching the filter. The filter can be nil to get all fields.

func (*Session) Import

func (s *Session) Import(ctx context.Context, d *Database, a *Archive, ifs []ImportField, wts ...io.WriterTo) (Err error)

Import one or more files to an archive with the given fields.

func (*Session) Search

func (s *Session) Search(ctx context.Context, d *Database, a *Archive, sr *Search, fs []SearchCriterion, rs *Results, options ...RequestOption) error

Search executes a search

func (*Session) Searches

func (s *Session) Searches(ctx context.Context, d *Database, a *Archive, f IDAndNamerFilter) (srs []Search, err error)

Searches gets the searches associated with an archive

func (*Session) Session

func (s *Session) Session(ctx context.Context, f func(context.Context, *Session) error) error

Session implements the client interface by just passing in itself.

type SessionOption

type SessionOption func(s *Session) error

SessionOption configures a session

func APIURL

func APIURL(u *url.URL) SessionOption

APIURL specifies the base URL of the Square 9 REST API.

func APIURLString

func APIURLString(u string) SessionOption

APIURLString configures the API URL with a string.

func BasicAuth

func BasicAuth(username, password string) SessionOption

BasicAuth configures a session to use basic authentication

func HTTPClient

func HTTPClient(h *http.Client) SessionOption

HTTPClient configures the HTTP client that a Session should use.

type SessionPool

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

SessionPool is a pool of individual sessions. Sessions are not safe for concurrent use but SessionPools are.

Implementation notes:

The implementation is too complicated but I don't yet know what to do about it. I'm open to suggestions!

The sessions field is initialized with a capacity equal to the limit value passed to NewSessionPool. The limit field also gets this capacity. No sessions are created initialy; not until the first call to Session is made. There, we try to get from the sessions channel (and fail the first time) so we create a new session. If using the session succeeds, it is put into the channel so a future attempt through the "fast path" (receive from the sessions channel) succeeds. If usage of the session returns an error

func NewSessionPool

func NewSessionPool(limit int, factory func(context.Context) (*Session, error)) *SessionPool

NewSessionPool creates a pool of clients.

func (*SessionPool) Close

func (p *SessionPool) Close() error

Close the pool by waiting for and closing all the sessions from the pool.

func (*SessionPool) Session

func (p *SessionPool) Session(ctx context.Context, f func(context.Context, *Session) error) error

Session borrows a session from the pool to perform some operation.

Jump to

Keyboard shortcuts

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