qb

package
v0.0.0-...-73f9b0c Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2019 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CtxKeyAction ctxKey = iota
	CtxKeyRealmHost
)

CtxKey contexts contain context keys.

View Source
const (
	DefaultConfigFile = "$HOME/.config/quickbase/config"
	DefaultTicketFile = "$HOME/.config/quickbase/ticket"
)

Default* constants contain configuration defaults.

View Source
const (
	FieldModeVirtual = "virtual"
	FieldModeLookup  = "lookup"
)

FieldMode* constants contain valid Quick Base field mode settings.

View Source
const (
	FieldTypeCheckbox        = "checkbox"
	FieldTypeDate            = "date"
	FieldTypeDuration        = "duration"
	FieldTypeEmailAddress    = "email"
	FieldTypeFileAttachment  = "file"
	FieldTypeListUser        = "multiuserid"
	FieldTypeMultiSelectText = "multitext"
	FieldTypeNumeric         = "float"
	FieldTypeNumericCurrency = "currency"
	FieldTypeNumericPercent  = "percent"
	FieldTypeNumericRating   = "rating"
	FieldTypePhoneNumber     = "phone"
	FieldTypeReportLink      = "dblink"
	FieldTypeText            = "text"
	FieldTypeTimeOfDay       = "timeofday"
	FieldTypeURL             = "url"
	FieldTypeUser            = "userid"
)

FieldType* constants contain valid Quick Base field types.

View Source
const EnvVarPrefix = "QUICKBASE"

EnvVarPrefix is the environment variable prefix for configuration options.

View Source
const TicketHours = 12

TicketHours is the default expiry for a ticket.

Variables

This section is empty.

Functions

func CacheTicket

func CacheTicket(file string, output AuthenticateOutput) error

CacheTicket writes the ticket to file so that it can be used in subsequent API requests.

func FieldTypes

func FieldTypes() []string

FieldTypes return all valid Quick Base field types.

func InitConfig

func InitConfig(v *viper.Viper) error

InitConfig reads config from options, environment variables, and config files in that order of preference. This is separated out into a different function so that it can be used by methods that construct their own instance of *viper.Viper.

func IsTicketFileErr

func IsTicketFileErr(err error) bool

IsTicketFileErr returns true if the error is a TicketFileError.

func ReadCachedTicket

func ReadCachedTicket(file string) (string, error)

ReadCachedTicket reads the data in the ticket file and returns the ticket if it exists.

func ReplaceTokens

func ReplaceTokens(v *viper.Viper, key string) string

ReplaceTokens replaces tokens in the values set as configuration options. For example, $HOME is replaced with the user's home directory dependant on platform, see https://github.com/kubernetes/client-go/blob/master/util/homedir/homedir.go.

Types

type AddRecordInput

type AddRecordInput struct {
	RequestParams
	Credentials

	TableID           string                `xml:"-"`
	DisplayRecord     bool                  `xml:"disprec,int,omitempty"`
	SetCheckboxFields bool                  `xml:"fform,int,omitempty"`
	Fields            []AddRecordInputField `xml:"field"`
	IgnoreErrors      bool                  `xml:"ignoreError,int,omitempty"`
	MillisecondsInUtc bool                  `xml:"msInUTC,int,omitempty"`
}

AddRecordInput models the request sent to API_AddRecord. See https://help.quickbase.com/api-guide/add_record.html

type AddRecordInputField

type AddRecordInputField struct {
	ID       int    `xml:"fid,attr,omitempty"`
	FileName string `xml:"filename,attr,omitempty"`
	Label    string `xml:"name,attr,omitempty"`
	Value    string `xml:",chardata"`
}

AddRecordInputField models the "field" element in AddRecordInput requests.

type AddRecordOutput

type AddRecordOutput struct {
	ResponseParams

	RecordID int `xml:"rid" json:"record_id"`
	UpdateID int `xml:"update_id" json:"update_id"`
}

AddRecordOutput models responses returned by API_AddRecord. See https://help.quickbase.com/api-guide/add_record.html

type AuthenticateInput

type AuthenticateInput struct {
	RequestParams

	Hours    int    `xml:"hours,omitempty"`
	Password string `xml:"password"`
	Username string `xml:"username"`
}

AuthenticateInput models requests sent to API_Authenticate. See https://help.quickbase.com/api-guide/authenticate.html

type AuthenticateOutput

type AuthenticateOutput struct {
	ResponseParams

	Ticket string `xml:"ticket"`
	UserID string `xml:"userid"`
}

AuthenticateOutput models the response returned by API_Authenticate. See https://help.quickbase.com/api-guide/authenticate.html

type AuthenticatedInput

type AuthenticatedInput interface {
	Input
	// contains filtered or unexported methods
}

AuthenticatedInput is the interface implemented by structs that model requests sent to the Quick Base API that require authentication.

type Bool

type Bool bool

Bool converts a boolean to an integer.

func (Bool) MarshalXML

func (b Bool) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements Marshaler.MarshalXML and renders the bool as an int.

type Client

type Client struct {

	// The HTTP client to use when sending requests. Defaults to
	// `http.DefaultClient`.
	HTTPClient *http.Client

	// Plugins contains the Plugin implementations.
	Plugins []Plugin
	// contains filtered or unexported fields
}

Client makes requests to the Quick Base API.

func NewClient

func NewClient(cfg Config) Client

NewClient returns a Client populated with default values.

func (Client) AddRecord

func (c Client) AddRecord(input *AddRecordInput) (output AddRecordOutput, err error)

AddRecord makes an API_AddRecord call. See https://help.quickbase.com/api-guide/index.html#add_record.html MACHINE GENERATED BY GO GENERATE; DO NOT EDIT

func (Client) Authenticate

func (c Client) Authenticate(input *AuthenticateInput) (output AuthenticateOutput, err error)

Authenticate makes call to API_Authenticate. See https://help.quickbase.com/api-guide/authenticate.html

func (Client) Config

func (c Client) Config() Config

Config returns the configuration.

func (Client) Do

func (c Client) Do(input Input, output Output) error

Do makes a request to the Quick Base API. This method sets some context about the request, initializes the request via the NewRequest method, invokes each plugins PreRequest method, uses *Client.HTTPClient to make the actual request, invokes each plugin's PostResponse method, then unmarshals the raw response into the passed Output struct.

func (Client) DoQuery

func (c Client) DoQuery(input *DoQueryInput) (output DoQueryOutput, err error)

DoQuery makes call to API_DoQuery. See https://help.quickbase.com/api-guide/do_query.html.

func (Client) EditRecord

func (c Client) EditRecord(input *EditRecordInput) (output EditRecordOutput, err error)

EditRecord makes an API_EditRecord call. See https://help.quickbase.com/api-guide/edit_record.html

func (Client) GetSchema

func (c Client) GetSchema(input *GetSchemaInput) (output GetSchemaOutput, err error)

GetSchema makes call to API_GetSchema. See https://help.quickbase.com/api-guide/getschema.html

func (Client) ImportFromCSV

func (c Client) ImportFromCSV(input *ImportFromCSVInput) (output ImportFromCSVOutput, err error)

ImportFromCSV makes an API_ImportFromCSV call. See https://help.quickbase.com/api-guide/importfromcsv.html

func (Client) NewRequest

func (c Client) NewRequest(input Input) (req *http.Request, err error)

NewRequest returns a *http.Request initialized with the data needed to make a request to the Quick Base API. In this method, the credentials are set, the Input struct is marshaled into the XML/JSON/HTML payload, and the URL of the action being performed is constructed.

func (Client) NewTicket

func (c Client) NewTicket(cachefile, username, password string, hours int) (output AuthenticateOutput, err error)

NewTicket calls the API_Authenticate endpoint to create a ticket that can be used to authenticate subsequent API requests. If a ticket is returned, it is cached in the ticket file.

func (Client) SetVariable

func (c Client) SetVariable(input *SetVariableInput) (output SetVariableOutput, err error)

SetVariable makes an API_SetDBvar call. See https://help.quickbase.com/api-guide/setdbvar.html

func (Client) UploadFile

func (c Client) UploadFile(input *UploadFileInput) (output UploadFileOutput, err error)

UploadFile makes an API_UploadFile call. See https://help.quickbase.com/api-guide/uploadfile.html

type Config

type Config interface {

	// Set sets a configuration option.
	Set(string, interface{})

	// AppID returns the dbid of the application used by default.
	AppID() string

	// AppToken returns the app token used to authenticate API requests.
	// See https://quickbase.com/api-guide/authentication_and_secure_access.html.
	AppToken() string

	// ConfigFile retuns the path to the TOML file that contains config. The
	// default path is "$HOME/.config/quickbase/config", where $HOME is
	// replaced with the user's home directory dependant on platform.
	ConfigFile() string

	// The realm host, e.g., https://MYREALM.quickbase.com/. Replace MYREALM
	// accordingly.
	RealmHost() string

	// TableID returns the dbid of the table used by default.
	TableID() string

	// Ticket returns the ticket used to authenticate API requests.
	// See https://quickbase.com/api-guide/authentication_and_secure_access.html
	Ticket() string

	// TicketFile returns the path to file continaing a cached ticket. The
	// default path is "$HOME/.config/quickbase/ticket", where $HOME is
	// replaced with the user's home directory dependant on platform.
	TicketFile() string

	// UserToken returns the user token used to authenticate API requests.
	// See https://quickbase.com/api-guide/create_user_tokens.html.
	UserToken() string
}

Config is the interface that contains runtime configuration.

type Credentials

type Credentials struct {
	AppToken  string `xml:"apptoken,omitempty"`
	Ticket    string `xml:"ticket,omitempty"`
	UserToken string `xml:"usertoken,omitempty"`
}

Credentials contains the parameters that are used to authenticate requests made to the Quick Base API. See https://quickbase.com/api-guide/authentication_and_secure_access.html.

func NewCredentials

func NewCredentials(cfg Config) Credentials

NewCredentials returns a Credentials with data populated dependant on configuration.

type DoQueryInput

type DoQueryInput struct {
	RequestParams
	Credentials

	TableID          string               `xml:"-"`
	Query            string               `xml:"query,omitempty"`
	QueryID          int                  `xml:"qid,omitempty"`
	QueryName        string               `xml:"qname,omitempty"`
	IncludeRecordIDs Bool                 `xml:"includeRids,omitempty"`
	ReturnPercentage Bool                 `xml:"returnpercentage,omitempty"`
	UseFieldIDs      Bool                 `xml:"useFids,omitempty"`
	Format           string               `xml:"fmt,omitempty"`
	FieldList        FieldList            `xml:"clist,omitempty"`
	SortList         FieldList            `xml:"slist,omitempty"`
	Options          *DoQueryInputOptions `xml:"options,omitempty"`
}

DoQueryInput models the request sent to API_DoQuery. See https://help.quickbase.com/api-guide/do_query.html

func (*DoQueryInput) EnsureOptions

func (input *DoQueryInput) EnsureOptions() *DoQueryInputOptions

EnsureOptions returns an initialized Options property. This method should be used in favor of accessing the property directly to avoid null pointer exceptions.

func (*DoQueryInput) Fields

func (input *DoQueryInput) Fields(fids ...int) *DoQueryInput

Fields sets the fields that are returned in the response.

func (*DoQueryInput) Limit

func (input *DoQueryInput) Limit(n int) *DoQueryInput

Limit sets the "num" option.

func (*DoQueryInput) Offset

func (input *DoQueryInput) Offset(n int) *DoQueryInput

Offset sets the "skp" option.

func (*DoQueryInput) OnlyNew

func (input *DoQueryInput) OnlyNew() *DoQueryInput

OnlyNew sets the "onlynew" option.

func (*DoQueryInput) Sort

func (input *DoQueryInput) Sort(sort []int, order []string) *DoQueryInput

Sort sets the fields and order in one shot.

func (*DoQueryInput) SortBy

func (input *DoQueryInput) SortBy(fids ...int) *DoQueryInput

SortBy sets the fields to be sorted by.

func (*DoQueryInput) SortOrder

func (input *DoQueryInput) SortOrder(order ...string) *DoQueryInput

SortOrder sets the "sortorder" option.

func (*DoQueryInput) Unsorted

func (input *DoQueryInput) Unsorted() *DoQueryInput

Unsorted sets the "nosort" option.

type DoQueryInputOptions

type DoQueryInputOptions struct {
	SortOrderList []string
	Limit         int
	Offset        int
	OnlyNew       bool
	Unsorted      bool
}

DoQueryInputOptions models the "options" element in API_DoQuery requests.

func (DoQueryInputOptions) MarshalXML

func (o DoQueryInputOptions) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements Marshaler.MarshalXML and formats the value of the "options" element.

type DoQueryOutput

type DoQueryOutput struct {
	ResponseParams

	Fields  []DoQueryOutputField  `xml:"table>fields>field"`
	Records []DoQueryOutputRecord `xml:"table>records>record"`
}

DoQueryOutput models the response returned by API_DoQuery. See https://help.quickbase.com/api-guide/do_query.html.

type DoQueryOutputField

type DoQueryOutputField struct {
	FieldID  int    `xml:"id,attr"`
	Type     string `xml:"field_type,attr"`
	BaseType string `xml:"base_type,attr"`
	Mode     string `xml:"mode,attr"`
	Label    string `xml:"label"`
}

DoQueryOutputField models the "table>fields" element. in an API_DoQuery response.

type DoQueryOutputRecord

type DoQueryOutputRecord struct {
	RecordID int                        `xml:"rid,attr"`
	UpdateID int                        `xml:"update_id"`
	Fields   []DoQueryOutputRecordField `xml:"f"`
}

DoQueryOutputRecord models the "table>records>record" element in an API_DoQuery response.

type DoQueryOutputRecordField

type DoQueryOutputRecordField struct {
	FieldID int    `xml:"id,attr"`
	Value   string `xml:",chardata"`
}

DoQueryOutputRecordField models the "table>records>record>field" element in an API_DoQuery response.

type EditRecordInput

type EditRecordInput struct {
	RequestParams
	Credentials

	TableID           string                 `xml:"-"`
	DisplayRecord     bool                   `xml:"disprec,int,omitempty"`
	SetCheckboxFields bool                   `xml:"fform,int,omitempty"`
	Fields            []EditRecordInputField `xml:"field"`
	IgnoreError       bool                   `xml:"ignoreError,int,omitempty"`
	MillisecondsInUtc bool                   `xml:"msInUTC,int,omitempty"`
	RecordID          int                    `xml:"rid"`
	UpdateID          int                    `xml:"update_id,omitempty"`
}

EditRecordInput models the request sent to API_EditRecord. See https://help.quickbase.com/api-guide/edit_record.html

type EditRecordInputField

type EditRecordInputField struct {
	ID       int    `xml:"fid,attr,omitempty"`
	FileName string `xml:"filename,attr,omitempty"`
	Label    string `xml:"name,attr,omitempty"`
	Value    string `xml:",chardata"`
}

EditRecordInputField models the "field" element in API_EditRecord requests.

type EditRecordOutput

type EditRecordOutput struct {
	ResponseParams

	NumFieldsChanged int `xml:"num_fields_changed" json:"num_fields_changed"`
	RecordID         int `xml:"rid" json:"record_id"`
	UpdateID         int `xml:"update_id" json:"update_id"`
}

EditRecordOutput models the response returned by API_EditRecord See https://help.quickbase.com/api-guide/edit_record.html

type FieldList

type FieldList []int

FieldList models field lists in API requests.

func (FieldList) MarshalXML

func (f FieldList) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML converts a list of fields to a "." delimited string.

type GetSchemaInput

type GetSchemaInput struct {
	RequestParams
	Credentials

	ID string `xml:"-"`
}

GetSchemaInput models requests sent to API_GetSchema. See https://help.quickbase.com/api-guide/getschema.html

type GetSchemaOutput

type GetSchemaOutput struct {
	ResponseParams

	Fields []DoQueryOutputField `xml:"table>fields>field"`
}

GetSchemaOutput models responses returned API_GetSchema. See https://help.quickbase.com/api-guide/getschema.html

type HTMLOutput

type HTMLOutput interface {
	Output
	// contains filtered or unexported methods
}

HTMLOutput is the interfaces implemented by structs that model responses returned from the Quick Base API requests with raw HTML payloads.

type ImportFromCSVInput

type ImportFromCSVInput struct {
	RequestParams
	Credentials

	TableID          string                     `xml:"-"`
	FieldList        FieldList                  `xml:"clist,omitempty"`
	OutputFieldList  FieldList                  `xml:"clist_output,omitempty"`
	MergeFieldID     int                        `xml:"mergeFieldId,omitempty"`
	DecimalAsPercent Bool                       `xml:"decimalPercent,omitempty"`
	Records          *ImportFromCSVInputRecords `xml:"records_CSV"`
	SkipFirstRow     Bool                       `xml:"skipfirst,omitempty"`
}

ImportFromCSVInput models the request sent to API_ImportFromCSV See https://help.quickbase.com/api-guide/importfromcsv.html

func (*ImportFromCSVInput) CSV

func (input *ImportFromCSVInput) CSV(csv []byte)

CSV sets raw CSV data.

func (*ImportFromCSVInput) EnsureRecords

func (input *ImportFromCSVInput) EnsureRecords() *ImportFromCSVInputRecords

EnsureRecords returns an initialized Records property. This method should be used in favor of accessing the property directly to avoid null pointer exceptions.

func (*ImportFromCSVInput) FormatCSV

func (input *ImportFromCSVInput) FormatCSV(records [][]string)

FormatCSV converts a string slice slice ([][]string) into CSV data.

type ImportFromCSVInputRecords

type ImportFromCSVInputRecords struct {
	CSV string `xml:",cdata"`
}

ImportFromCSVInputRecords models the "records_CSV" element in API_ImportFromCSV requests.

type ImportFromCSVOutput

type ImportFromCSVOutput struct {
	ResponseParams

	NumRecordsAdded   int                         `xml:"num_recs_added"`
	NumRecordsInput   int                         `xml:"num_recs_input"`
	NumRecordsUpdated int                         `xml:"num_recs_updated"`
	Records           []ImportFromCSVOutputRecord `xml:"rids>rid,omitempty"`
}

ImportFromCSVOutput models the response returned by API_ImportFromCSV See https://help.quickbase.com/api-guide/importfromcsv.html

type ImportFromCSVOutputRecord

type ImportFromCSVOutputRecord struct {
	ID       int `xml:",chardata"`
	UpdateID int `xml:"update_id,attr"`
}

ImportFromCSVOutputRecord models the "rids>rid" element in API_ImportFromCSV responses.

type Input

type Input interface {
	// contains filtered or unexported methods
}

Input is the interface implemented by structs that model requests sent to the Quick Base API.

type Output

type Output interface {
	// contains filtered or unexported methods
}

Output is the interface implemented by structs that model responses returned from Quick Base API requests.

type Plugin

type Plugin interface {

	// PreRequest is the hook that is invoked prior to the request being
	// sent to the Quick Base API.
	PreRequest(context.Context, *http.Request) context.Context

	// PostResponse is the hook invoked after the response is sent from the
	// Quick Base API. This hook is invoked whether the request was
	// successful or not.
	PostResponse(context.Context, *http.Request, *http.Response, []byte, error) context.Context
}

Plugin is the interface implemented by plugins that hook into the API request process.

type RequestParams

type RequestParams struct {
	XMLName           xml.Name `xml:"qdbapi"`
	UserData          string   `xml:"udata,omitempty"`
	MillisecondsInUTC Bool     `xml:"msInUTC,omitempty"`
}

RequestParams models the parameters that are common to all API requests.

type ResponseParams

type ResponseParams struct {
	XMLName     xml.Name `xml:"qdbapi" json:"-"`
	Action      string   `xml:"action" json:"-"`
	ErrorCode   int      `xml:"errcode" json:"-"`
	ErrorText   string   `xml:"errtext" json:"-"`
	ErrorDetail string   `xml:"errdetail" json:"-"`
	UserData    string   `xml:"udata,omitempty" json:"user_data,omitempty"`
}

ResponseParams implements Output and models the parameters that are common to all responses.

type SetVariableInput

type SetVariableInput struct {
	RequestParams
	Credentials

	AppID string `xml:"-"`
	Name  string `xml:"varname"`
	Value string `xml:"value"`
}

SetVariableInput models the request sent to API_SetDBvar See https://help.quickbase.com/api-guide/setdbvar.html

type SetVariableOutput

type SetVariableOutput struct {
	ResponseParams
}

SetVariableOutput models the response returned by API_SetDBvar See https://help.quickbase.com/api-guide/setdbvar.html

type StandardConfig

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

StandardConfig wraps viper.Viper "Get*" methods to return configuration.

func NewConfig

func NewConfig() StandardConfig

NewConfig returns a StandardConfig that reads configuration from explicitly set options, environment variables, and a TOML configuration file in that order of preference.

func (StandardConfig) AppID

func (c StandardConfig) AppID() string

AppID implements Config.AppID().

func (StandardConfig) AppToken

func (c StandardConfig) AppToken() string

AppToken implements Config.AppToken().

func (StandardConfig) ConfigFile

func (c StandardConfig) ConfigFile() string

ConfigFile implements Config.ConfigFile().

func (StandardConfig) RealmHost

func (c StandardConfig) RealmHost() string

RealmHost implements Config.RealmHost().

func (StandardConfig) Set

func (c StandardConfig) Set(key string, value interface{})

Set explicitly sets a configuration option.

func (StandardConfig) TableID

func (c StandardConfig) TableID() string

TableID implements Config.TableID().

func (StandardConfig) Ticket

func (c StandardConfig) Ticket() string

Ticket implements Config.Ticket().

func (StandardConfig) TicketFile

func (c StandardConfig) TicketFile() string

TicketFile implements Config.TicketFile().

func (StandardConfig) UserToken

func (c StandardConfig) UserToken() string

UserToken implements Config.UserToken().

type TicketFileError

type TicketFileError struct {
	File string
	Err  error
}

TicketFileError implents the error interface and records an error reading from and writing to the ticket file.

func (TicketFileError) Error

func (e TicketFileError) Error() string

Error satisfies the error interface and simply returns the error string of the underlying error.

type UploadFileInput

type UploadFileInput struct {
	RequestParams
	Credentials

	TableID  string                 `xml:"-"`
	Fields   []UploadFileInputField `xml:"field"`
	RecordID int                    `xml:"rid"`
}

UploadFileInput models the request sent to API_UploadFile See https://help.quickbase.com/api-guide/uploadfile.html

type UploadFileInputField

type UploadFileInputField struct {
	ID       int    `xml:"fid,attr"`
	FileData string `xml:",chardata"`
	Name     string `xml:"filename,attr"`
}

UploadFileInputField models the "field" element in API_UploadFile requests.

type UploadFileOutput

type UploadFileOutput struct {
	ResponseParams

	Fields []UploadFileOutputField `xml:"file_fields>field" json:"fields"`
}

UploadFileOutput models the response returned by API_UploadFile See https://help.quickbase.com/api-guide/uploadfile.html

type UploadFileOutputField

type UploadFileOutputField struct {
	ID  int    `xml:"id,attr" json:"field_id"`
	URL string `xml:"url" json:"url"`
}

UploadFileOutputField models the "file_fields>field" element in API_UploadFile responses.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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