-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmember_api.go
121 lines (98 loc) · 3.77 KB
/
member_api.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
package pkgo
import (
"emperror.dev/errors"
"github.com/google/uuid"
)
// Member gets a member by their ID.
func (s *Session) Member(id string) (m Member, err error) {
err = s.RequestJSON("GET", "/members/"+id, &m)
return
}
// MemberByUUID gets a member by their UUID.
func (s *Session) MemberByUUID(id uuid.UUID) (Member, error) {
return s.Member(id.String())
}
// Members gets all members of a system.
// If the system's member list is set to private, requires authentication.
// If the request is not authenticated, only public members will be returned.
func (s *Session) Members(id string) ([]Member, error) {
if id == "" {
return nil, errors.Sentinel("pkgo: no ID provided")
}
m := []Member{}
err := s.RequestJSON("GET", "/systems/"+id+"/members", &m)
return m, err
}
// EditMemberData is the data for s.EditMember.
type EditMemberData struct {
Name NullableString `json:"name,omitempty"`
DisplayName NullableString `json:"display_name,omitempty"`
Description NullableString `json:"description,omitempty"`
Pronouns NullableString `json:"pronouns,omitempty"`
Color *Color `json:"color,omitempty"`
Birthday *Birthday `json:"birthday,omitempty"`
AvatarURL NullableString `json:"avatar_url,omitempty"`
Banner NullableString `json:"banner,omitempty"`
ProxyTags []ProxyTag `json:"proxy_tags,omitempty"`
KeepProxy bool `json:"keep_proxy,omitempty"`
Privacy *MemberPrivacy `json:"privacy,omitempty"`
}
// EditMember edits a member by ID. Requires authentication.
func (s *Session) EditMember(id string, emd EditMemberData) (Member, error) {
var m Member
err := s.RequestJSON("PATCH", "/members/"+id, &m, WithJSONBody(emd))
return m, err
}
// CreateMemberData is the data for s.CreateMember.
type CreateMemberData struct {
Name string `json:"name,omitempty"`
DisplayName string `json:"display_name,omitempty"`
Description string `json:"description,omitempty"`
Pronouns string `json:"pronouns,omitempty"`
Color Color `json:"color,omitempty"`
Birthday Birthday `json:"birthday,omitempty"`
AvatarURL string `json:"avatar_url,omitempty"`
Banner string `json:"banner,omitempty"`
ProxyTags []ProxyTag `json:"proxy_tags,omitempty"`
KeepProxy bool `json:"keep_proxy"`
Privacy *MemberPrivacy `json:"privacy,omitempty"`
}
// CreateMember creates a member. Requires authentication.
func (s *Session) CreateMember(data CreateMemberData) (m Member, err error) {
err = s.RequestJSON("POST", "/members", &m, WithJSONBody(data))
return
}
// DeleteMember deletes a member. Requires authentication.
func (s *Session) DeleteMember(id string) (err error) {
_, err = s.Request("DELETE", "/members/"+id)
return
}
// AddMemberGroups adds a member to the given groups IDs.
func (s *Session) AddMemberGroups(memberID string, groupIDs []string) (err error) {
if groupIDs == nil {
groupIDs = []string{}
}
_, err = s.Request("POST", "/members/"+memberID+"/groups/add", WithJSONBody(groupIDs))
return
}
// RemoveMemberGroups removes a member from the given groups IDs.
func (s *Session) RemoveMemberGroups(memberID string, groupIDs []string) (err error) {
if groupIDs == nil {
groupIDs = []string{}
}
_, err = s.Request("POST", "/members/"+memberID+"/groups/remove", WithJSONBody(groupIDs))
return
}
// OverwriteMemberGroups overwrites a member's groups with the given groups IDs.
func (s *Session) OverwriteMemberGroups(memberID string, groupIDs []string) (err error) {
if groupIDs == nil {
groupIDs = []string{}
}
_, err = s.Request("POST", "/members/"+memberID+"/groups/overwrite", WithJSONBody(groupIDs))
return
}
// GroupMembers gets the members list of the given group.
func (s *Session) GroupMembers(groupID string) (m []Member, err error) {
err = s.RequestJSON("GET", "/groups/"+groupID+"/members", &m)
return
}