lemonsqueezy.WithBaseURL   A
last analyzed

Complexity

Conditions 3

Size

Total Lines 4
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
package lemonsqueezy
2
3
import (
4
	"net/http"
5
	"strings"
6
)
7
8
// Option is options for constructing a client
9
type Option interface {
10
	apply(config *clientConfig)
11
}
12
13
type clientOptionFunc func(config *clientConfig)
14
15
func (fn clientOptionFunc) apply(config *clientConfig) {
16
	fn(config)
17
}
18
19
// WithHTTPClient sets the underlying HTTP client used for API requests.
20
// By default, http.DefaultClient is used.
21
func WithHTTPClient(httpClient *http.Client) Option {
22
	return clientOptionFunc(func(config *clientConfig) {
23
		if httpClient != nil {
24
			config.httpClient = httpClient
25
		}
26
	})
27
}
28
29
// WithBaseURL set's the base url for the flutterwave API
30
func WithBaseURL(baseURL string) Option {
31
	return clientOptionFunc(func(config *clientConfig) {
32
		if baseURL != "" {
33
			config.baseURL = strings.TrimRight(baseURL, "/")
34
		}
35
	})
36
}
37
38
// WithAPIKey sets the lemonsqueezy API used to authenticate requests.
39
// https://docs.lemonsqueezy.com/api#authentication
40
func WithAPIKey(apiKey string) Option {
41
	return clientOptionFunc(func(config *clientConfig) {
42
		config.apiKey = apiKey
43
	})
44
}
45
46
// WithSigningSecret sets the lemonsqueezy webhook signing secret used to authenticate webhook requests.
47
// https://docs.lemonsqueezy.com/api/webhooks#webhook-requests
48
func WithSigningSecret(signingSecret string) Option {
49
	return clientOptionFunc(func(config *clientConfig) {
50
		config.signingSecret = signingSecret
51
	})
52
}
53