api

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Version string
)

Functions

This section is empty.

Types

type APIError added in v0.3.3

type APIError struct {
	Message string `json:"message"`
	Status  int    `json:"status"`
	Title   string `json:"title"`
}

func (APIError) Error added in v0.3.3

func (e APIError) Error() string

type ChildEndpoint

type ChildEndpoint[T any] struct {
	Path string
	// contains filtered or unexported fields
}

func NewChildEndpoint

func NewChildEndpoint[T any](svc *Service, parentPath, childPath string) *ChildEndpoint[T]

func (*ChildEndpoint[T]) Create

func (ce *ChildEndpoint[T]) Create(ctx context.Context, parentID string, mdl *T) error

func (*ChildEndpoint[T]) Delete

func (ce *ChildEndpoint[T]) Delete(ctx context.Context, parentID string, id string) error

func (*ChildEndpoint[T]) Get

func (ce *ChildEndpoint[T]) Get(ctx context.Context, parentID string, id string) (*T, error)

func (*ChildEndpoint[T]) Patch

func (ce *ChildEndpoint[T]) Patch(ctx context.Context, parentID string, id string, mdl *T) error

func (*ChildEndpoint[T]) Search

func (ce *ChildEndpoint[T]) Search(ctx context.Context, parentID string, opts ...*Options) (SearchResult[T], error)

func (*ChildEndpoint[T]) Update

func (ce *ChildEndpoint[T]) Update(ctx context.Context, parentID string, id string, mdl *T) error

type Endpoint

type Endpoint[T any] struct {
	Path string
	// contains filtered or unexported fields
}

func NewEndpoint

func NewEndpoint[T any](svc *Service, path string) *Endpoint[T]

func (*Endpoint[T]) Create

func (e *Endpoint[T]) Create(ctx context.Context, mdl *T) error

Create creates a new model of type T within the API

func (*Endpoint[T]) Delete

func (e *Endpoint[T]) Delete(ctx context.Context, id string) error

Delete deletes a model of type T from the API

func (*Endpoint[T]) Get

func (e *Endpoint[T]) Get(ctx context.Context, id string) (*T, error)

Get gets a single model of type T from the API

func (*Endpoint[T]) Patch

func (e *Endpoint[T]) Patch(ctx context.Context, id string, mdl *T) error

Patch updates a model of type T within the API while preserving any fields that are omitted and any additional externalIDs that already exist

func (*Endpoint[T]) Search

func (e *Endpoint[T]) Search(ctx context.Context, opts ...*Options) (SearchResult[T], error)

Search searches for models of type T within the API

func (*Endpoint[T]) Update

func (e *Endpoint[T]) Update(ctx context.Context, id string, mdl *T) error

Update updates a model of type T within the API

type Options

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

func EmptyOptions

func EmptyOptions() *Options

EmptyOptions returns a new options struct which can be used in conjunction with the various API methods to control the results returned from the API.

func (*Options) AddField

func (o *Options) AddField(field ...string) *Options

AddField adds a field to the options used to control which fields are returned in the results for an API request.

func (*Options) AddFilter

func (o *Options) AddFilter(field string, value ...any) *Options

AddFilter adds a field and value to the options used to control which results are returned for an API request.

func (*Options) AddPage

func (o *Options) AddPage(field string, value int) *Options

AddPage sets pagination values for the desired pagination strategy... the PageDefauilt uses "offset" and "limit", but this method can be used to suggest a different strategy (e.g. "page" and "size") if desired (though, PageDefault is recommended).

func (*Options) AddSort

func (o *Options) AddSort(field ...string) *Options

AddSort adds a field to the options used to control which fields are used to sort the results for an API request. Provided a field name prefixed with a "-" will sort the results in descending order (e.g. "-name" or "-updatedAt").

func (*Options) FormatQuery added in v0.3.0

func (o *Options) FormatQuery() string

func (*Options) NextPage

func (o *Options) NextPage() *Options

NextPage increments the offset value by the limit value for navigating to the next page of results. This method assumes the default pagination strategy of "offset" and "limit" is used.

func (*Options) PageDefault

func (o *Options) PageDefault() *Options

PageDefault resets the pagination options to the default values of "offset" and "limit". This method is useful for resetting the pagination options when switching between different pagination strategies.

func (*Options) PreviousPage

func (o *Options) PreviousPage() *Options

PreviousPage decrements the offset value by the limit value for navigating to the previous page of results. This method assumes the default pagination strategy of "offset" and "limit" is used.

func (*Options) Query

func (o *Options) Query() url.Values

Query returns a url.Values representation of the options struct which can be used to construct a query string for an API request.

func (*Options) RemoveField

func (o *Options) RemoveField(field string) *Options

RemoveField removes a field from the options used to control which fields are returned in the results for an API request.

func (*Options) RemoveFilter

func (o *Options) RemoveFilter(field string) *Options

RemoveFilter removes a field and value from the options used to control which results are returned for an API request.

func (*Options) RemovePage

func (o *Options) RemovePage(field string) *Options

RemovePage removes pagination values for the desired pagination strategy... the PageDefauilt uses "offset" and "limit", but this method can be used to suggest a different strategy (e.g. "page" and "size") if desired (though, PageDefault is recommended).

func (*Options) RemoveSort

func (o *Options) RemoveSort(field string) *Options

RemoveSort removes a field from the options used to control which fields are used to sort the results for an API request.

type ReadChildResource

type ReadChildResource[T any] interface {
	Search(context.Context, string, ...*Options) (SearchResult[T], error)
	Get(context.Context, string, string) (*T, error)
}

type ReadResource

type ReadResource[T any] interface {
	Search(context.Context, ...*Options) (SearchResult[T], error)
	Get(context.Context, string) (*T, error)
}

type SearchResult

type SearchResult[T any] struct {
	Data    []*T          `json:"data"`
	Options query.Options `json:"options"`
	Total   uint          `json:"total"`
}

SearchResult is a generic struct for returning search results from any API. It contains the list of results, the query options used to generate the results, and the total number of results.

type Service

type Service struct {
	Host  string
	Proto string
	// contains filtered or unexported fields
}

Service represents the environment in which the API is being used. It contains the name of the environment, the protocol, and a valid token for making API requests within the environment.

func NewService

func NewService(svr string, oauth2 *clientcredentials.Config) *Service

NewService returns a new Environment with the given name and token. The protocol is set to the default protocol (https).

func (*Service) IsValid

func (e *Service) IsValid() bool

IsValid returns true if the environment name, protocol, and token are not blank.

type WriteChildResouce

type WriteChildResouce[T any] interface {
	Create(context.Context, string, *T) error
	Delete(context.Context, string, string) error
	Patch(context.Context, string, string, *T) error
	Update(context.Context, string, string, *T) error
}

type WriteResource

type WriteResource[T any] interface {
	Create(context.Context, *T) error
	Delete(context.Context, string) error
	Patch(context.Context, string, *T) error
	Update(context.Context, string, *T) error
}

Jump to

Keyboard shortcuts

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