Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP client interface #47

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ import (
"net/http"
)

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

type APIClient struct {
Key string
URL string
UserAgent string
Client *http.Client
Client HTTPClient
}

// NewAPIClient prepares a client for use with the Customer.io API, see: https://customer.io/docs/api/#apicoreintroduction
Expand Down
2 changes: 1 addition & 1 deletion customerio.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type CustomerIO struct {
apiKey string
URL string
UserAgent string
Client *http.Client
Client HTTPClient
}

// CustomerIOError is returned by any method that fails at the API level
Expand Down
4 changes: 1 addition & 3 deletions options.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package customerio

import "net/http"

type option struct {
api func(*APIClient)
track func(*CustomerIO)
Expand Down Expand Up @@ -34,7 +32,7 @@ func WithRegion(r region) option {
}
}

func WithHTTPClient(client *http.Client) option {
func WithHTTPClient(client HTTPClient) option {
return option{
api: func(a *APIClient) {
a.Client = client
Expand Down