forked from schmorrison/Zoho
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzoho.go
62 lines (54 loc) · 1.56 KB
/
zoho.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
62
package zoho
import (
"net"
"net/http"
"time"
)
// New initializes a Zoho structure
func New() *Zoho {
z := Zoho{
client: &http.Client{
Timeout: time.Second * 10,
Transport: &http.Transport{
Dial: (&net.Dialer{
Timeout: 5 * time.Second,
}).Dial,
TLSHandshakeTimeout: 5 * time.Second,
},
},
tokensFile: "./.tokens.zoho",
}
return &z
}
// SetTokenManager can be used to provide a type which implements the TokenManager interface
// which will get/set AccessTokens/RefreshTokens using a persistence mechanism
func (z *Zoho) SetTokenManager(tm TokenLoaderSaver) {
z.tokenManager = tm
}
// SetTokensFile can be used to set the file location of the token persistence location,
// by default tokens are stored in a file in the current directory called '.tokens.zoho'
func (z *Zoho) SetTokensFile(s string) {
z.tokensFile = s
}
// CustomHTTPClient can be used to provide a custom HTTP Client that replaces the once instantiated
// when executing New()
//
// A notable use case is AppEngine where a user must use the appengine/urlfetch packages provided http client
// when performing outbound http requests.
func (z *Zoho) CustomHTTPClient(c *http.Client) {
z.client = c
}
// Zoho is for accessing all APIs. It is used by subpackages to simplify passing authentication
// values between API subpackages.
type Zoho struct {
oauth struct {
scopes []ScopeString
clientID string
clientSecret string
redirectURI string
token AccessTokenResponse
}
client *http.Client
tokenManager TokenLoaderSaver
tokensFile string
}