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
|
package kbchat
import (
"encoding/json"
"fmt"
"strings"
"github.com/keybase/go-keybase-chat-bot/kbchat/types/keybase1"
)
type ListTeamMembers struct {
Result keybase1.TeamDetails `json:"result"`
Error Error `json:"error"`
}
type ListMembersOutputMembersCategory struct {
Username string `json:"username"`
FullName string `json:"fullName"`
}
type ListUserMemberships struct {
Result keybase1.AnnotatedTeamList `json:"result"`
Error Error `json:"error"`
}
func (a *API) ListMembersOfTeam(teamName string) (res keybase1.TeamMembersDetails, err error) {
apiInput := fmt.Sprintf(`{"method": "list-team-memberships", "params": {"options": {"team": "%s"}}}`, teamName)
cmd := a.runOpts.Command("team", "api")
cmd.Stdin = strings.NewReader(apiInput)
bytes, err := cmd.CombinedOutput()
if err != nil {
return res, APIError{err}
}
members := ListTeamMembers{}
err = json.Unmarshal(bytes, &members)
if err != nil {
return res, UnmarshalError{err}
}
if members.Error.Message != "" {
return res, members.Error
}
return members.Result.Members, nil
}
func (a *API) ListUserMemberships(username string) ([]keybase1.AnnotatedMemberInfo, error) {
apiInput := fmt.Sprintf(`{"method": "list-user-memberships", "params": {"options": {"username": "%s"}}}`, username)
cmd := a.runOpts.Command("team", "api")
cmd.Stdin = strings.NewReader(apiInput)
bytes, err := cmd.CombinedOutput()
if err != nil {
return nil, APIError{err}
}
members := ListUserMemberships{}
err = json.Unmarshal(bytes, &members)
if err != nil {
return nil, UnmarshalError{err}
}
if members.Error.Message != "" {
return nil, members.Error
}
return members.Result.Teams, nil
}
|