client

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package client provides the base for all requests and responses to the Paddle API.

Index

Constants

This section is empty.

Variables

View Source
var ErrDirectiveRequiresBool = errors.New("include directive requires a boolean value")

ErrDirectiveRequiresBool is returned when the directive's struct field is not a boolean.

Functions

func ContextWithTransitID

func ContextWithTransitID(ctx context.Context, transitID string) context.Context

ContextWithTransitID returns a new context with the provided transit ID.

func TransitIDFromContext

func TransitIDFromContext(ctx context.Context) string

TransitIDFromContext returns the transit ID from the provided context.

Types

type Client

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

Client provides the base for all requests and responses to the Paddle API.

func New

func New(httpClient HTTPDoer, apiKey string, baseURL *url.URL) (*Client, error)

New returns a new Client with the provided http.Client, apiKey, and baseURL.

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, path string, src, dst any) (err error)

Do sends an API request and returns the API response. The src field is a request which contains `json` or `in` struct tags (see github.com/ggicci/httpin) and will be encoded as the request body. The dst field is a response which will be decoded from the response body. The dst field should be given as a pointer. If the src field is nil, no request body will be sent. If the dst field is nil, no response body will be decoded.

type DirectiveInclude

type DirectiveInclude struct{}

DirectiveInclude is a directive that adds the custom 'include' query parameter to the request, based on the value of the directive's struct field.

func (*DirectiveInclude) Decode

Decode is not implemented. This is because we only deal with encoding concerns in the client.

func (*DirectiveInclude) Encode

Encode adds/appends the custom 'include' query parameter to the request. The value of the directive's struct field is expected to be a boolean. If the value is true, the directive's value query parameter 'include'. e.g.

type Request struct {
 IncludeCustomer bool `in:"paddle_include=customer"`
}

Req{IncludeCustomer: true} // ?paddle_include=customer

type DirectiveQuery

type DirectiveQuery struct {
	core.DirectiveQuery
}

DirectiveQuery extends the core.DirectiveQuery struct from the httpin package and adds support for the "omitempty" tag.

func (*DirectiveQuery) Encode

func (d *DirectiveQuery) Encode(rtm *core.DirectiveRuntime) error

Encode adds the values of the input struct into the http.Request as query parameters. If the value is zero and the "omitempty" tag is present, the value will not be added to the query string.

type Doer

type Doer interface {
	Do(ctx context.Context, method, path string, src, dst any) (err error)
}

Doer is an interface that expects the Do method for making API requests.

type HTTPDoer

type HTTPDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPDoer is an interface that expects the Do method for making HTTP requests.

type Wanter

type Wanter interface {
	Wants(Doer)
}

Wanter is an interface that can be implemented by a response struct. It is used to inject the client into to the response struct after a request has been successfully made.

Jump to

Keyboard shortcuts

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