forked from customerio/go-customerio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.go
49 lines (44 loc) · 1.02 KB
/
auth.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
package customerio
import (
"encoding/json"
"fmt"
"net/http"
)
// RegionInfo is the response from FindRegion
type RegionInfo struct {
DataCenter string `json:"data_center"`
EnvironmentID uint64 `json:"environment_id"`
URL string `json:"url"`
}
/*
// Example Response
{
"url": "https://track.customer.io",
"data_center": "us",
"environment_id": 3
}
*/
// FindRegion will return the url, data center and environment id
// See: https://customer.io/docs/api/#tag/trackAuth
func (c *Client) FindRegion() (region *RegionInfo, err error) {
var resp StandardResponse
if resp, err = c.request(
http.MethodGet,
fmt.Sprintf("%s/api/v1/accounts/region", c.options.trackURL),
nil,
); err != nil {
return
}
err = json.Unmarshal(resp.Body, ®ion)
return
}
// TestAuth will test your current Tracking API credentials
// See: https://customer.io/docs/api/#tag/trackAuth
func (c *Client) TestAuth() error {
_, err := c.request(
http.MethodGet,
fmt.Sprintf("%s/auth", c.options.trackURL),
nil,
)
return err
}