-
Notifications
You must be signed in to change notification settings - Fork 1
/
user.go
114 lines (86 loc) · 2.5 KB
/
user.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package guildedgo
type User struct {
// The ID of the user
Id string `json:"id"`
// The type of user. If this property is absent, it can assumed to be of type user
Type string `json:"type,omitempty"`
Name string `json:"name"`
// The avatar image associated with the user
Avatar string `json:"avatar,omitempty"`
// The banner image associated with the user
Banner string `json:"banner,omitempty"`
// The ISO 8601 timestamp that the user was created at
CreatedAt string `json:"createdAt"`
Status UserStatus `json:"status,omitempty"`
}
type UserStatus struct {
Content string `json:"content,omitempty"`
EmoteID int `json:"emoteId"`
}
type UserSummary struct {
// The ID of the user
Id string `json:"id"`
// The type of user. If this property is absent, it can assumed to be of type user
Type string `json:"type,omitempty"`
Name string `json:"name"`
// The avatar image associated with the user
Avatar string `json:"avatar,omitempty"`
}
type UserStatusUpdate struct {
Content string `json:"content,omitempty"`
EmoteID int `json:"emoteId"`
ExpiresAt string `json:"expiresAt,omitempty"`
}
type UserResponse struct {
User `json:"user"`
}
const (
UserTypeUser = "user"
UserTypeBot = "bot"
)
type UserService interface {
GetUser(id string) (*User, error)
GetUsersServers(id string) ([]Server, error)
UpdateStatus(id string, status UserStatusUpdate) error
DeleteStatus(id string) error
}
type userService struct {
client *Client
}
var _ UserService = &userService{}
func (service *userService) GetUser(id string) (*User, error) {
endpoint := guildedApi + "/users/" + id
var response UserResponse
err := service.client.GetRequestV2(endpoint, &response)
if err != nil {
return nil, err
}
return &response.User, nil
}
func (service *userService) GetUsersServers(id string) ([]Server, error) {
endpoint := guildedApi + "/users/" + id + "/servers"
var response struct {
Servers []Server `json:"servers"`
}
err := service.client.GetRequestV2(endpoint, &response)
if err != nil {
return nil, err
}
return response.Servers, nil
}
func (service *userService) UpdateStatus(id string, status UserStatusUpdate) error {
endpoint := guildedApi + "/users/" + id + "/status"
err := service.client.PutRequestV2(endpoint, &status, nil)
if err != nil {
return err
}
return nil
}
func (service *userService) DeleteStatus(id string) error {
endpoint := guildedApi + "/users/" + id + "/status"
_, err := service.client.DeleteRequest(endpoint)
if err != nil {
return err
}
return nil
}