forked from grafana/amixr-api-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slack_channel.go
57 lines (47 loc) · 1.52 KB
/
slack_channel.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
package aapi
import (
"fmt"
"net/http"
)
// SlackChannelService handles requests to slack channel endpoint
//
// // https://grafana.com/docs/grafana-cloud/oncall/oncall-api-reference/slack_channels/
type SlackChannelService struct {
client *Client
url string
}
// NewSlackChannelsService creates SlackChannelService with defined url
func NewSlackChannelService(client *Client) *SlackChannelService {
slackChannelService := SlackChannelService{}
slackChannelService.client = client
slackChannelService.url = "slack_channels"
return &slackChannelService
}
type PaginatedSlackChannelsResponse struct {
PaginatedResponse
SlackChannels []*SlackChannel `json:"results"`
}
type SlackChannel struct {
Name string `json:"name"`
SlackId string `json:"slack_id"`
}
type ListSlackChannelOptions struct {
ListOptions
ChannelName string `url:"channel_name,omitempty" json:"channel_name,omitempty"`
}
// ListSlackChannels gets all slackChannels for authorized organization
//
// https://grafana.com/docs/grafana-cloud/oncall/oncall-api-reference/slack_channels/#list-slack-channels
func (service *SlackChannelService) ListSlackChannels(opt *ListSlackChannelOptions) (*PaginatedSlackChannelsResponse, *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 slackChannels *PaginatedSlackChannelsResponse
resp, err := service.client.Do(req, &slackChannels)
if err != nil {
return nil, resp, err
}
return slackChannels, resp, err
}