/
telegraph.go
43 lines (31 loc) · 915 Bytes
/
telegraph.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
package telegraph
// http://telegra.ph/api
// constants
const (
APIBaseURL = "https://api.telegra.ph"
)
// Verbose flag for logging
var Verbose bool // default: false
// Client struct
type Client struct {
AccessToken string
Socks5Proxy string
}
// Create creates a new Telegraph client.
func Create(shortName, authorName, authorURL string, socks5Proxy string) (*Client, error) {
client := Client{Socks5Proxy: socks5Proxy}
created, err := client.CreateAccount(shortName, authorName, authorURL)
if err == nil {
return &Client{AccessToken: created.AccessToken, Socks5Proxy: socks5Proxy}, nil
}
return nil, err
}
// Load a Telegraph client with access token.
func Load(accessToken string, socks5Proxy string) (*Client, error) {
client := Client{AccessToken: accessToken, Socks5Proxy: socks5Proxy}
_, err := client.GetAccountInfo(nil)
if err == nil {
return &client, nil
}
return nil, err
}