| Total Lines | 55 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | package orangemoney |
||
| 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 | // WithUsername sets the Orange API Username used to fetch the access token |
||
| 39 | func WithUsername(username string) Option { |
||
| 40 | return clientOptionFunc(func(config *clientConfig) { |
||
| 41 | config.username = username |
||
| 42 | }) |
||
| 43 | } |
||
| 44 | |||
| 45 | // WithPassword sets the Orange API password used to fetch the access token |
||
| 46 | func WithPassword(password string) Option { |
||
| 47 | return clientOptionFunc(func(config *clientConfig) { |
||
| 48 | config.password = password |
||
| 49 | }) |
||
| 50 | } |
||
| 51 | |||
| 52 | // WithAuthToken sets the X-AUTH-TOKEN used as a header of API requests |
||
| 53 | func WithAuthToken(authToken string) Option { |
||
| 54 | return clientOptionFunc(func(config *clientConfig) { |
||
| 55 | config.authToken = authToken |
||
| 56 | }) |
||
| 58 |