-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathusers.go
100 lines (69 loc) · 1.98 KB
/
users.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package dbl
import (
"encoding/json"
)
type User struct {
// The id of the user
ID string `json:"id"`
// The username of the user
Username string `json:"username"`
// The discriminator of the user
Discriminator string `json:"discriminator"`
// The avatar hash of the user's avatar (may be empty)
Avatar string `json:"avatar"`
// The cdn hash of the user's avatar if the user has none
DefAvatar string `json:"defAvatar"`
// The bio of the user
Biography string `json:"bio"`
// The banner image url of the user (may be empty)
Banner string `json:"banner"`
Social *Social `json:"social"`
// The custom hex color of the user (may be empty)
Color string `json:"color"`
// The supporter status of the user
Supporter bool `json:"supporter"`
// The certified status of the user
CertifiedDeveloper bool `json:"certifiedDev"`
// The mod status of the user
Moderator bool `json:"mod"`
// The website moderator status of the user
WebsiteModerator bool `json:"webMod"`
// The admin status of the user
Admin bool `json:"admin"`
}
type Social struct {
// The youtube channel id of the user (may be empty)
Youtube string `json:"youtube"`
// The reddit username of the user (may be empty)
Reddit string `json:"reddit"`
// The twitter username of the user (may be empty)
Twitter string `json:"twitter"`
// The instagram username of the user (may be empty)
Instagram string `json:"instagram"`
// The github username of the user (may be empty)
Github string `json:"github"`
}
// Information about a particular user
func (c *Client) GetUser(UserID string) (*User, error) {
if c.token == "" {
return nil, ErrRequireAuthentication
}
req, err := c.createRequest("GET", "users/"+UserID, nil)
if err != nil {
return nil, err
}
res, err := c.httpClient.Do(req)
if err != nil {
return nil, err
}
body, err := c.readBody(res)
if err != nil {
return nil, err
}
user := &User{}
err = json.Unmarshal(body, user)
if err != nil {
return nil, err
}
return user, nil
}