client

package
v0.0.1-beta.4 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2025 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// APIUrl is the URL of our API.
	APIUrl = "https://api.sumup.com"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func New

func New(opts ...ClientOption) *Client

New creates new HTTP API client. The client is by default configured with environment variables (e.g. `SUMUP_API_KEY`). To override the default configuration use [ClientOption]s.

func (*Client) Call

func (c *Client) Call(
	ctx context.Context, method, path string, opts ...RequestOption,
) (*http.Response, error)

Call executes a SumUp API call. Use [RequestOption]s to configure the request.

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

Do sends an HTTP request and returns an HTTP response, following policy (such as redirects, cookies, auth) as configured on the HTTP client.

func (*Client) NewRequest

func (c *Client) NewRequest(
	ctx context.Context, method, path string, body io.Reader,
) (*http.Request, error)

NewRequest returns a new http.Request given a method, URL, and optional body.

NewRequest returns a Request suitable for use with Client.Do.

func (*Client) WithAPIKey

func (c *Client) WithAPIKey(key string) ClientOption

WithAPIKey returns a ClientOption that configures the client with an API key for authorization.

func (*Client) WithBaseURL

func (c *Client) WithBaseURL(base string) ClientOption

WithBaseURL returns a ClientOption that configures the client with a base URL that the individual API call paths will be resolved against.

func (*Client) WithHTTPClient

func (c *Client) WithHTTPClient(client *http.Client) ClientOption

WithClient returns a ClientOption that configures the client to use a specific http client for underlying requests.

type ClientOption

type ClientOption func(c *Client) error

ClientOption is an option for the SumUp API client.

type RequestOption

type RequestOption func(req *request) error

RequestOption is an option for the request made by the SumUp Client.

func WithHTTPClient

func WithHTTPClient(client *http.Client) RequestOption

WithHTTPClient returns a RequestOption that overrides the underlying http.Client of the service used to make the request.

func WithHeader

func WithHeader(key, value string) RequestOption

WithHeader returns a RequestOption that sets a header key-value pair. Any previously set value will be overwritten.

func WithJSONBody

func WithJSONBody(v any) RequestOption

WithBody returns a RequestOption that sets the request body as a JSON of the value v.

func WithQueryValues

func WithQueryValues(q url.Values) RequestOption

WithQueryValues returns a RequestOption that sets the request query params.

Jump to

Keyboard shortcuts

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