-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathescalation_chain.go
151 lines (120 loc) · 4.34 KB
/
escalation_chain.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package aapi
import (
"fmt"
"net/http"
)
// EscalationChainService handles requests to escalation chain endpoint
//
// https://grafana.com/docs/grafana-cloud/oncall/oncall-api-reference/escalation_chains/
type EscalationChainService struct {
client *Client
url string
}
// NewEscalationChainService creates EscalationChainService with corresponding url part
func NewEscalationChainService(client *Client) *EscalationChainService {
escalationChainService := EscalationChainService{}
escalationChainService.client = client
escalationChainService.url = "escalation_chains"
return &escalationChainService
}
type PaginatedEscalationChainsResponse struct {
PaginatedResponse
EscalationChains []*EscalationChain `json:"results"`
}
type EscalationChain struct {
ID string `json:"id"`
Name string `json:"name"`
TeamId string `json:"team_id"`
}
type ListEscalationChainOptions struct {
ListOptions
Name string `url:"name,omitempty" json:"name,omitempty"`
}
// ListEscalationChains fetches all escalation chains for current organization.
//
// https://grafana.com/docs/grafana-cloud/oncall/oncall-api-reference/escalation_chains/#list-escalation-chains
func (service *EscalationChainService) ListEscalationChains(opt *ListEscalationChainOptions) (*PaginatedEscalationChainsResponse, *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 escalation_chains *PaginatedEscalationChainsResponse
resp, err := service.client.Do(req, &escalation_chains)
if err != nil {
return nil, resp, err
}
return escalation_chains, resp, err
}
type GetEscalationChainOptions struct {
}
// GetEscalationChain fetches escalation chain by given id.
//
// https://grafana.com/docs/grafana-cloud/oncall/oncall-api-reference/escalation_chains/#get-an-escalation-chain
func (service *EscalationChainService) GetEscalationChain(id string, opt *GetEscalationChainOptions) (*EscalationChain, *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
}
escalation_chain := new(EscalationChain)
resp, err := service.client.Do(req, escalation_chain)
if err != nil {
return nil, resp, err
}
return escalation_chain, resp, err
}
type CreateEscalationChainOptions struct {
Name string `json:"name,omitempty"`
TeamId string `json:"team_id"`
}
// CreateEscalationChain creates escalation chain with name and team_id.
//
// https://grafana.com/docs/grafana-cloud/oncall/oncall-api-reference/escalation_chains/#create-an-escalation-chain
func (service *EscalationChainService) CreateEscalationChain(opt *CreateEscalationChainOptions) (*EscalationChain, *http.Response, error) {
u := fmt.Sprintf("%s/", service.url)
req, err := service.client.NewRequest("POST", u, opt)
if err != nil {
return nil, nil, err
}
escalationChain := new(EscalationChain)
resp, err := service.client.Do(req, escalationChain)
if err != nil {
return nil, resp, err
}
return escalationChain, resp, err
}
type UpdateEscalationChainOptions struct {
Name string `json:"name,omitempty"`
TeamId string `json:"team_id"`
}
// UpdateEscalationChain updates escalation chain with name.
//
// https://grafana.com/docs/grafana-cloud/oncall/oncall-api-reference/escalation_chains/#update-an-escalation-chain
func (service *EscalationChainService) UpdateEscalationChain(id string, opt *UpdateEscalationChainOptions) (*EscalationChain, *http.Response, error) {
u := fmt.Sprintf("%s/%s/", service.url, id)
req, err := service.client.NewRequest("PUT", u, opt)
if err != nil {
return nil, nil, err
}
escalationChain := new(EscalationChain)
resp, err := service.client.Do(req, escalationChain)
if err != nil {
return nil, resp, err
}
return escalationChain, resp, err
}
type DeleteEscalationChainOptions struct {
}
// DeleteEscalationChain deletes escalation chain.
//
// https://grafana.com/docs/grafana-cloud/oncall/oncall-api-reference/escalation_chains/#delete-an-escalation-chain
func (service *EscalationChainService) DeleteEscalationChain(id string, opt *DeleteEscalationChainOptions) (*http.Response, error) {
u := fmt.Sprintf("%s/%s/", service.url, id)
req, err := service.client.NewRequest("DELETE", u, opt)
if err != nil {
return nil, err
}
resp, err := service.client.Do(req, nil)
return resp, err
}