apis

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMaxRetryCountReached = fmt.Errorf("max retry count of %d reached", constants.MaxRetryCountOnTooManyRequestsError)
)

Functions

func AddToQueryIfSet added in v0.5.0

func AddToQueryIfSet(q url.Values, key string, value string)

func FirstNElementsOfSlice added in v0.5.0

func FirstNElementsOfSlice[Element any](slice []Element, n int) []Element

func MapToCommaString added in v0.5.0

func MapToCommaString[t any](slice []t) string

Types

type Call

type Call[responseType any] struct {
	Method                  string
	URL                     string
	QueryParams             url.Values
	Body                    []byte
	RestrictedDataToken     *string
	ParseErrorListOnError   bool
	WaitDurationOnRateLimit time.Duration
}

func NewCall

func NewCall[responseType any](method string, url string) *Call[responseType]

func (*Call[responseType]) Execute

func (a *Call[responseType]) Execute(httpClient HTTPClient) (*CallResponse[responseType], error)

Execute will return response object on success

func (*Call[responseType]) WithBody

func (a *Call[responseType]) WithBody(body []byte) *Call[responseType]

func (*Call[responseType]) WithParseErrorListOnError added in v0.3.0

func (a *Call[responseType]) WithParseErrorListOnError() *Call[responseType]

func (*Call[responseType]) WithQueryParams

func (a *Call[responseType]) WithQueryParams(queryParams url.Values) *Call[responseType]

func (*Call[responseType]) WithRateLimit added in v0.5.1

func (a *Call[responseType]) WithRateLimit(callsPer float32, duration time.Duration) *Call[responseType]

func (*Call[responseType]) WithRestrictedDataToken

func (a *Call[responseType]) WithRestrictedDataToken(token *string) *Call[responseType]

WithRestrictedDataToken is optional and can be passed to replace the existing accessToken

type CallResponse added in v0.3.0

type CallResponse[responseBodyType any] struct {
	Status       int
	ResponseBody *responseBodyType
	ErrorList    *ErrorList
}

func (*CallResponse[any]) ErrorsAsString added in v0.4.4

func (r *CallResponse[any]) ErrorsAsString() string

ErrorsAsString returns all errors as string or an empty string.

func (*CallResponse[any]) IsError added in v0.3.0

func (r *CallResponse[any]) IsError() bool

IsError checks if the status is in range 4xx - 5xx

func (*CallResponse[any]) IsSuccess added in v0.3.0

func (r *CallResponse[any]) IsSuccess() bool

IsSuccess checks if the status is in range 2xx

type Error

type Error struct {
	// An error code that identifies the type of error that occurred.
	Code string `json:"code"`
	// A message that describes the error condition in a human-readable form.
	Message string `json:"message"`
	// Additional details that can help the caller understand or fix the issue.
	Details *string `json:"details,omitempty"`
}

Error response returned when the request is unsuccessful.

type ErrorList

type ErrorList struct {
	Errors []Error `json:"errors"`
}

ErrorList A list of error responses returned when a request is unsuccessful.

type HTTPClient added in v0.6.0

type HTTPClient interface {
	Do(*http.Request) (*http.Response, error)
	GetEndpoint() constants.Endpoint
	Close()
}

type JsonTimeISO8601

type JsonTimeISO8601 struct {
	time.Time
}

JsonTimeISO8601 marshals time.Time to ISO 8601 format

func (JsonTimeISO8601) MarshalJSON

func (t JsonTimeISO8601) MarshalJSON() ([]byte, error)

func (JsonTimeISO8601) String

func (t JsonTimeISO8601) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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