api

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultContentType    = "application/json"
	DefaultAccept         = DefaultContentType
	DefaultCacheControl   = "no-cache"
	MaxEntitiesPerRequest = 250
)

Variables

View Source
var (
	ErrNoContent                  = errors.New("no content")
	ErrNoAuth                     = errors.New("not authorized")
	ErrUnreachable                = errors.New("unreachable")
	ErrInvalidOptionsURL          = errors.New("invalid URL options")
	ErrInvalidExchangeAuthOptions = errors.New(
		"invalid ExchangeAuth options",
	)
	ErrUrlParsing = errors.New("URL parsing")
)

Functions

func NewErrorAPI added in v0.5.0

func NewErrorAPI(err error) error

func NewRequestError added in v0.5.0

func NewRequestError(err error) error

Types

type Client

type Client struct {
	*log.Logger

	BaseURL *url.URL

	Debug bool
	// contains filtered or unexported fields
}

func NewAPI added in v0.5.0

func NewAPI(secretPath string) (*Client, error)

func (*Client) ExchangeAuth

func (api *Client) ExchangeAuth() (*TokenPair, error)

func (*Client) Get

func (api *Client) Get(
	u string,
	result interface{},
) error

func (*Client) Patch

func (api *Client) Patch(
	u string,
	request any,
	result any,
) error

func (*Client) Post

func (api *Client) Post(
	u string,
	request any,
	result any,
) error

func (*Client) RefreshToken

func (api *Client) RefreshToken() (*OAuthTokenResponse, error)

func (*Client) RefreshTokenIfExpired

func (api *Client) RefreshTokenIfExpired() error

func (*Client) RequestsMade added in v0.6.0

func (client *Client) RequestsMade() int64

func (*Client) SetMRPS added in v0.6.0

func (client *Client) SetMRPS(rps int) *Client

Set maximum requests per second.

type ClientOptions

type ClientOptions struct {
	URL         string `json:"url"`
	RedirectURL string `json:"redirect_url"`

	AuthCode string `json:"auth_code"`

	ClientId     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`

	AccessToken string `json:"access_token"`

	ExpirationAt time.Time `json:"expiration_at,omitempty"`
	RefreshToken string    `json:"refresh_token"`
}

type OAuthTokenResponse added in v0.5.0

type OAuthTokenResponse struct {
	TokenType    string `json:"token_type"`
	ExpiresIn    int    `json:"expires_in"`
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
}

type RequestOptions added in v0.5.0

type RequestOptions struct {
	Method  string
	Body    interface{}
	Headers map[string]string
}

type TokenPair

type TokenPair struct {
	Access, Refresh string
}

Jump to

Keyboard shortcuts

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