-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathteam.go
76 lines (61 loc) · 1.58 KB
/
team.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
package aapi
import (
"fmt"
"net/http"
)
// TeamService handles requests to team endpoint
type TeamService struct {
client *Client
url string
}
// NewTeamService creates TeamService with defined url
func NewTeamService(client *Client) *TeamService {
teamService := TeamService{}
teamService.client = client
teamService.url = "teams"
return &teamService
}
type PaginatedTeamsResponse struct {
PaginatedResponse
Teams []*Team `json:"results"`
}
type Team struct {
ID string `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
AvatarUrl string `json:"avatar_url"`
}
type ListTeamOptions struct {
ListOptions
Name string `url:"name,omitempty" json:"name,omitempty"`
}
// ListTeams fetchs all Teams for authorized user
func (service *TeamService) ListTeams(opt *ListTeamOptions) (*PaginatedTeamsResponse, *http.Response, error) {
u := fmt.Sprintf("%s", service.url)
req, err := service.client.NewRequest("GET", u, opt)
if err != nil {
return nil, nil, err
}
var teams *PaginatedTeamsResponse
resp, err := service.client.Do(req, &teams)
if err != nil {
return nil, resp, err
}
return teams, resp, err
}
type GetTeamOptions struct {
}
// GetTeam fetches team by given id
func (service *TeamService) GetTeam(id string, opt *GetTeamOptions) (*Team, *http.Response, error) {
u := fmt.Sprintf("%s/%s/", service.url, id)
req, err := service.client.NewRequest("GET", u, opt)
if err != nil {
return nil, nil, err
}
team := new(Team)
resp, err := service.client.Do(req, team)
if err != nil {
return nil, resp, err
}
return team, resp, err
}