-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathulule.go
More file actions
51 lines (44 loc) · 1.12 KB
/
ulule.go
File metadata and controls
51 lines (44 loc) · 1.12 KB
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
package ulule
import (
"crypto/tls"
"net/http"
"time"
)
// ClientAPI is a structure that can be used to
// communicate with Ulule's API
type Client struct {
// authentication
// different methods will be used depending on what's provided
// basic auth / api key auth / oauth access token
username string
userid string
apikey string
accessToken string
password string
httpClient *http.Client
}
// ClientWithUsernameAndApiKey returns a Client initialized with given
// username and api key
func ClientWithUsernameAndApiKey(username, apikey string) *Client {
clientAPI := &Client{
username: username,
apikey: apikey,
}
clientAPI.initHttpClient()
return clientAPI
}
// ClientWithToken returns a Client initialized with OAuth2 access token
func ClientWithToken(accessToken string) *Client {
clientAPI := &Client{
accessToken: accessToken,
}
clientAPI.initHttpClient()
return clientAPI
}
// utils
func (c *Client) initHttpClient() {
transport := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
c.httpClient = &http.Client{Transport: transport, Timeout: time.Second * 30}
}