forked from tim-online/go-twinfield
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
61 lines (46 loc) · 1.52 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package twinfield
import "net/http"
const (
libraryVersion = "0.0.1"
// loginEndpoint = "https://login.twinfield.com/webservices/session.asmx?wsdl"
userAgent = "go-twinfield/" + libraryVersion
mediaType = "text/xml"
)
func NewClient(httpClient *http.Client, user string, password string, organisation string) *Client {
if httpClient == nil {
httpClient = http.DefaultClient
}
// set package globals :(
User = user
Password = password
Organisation = organisation
// baseURL, _ := url.Parse(defaultBaseURL)
c := &Client{client: httpClient, UserAgent: userAgent}
// c.Products = &ProductsService{client: c}
return c
}
func NewOauthClient(httpClient *http.Client, clientID, clientSecret, refreshToken string) *Client {
if httpClient == nil {
httpClient = http.DefaultClient
}
// set package globals :(
ClientID = clientID
ClientSecret = clientSecret
RefreshToken = refreshToken
// baseURL, _ := url.Parse(defaultBaseURL)
c := &Client{client: httpClient, UserAgent: userAgent}
// c.Products = &ProductsService{client: c}
return c
}
type Client struct {
// HTTP client used to communicate with the DO API.
client *http.Client
// User agent for client
UserAgent string
// Services used for communicating with the API
Login *LoginService
// Optional function called after every successful request made to the DO APIs
onRequestCompleted RequestCompletionCallback
}
// RequestCompletionCallback defines the type of the request callback function
type RequestCompletionCallback func(*http.Request, *http.Response)