Documentation
¶
Index ¶
- Constants
- type Client
- func (c *Client) Call(ctx context.Context, method, path string, opts ...RequestOption) (*http.Response, error)
- func (c *Client) Do(req *http.Request) (*http.Response, error)
- func (c *Client) NewRequest(ctx context.Context, method, path string, body io.Reader) (*http.Request, error)
- func (c *Client) WithAPIKey(key string) ClientOption
- func (c *Client) WithHTTPClient(client *http.Client) ClientOption
- type ClientOption
- type RequestOption
Constants ¶
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 ¶
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) 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 ¶
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.