-
Notifications
You must be signed in to change notification settings - Fork 72
/
member.go
84 lines (75 loc) · 2.56 KB
/
member.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
// Copyright © 2016 Aaron Longwell
//
// Use of this source code is governed by an MIT license.
// Details in the LICENSE file.
package trello
import (
"fmt"
)
// Member represents a Trello member.
// https://developers.trello.com/reference/#member-object
type Member struct {
client *Client
ID string `json:"id"`
Username string `json:"username"`
FullName string `json:"fullName"`
Initials string `json:"initials"`
AvatarHash string `json:"avatarHash"`
Email string `json:"email"`
IDBoards []string `json:"idBoards"`
IDOrganizations []string `json:"idOrganizations"`
}
// GetMember takes a member id and Arguments and returns a Member or an error.
func (c *Client) GetMember(memberID string, extraArgs ...Arguments) (member *Member, err error) {
args := flattenArguments(extraArgs)
path := fmt.Sprintf("members/%s", memberID)
err = c.Get(path, args, &member)
if err == nil {
member.SetClient(c)
}
return
}
// GetMyMember returns Member for the user authenticating the API call
func (c *Client) GetMyMember(args Arguments) (member *Member, err error) {
path := "members/me"
err = c.Get(path, args, &member)
if err == nil {
member.SetClient(c)
}
return
}
// GetMembers takes Arguments and returns a slice of all members of the organization or an error.
func (o *Organization) GetMembers(extraArgs ...Arguments) (members []*Member, err error) {
args := flattenArguments(extraArgs)
path := fmt.Sprintf("organizations/%s/members", o.ID)
err = o.client.Get(path, args, &members)
for i := range members {
members[i].SetClient(o.client)
}
return
}
// GetMembers takes Arguments and returns a slice of all members of the Board or an error.
func (b *Board) GetMembers(extraArgs ...Arguments) (members []*Member, err error) {
args := flattenArguments(extraArgs)
path := fmt.Sprintf("boards/%s/members", b.ID)
err = b.client.Get(path, args, &members)
for i := range members {
members[i].SetClient(b.client)
}
return
}
// GetMembers takes Arguments and returns a slice of all members of the Card or an error.
func (c *Card) GetMembers(extraArgs ...Arguments) (members []*Member, err error) {
args := flattenArguments(extraArgs)
path := fmt.Sprintf("cards/%s/members", c.ID)
err = c.client.Get(path, args, &members)
for i := range members {
members[i].SetClient(c.client)
}
return
}
// SetClient can be used to override this Member's internal connection to the
// Trello API. Normally, this is set automatically after API calls.
func (m *Member) SetClient(newClient *Client) {
m.client = newClient
}