forked from grokify/goauth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_me.go
67 lines (55 loc) · 1.23 KB
/
get_me.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
63
64
65
66
67
package main
import (
"context"
"fmt"
"os"
"github.com/grokify/goauth/zendesk"
"github.com/grokify/mogo/config"
"github.com/grokify/mogo/fmt/fmtutil"
"github.com/grokify/mogo/net/http/httputilmore"
)
func MeURL(subdomain string) string {
return fmt.Sprintf("https://%v.zendesk.com/api/v2/users/me.json", subdomain)
}
func main() {
_, err := config.LoadDotEnv([]string{os.Getenv("ENV_PATH"), "./.env"}, -1)
if err != nil {
panic(err)
}
client, err := zendesk.NewClientPassword(
context.Background(),
os.Getenv("ZENDESK_USERNAME"),
os.Getenv("ZENDESK_PASSWORD"),
)
if err != nil {
panic(err)
}
subdomain := os.Getenv("ZENDESK_SUBDOMAIN")
if 1 == 0 {
meURL := MeURL(subdomain)
resp, err := client.Get(meURL)
if err != nil {
panic(err)
}
err = httputilmore.PrintResponse(resp, true)
if err != nil {
panic(err)
}
}
if 1 == 1 {
me, resp, err := zendesk.GetMe(client, subdomain)
if err != nil {
panic(err)
} else if resp.StatusCode >= 300 {
panic(fmt.Errorf("Status Code %v", resp.StatusCode))
}
fmtutil.PrintJSON(me)
cu := zendesk.NewClientUtil(client, subdomain)
scim, err := cu.GetSCIMUser()
if err != nil {
panic(err)
}
fmtutil.PrintJSON(scim)
}
fmt.Println("DONE")
}