forked from kothar/asana-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteams.go
72 lines (56 loc) · 1.94 KB
/
teams.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
package asana
import (
"fmt"
)
// Team is used to group related projects and people together within an
// organization. Each project in an organization is associated with a team.
type Team struct {
client *Client
// Read-only. Globally unique ID of the object
ID string `json:"gid,omitempty"`
// Read-only. The name of the object.
Name string `json:"name,omitempty"`
// The description of the team with formatting as HTML.
Description string `json:"description,omitempty"`
// The description of the team with formatting as HTML.
HTMLDescription string `json:"html_description,omitempty"`
Organization *Workspace `json:"organization,omitempty"`
}
// Fetch loads the full details for this Team
func (t *Team) Fetch(client *Client) error {
client.trace("Loading team details for %q\n", t.Name)
// Use fields options to request Organization field which is not returned by default
_, err := client.get(fmt.Sprintf("/teams/%s", t.ID), nil, t, Fields(*t))
return err
}
// Teams returns the compact records for all teams in the organization visible to the authorized user
func (w *Workspace) Teams(options ...*Options) ([]*Team, *NextPage, error) {
w.client.trace("Listing teams in workspace %s...\n", w.ID)
var result []*Team
// Make the request
nextPage, err := w.client.get(fmt.Sprintf("/organizations/%s/teams", w.ID), nil, &result, options...)
for _, r := range result {
r.client = w.client
}
return result, nextPage, err
}
// AllTeams repeatedly pages through all available teams in a workspace
func (w *Workspace) AllTeams(options ...*Options) ([]*Team, error) {
var allTeams []*Team
nextPage := &NextPage{}
var teams []*Team
var err error
for nextPage != nil {
page := &Options{
Limit: 100,
Offset: nextPage.Offset,
}
allOptions := append([]*Options{page}, options...)
teams, nextPage, err = w.Teams(allOptions...)
if err != nil {
return nil, err
}
allTeams = append(allTeams, teams...)
}
return allTeams, nil
}