-
Notifications
You must be signed in to change notification settings - Fork 7
/
user_group.go
64 lines (53 loc) · 1.61 KB
/
user_group.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
package aapi
import (
"fmt"
"net/http"
)
// UserGroupService handles requests for user group endpoint
//
// https://grafana.com/docs/grafana-cloud/oncall/oncall-api-reference/user_groups/
type UserGroupService struct {
client *Client
url string
}
// NewUserGroupService creates UserGroupService with defined url
func NewUserGroupService(client *Client) *UserGroupService {
userGroupService := UserGroupService{}
userGroupService.client = client
userGroupService.url = "user_groups"
return &userGroupService
}
type PaginatedUserGroupsResponse struct {
PaginatedResponse
UserGroups []*UserGroup `json:"results"`
}
type UserGroup struct {
ID string `json:"id"`
Type string `json:"type"`
SlackUserGroup *SlackUserGroup `json:"slack"`
}
type SlackUserGroup struct {
ID string `json:"id"`
Name string `json:"name"`
Handle string `json:"handle"`
}
type ListUserGroupOptions struct {
ListOptions
SlackHandle string `url:"slack_handle,omitempty" json:"slack_handle,omitempty"`
}
// ListUserGroups gets all UserGroups for authorized organization
//
// https://grafana.com/docs/grafana-cloud/oncall/oncall-api-reference/user_groups/#list-user-groups
func (service *UserGroupService) ListUserGroups(opt *ListUserGroupOptions) (*PaginatedUserGroupsResponse, *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 userGroups *PaginatedUserGroupsResponse
resp, err := service.client.Do(req, &userGroups)
if err != nil {
return nil, resp, err
}
return userGroups, resp, err
}