rest

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Revolts API
	RevoltAPI = "https://api.revolt.chat/"

	// The staging API, used by the official apps etc, default
	RevoltAPIStaging = "https://app.revolt.chat/api/"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Bytes

type Bytes struct {
	Raw []byte
}

Represents a raw byte array (avatars for example)

type Method

type Method string
const (
	HEAD    Method = "HEAD"
	GET     Method = "GET"
	POST    Method = "POST"
	PUT     Method = "PUT"
	PATCH   Method = "PATCH"
	DELETE  Method = "DELETE"
	OPTIONS Method = "OPTIONS"
)

type Request

type Request[T any] struct {
	Method  Method
	Path    string
	Json    any
	Headers map[string]string
	Cookies []http.Cookie

	// Initial response, if any
	InitialResp *T
	// contains filtered or unexported fields
}

A request to the API

func (Request[T]) NoContent

func (r Request[T]) NoContent(config *RestConfig) error

Discards the content as long as the response is OK otherwise error is returned

func (Request[T]) Request

func (r Request[T]) Request(config *RestConfig) (*http.Response, error)

Makes a request to the API

func (Request[T]) With

func (r Request[T]) With(config *RestConfig) (*T, error)

Executes the request and unmarshals the response body if the response is OK otherwise returns error

type RequestData

type RequestData struct {
	Method  Method
	Path    string
	Json    any
	Headers map[string]string
	Config  *RestConfig
}

Request data from API, but not generic so can be used in OnMarshal and other functions

In addition to typical Request data, this also contains config.Config

type RestConfig

type RestConfig struct {
	// The URL of the API
	APIUrl string

	// Timeout for requests
	Timeout time.Duration

	// Logger to use, will be autofilled if not provided
	Logger *zap.Logger

	// Session token for requests
	SessionToken *auth.Token

	// Ratelimiter
	Ratelimiter *ratelimits.RateLimiter

	// Max tries for requests
	MaxRestRetries int

	// On ratelimit function
	OnRatelimit func(*types.RateLimit)

	// Whether or not to retry on ratelimit
	RetryOnRatelimit bool

	// Pester client
	Pester *pester.Client

	// Functions to run upon successful marshal
	OnMarshal []func(r *RequestData, v any) error

	// Shared state for rest requests
	SharedState *state.State

	// Disable rest caching
	DisableRestCaching bool
}

func DefaultRestConfig

func DefaultRestConfig() RestConfig

DefaultRestConfig is the default configuration for the client

type RestError

type RestError struct {
	types.APIError
}

Note that a RestError satisfies the error interface

func (RestError) Error

func (r RestError) Error() string

Directories

Path Synopsis
Ratelimits impl from https://github.com/bwmarrin/discordgo/blob/master/ratelimit.go
Ratelimits impl from https://github.com/bwmarrin/discordgo/blob/master/ratelimit.go
+interactions <in docs but its actually reactions>
+interactions <in docs but its actually reactions>

Jump to

Keyboard shortcuts

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