forked from addcnos/youdu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
group.go
154 lines (126 loc) · 3.76 KB
/
group.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package youdu
import (
"context"
"net/http"
)
type CreateGroupRequest struct {
Name string `json:"name"`
}
type CreateGroupResponse struct {
Id string `json:"id"`
}
type UpdateGroupRequest struct {
Id string `json:"id"`
Name string `json:"name"`
}
type GroupUpdateMemberRequest struct {
Id string `json:"id"`
UserList []string `json:"userList"`
}
type GroupInfoMember struct {
Account string `json:"account"`
Name string `json:"name"`
Mobile string `json:"mobile"`
}
type GroupInfoResponse struct {
Id string `json:"id"`
Name string `json:"name"`
Members []GroupInfoMember `json:"members"`
}
type GroupItem struct {
Id string `json:"id"`
Name string `json:"name"`
}
type GroupListResponse struct {
GroupList []GroupItem `json:"groupList"`
}
type IsGroupMemberResponse struct {
Belong bool `json:"belong"`
}
func (c *Client) CreateGroup(ctx context.Context, request CreateGroupRequest) (response CreateGroupResponse, err error) {
req, err := c.newRequest(ctx, http.MethodPost, "/cgi/group/create",
withRequestBody(request), withRequestAccessToken(), withRequestEncrypt())
if err != nil {
return
}
err = c.sendRequest(req, &response, withResponseDecrypt())
return
}
func (c *Client) DeleteGroup(ctx context.Context, groupId string) (response Response, err error) {
req, err := c.newRequest(ctx, http.MethodGet, "/cgi/group/delete",
withRequestAccessToken(),
withRequestParamsKV("id", groupId),
)
if err != nil {
return
}
err = c.sendRequest(req, &response)
return
}
func (c *Client) UpdateGroup(ctx context.Context, request UpdateGroupRequest) (response Response, err error) {
req, err := c.newRequest(ctx, http.MethodPost, "/cgi/group/update",
withRequestBody(request), withRequestAccessToken(), withRequestEncrypt())
if err != nil {
return
}
err = c.sendRequest(req, &response)
return
}
func (c *Client) AddGroupMember(ctx context.Context, request GroupUpdateMemberRequest) (response Response, err error) {
req, err := c.newRequest(ctx, http.MethodPost, "/cgi/group/addmember",
withRequestBody(request), withRequestAccessToken(), withRequestEncrypt())
if err != nil {
return
}
err = c.sendRequest(req, &response)
return
}
func (c *Client) DelGroupMember(ctx context.Context, request GroupUpdateMemberRequest) (response Response, err error) {
req, err := c.newRequest(ctx, http.MethodPost, "/cgi/group/delmember",
withRequestBody(request), withRequestAccessToken(), withRequestEncrypt())
if err != nil {
return
}
err = c.sendRequest(req, &response)
return
}
func (c *Client) GetGroupInfo(ctx context.Context, groupId string) (response GroupInfoResponse, err error) {
req, err := c.newRequest(ctx, http.MethodGet, "/cgi/group/info",
withRequestAccessToken(),
withRequestEncrypt(),
withRequestParamsKV("id", groupId),
)
if err != nil {
return
}
err = c.sendRequest(req, &response, withResponseDecrypt())
return
}
func (c *Client) GetGroupList(ctx context.Context, userId ...string) (response GroupListResponse, err error) {
opts := []requestOption{
withRequestAccessToken(),
withRequestEncrypt(),
}
if len(userId) > 0 {
opts = append(opts, withRequestParamsKV("userId", userId[0]))
}
req, err := c.newRequest(ctx, http.MethodGet, "/cgi/group/list", opts...)
if err != nil {
return
}
err = c.sendRequest(req, &response, withResponseDecrypt())
return
}
func (c *Client) IsGroupMember(ctx context.Context, groupId string, userId string) (response IsGroupMemberResponse, err error) {
req, err := c.newRequest(ctx, http.MethodGet, "/cgi/group/ismember",
withRequestAccessToken(),
withRequestEncrypt(),
withRequestParamsKV("id", groupId),
withRequestParamsKV("userId", userId),
)
if err != nil {
return
}
err = c.sendRequest(req, &response, withResponseDecrypt())
return
}