forked from grafana/amixr-api-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
on_call_shift.go
199 lines (168 loc) · 6.97 KB
/
on_call_shift.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
package aapi
import (
"fmt"
"net/http"
)
// OnCallShiftService handles requests to on-call shift endpoint
//
// // https://grafana.com/docs/grafana-cloud/oncall/oncall-api-reference/on_call_shifts/
type OnCallShiftService struct {
client *Client
url string
}
// NewOnCallShiftService creates OnCallShiftService with defined url
func NewOnCallShiftService(client *Client) *OnCallShiftService {
onCallShiftService := OnCallShiftService{}
onCallShiftService.client = client
onCallShiftService.url = "on_call_shifts"
return &onCallShiftService
}
type PaginatedOnCallShiftsResponse struct {
PaginatedResponse
OnCallShifts []*OnCallShift `json:"results"`
}
type OnCallShift struct {
ID string `json:"id"`
TeamId string `json:"team_id"`
Type string `json:"type"`
Name string `json:"name"`
Level int `json:"level"`
Start string `json:"start"`
Duration int `json:"duration"`
Until *string `json:"until"`
Frequency *string `json:"frequency"`
Users *[]string `json:"users"`
Interval *int `json:"interval"`
WeekStart *string `json:"week_start"`
ByDay *[]string `json:"by_day"`
ByMonth *[]int `json:"by_month"`
ByMonthday *[]int `json:"by_monthday"`
RollingUsers *[][]string `json:"rolling_users"`
TimeZone *string `json:"time_zone"`
StartRotationFromUserIndex *int `json:"start_rotation_from_user_index"`
}
type ListOnCallShiftOptions struct {
ListOptions
ScheduleId string `url:"schedule_id,omitempty" json:"schedule_id,omitempty"`
Name string `url:"name,omitempty" json:"name,omitempty"`
}
// ListOnCallShifts fetches all on-call shifts for authorized organization
//
// https://grafana.com/docs/grafana-cloud/oncall/oncall-api-reference/on_call_shifts/#list-oncall-shifts
func (service *OnCallShiftService) ListOnCallShifts(opt *ListOnCallShiftOptions) (*PaginatedOnCallShiftsResponse, *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 onCallShifts *PaginatedOnCallShiftsResponse
resp, err := service.client.Do(req, &onCallShifts)
if err != nil {
return nil, resp, err
}
return onCallShifts, resp, err
}
type GetOnCallShiftOptions struct {
}
// GetOnCallShift fetches shift by given id
//
// https://grafana.com/docs/grafana-cloud/oncall/oncall-api-reference/on_call_shifts/#get-oncall-shifts
func (service *OnCallShiftService) GetOnCallShift(id string, opt *GetOnCallShiftOptions) (*OnCallShift, *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
}
onCallShift := new(OnCallShift)
resp, err := service.client.Do(req, onCallShift)
if err != nil {
return nil, resp, err
}
return onCallShift, resp, err
}
type CreateOnCallShiftOptions struct {
TeamId string `json:"team_id"`
Type string `json:"type"`
Name string `json:"name"`
Level *int `json:"level,omitempty"`
Start string `json:"start"`
Duration int `json:"duration"`
Until *string `json:"until"`
Frequency *string `json:"frequency"`
Users *[]string `json:"users"`
Interval *int `json:"interval"`
WeekStart *string `json:"week_start,omitempty"`
ByDay *[]string `json:"by_day"`
ByMonth *[]int `json:"by_month"`
ByMonthday *[]int `json:"by_monthday"`
Source int `json:"source"`
RollingUsers *[][]string `json:"rolling_users"`
TimeZone *string `json:"time_zone"`
StartRotationFromUserIndex *int `json:"start_rotation_from_user_index"`
}
// CreateOnCallShift creates an on-call shift
//
// https://grafana.com/docs/grafana-cloud/oncall/oncall-api-reference/on_call_shifts/#create-an-oncall-shift
func (service *OnCallShiftService) CreateOnCallShift(opt *CreateOnCallShiftOptions) (*OnCallShift, *http.Response, error) {
u := fmt.Sprintf("%s/", service.url)
req, err := service.client.NewRequest("POST", u, opt)
if err != nil {
return nil, nil, err
}
onCallShift := new(OnCallShift)
resp, err := service.client.Do(req, onCallShift)
if err != nil {
return nil, resp, err
}
return onCallShift, resp, err
}
type UpdateOnCallShiftOptions struct {
Type string `json:"type"`
Name string `json:"name"`
TeamId string `json:"team_id"`
Level *int `json:"level,omitempty"`
Start string `json:"start"`
Duration int `json:"duration"`
Until *string `json:"until"`
Frequency *string `json:"frequency"`
Users *[]string `json:"users"`
Interval *int `json:"interval"`
WeekStart *string `json:"week_start,omitempty"`
ByDay *[]string `json:"by_day"`
ByMonth *[]int `json:"by_month"`
ByMonthday *[]int `json:"by_monthday"`
Source int `json:"source"`
RollingUsers *[][]string `json:"rolling_users"`
TimeZone *string `json:"time_zone"`
StartRotationFromUserIndex *int `json:"start_rotation_from_user_index"`
}
// UpdateOnCallShift updates on-call shift
//
// https://grafana.com/docs/grafana-cloud/oncall/oncall-api-reference/on_call_shifts/#update-oncall-shift
func (service *OnCallShiftService) UpdateOnCallShift(id string, opt *UpdateOnCallShiftOptions) (*OnCallShift, *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
}
onCallShift := new(OnCallShift)
resp, err := service.client.Do(req, onCallShift)
if err != nil {
return nil, resp, err
}
return onCallShift, resp, err
}
type DeleteOnCallShiftOptions struct {
}
// DeleteOnCallShift deletes on-call shift
//
// https://grafana.com/docs/grafana-cloud/oncall/oncall-api-reference/on_call_shifts/#delete-oncall-shift
func (service *OnCallShiftService) DeleteOnCallShift(id string, opt *DeleteOnCallShiftOptions) (*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
}