-
Notifications
You must be signed in to change notification settings - Fork 1
/
support_hour.go
249 lines (211 loc) · 7.29 KB
/
support_hour.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
package ilert
import (
"encoding/json"
"errors"
"fmt"
"net/url"
"strconv"
)
// SupportHour definition https://api.ilert.com/api-docs/#tag/SupportHours
type SupportHour struct {
ID int64 `json:"id"`
Name string `json:"name"`
Teams []TeamShort `json:"teams,omitempty"`
Timezone string `json:"timezone,omitempty"`
SupportDays *SupportDays `json:"supportDays"`
}
// CreateSupportHourInput represents the input of a CreateSupportHour operation.
type CreateSupportHourInput struct {
_ struct{}
SupportHour *SupportHour
}
// CreateSupportHourOutput represents the output of a CreateSupportHour operation.
type CreateSupportHourOutput struct {
_ struct{}
SupportHour *SupportHour
}
// CreateSupportHour creates a new support hours resource. https://api.ilert.com/api-docs/#tag/Support-Hours/paths/~1support-hours/post
func (c *Client) CreateSupportHour(input *CreateSupportHourInput) (*CreateSupportHourOutput, error) {
if input == nil {
return nil, errors.New("input is required")
}
if input.SupportHour == nil {
return nil, errors.New("support hour input is required")
}
resp, err := c.httpClient.R().SetBody(input.SupportHour).Post(apiRoutes.supportHours)
if err != nil {
return nil, err
}
if apiErr := getGenericAPIError(resp, 201); apiErr != nil {
return nil, apiErr
}
supportHour := &SupportHour{}
err = json.Unmarshal(resp.Body(), supportHour)
if err != nil {
return nil, err
}
return &CreateSupportHourOutput{SupportHour: supportHour}, nil
}
// GetSupportHourInput represents the input of a GetSupportHour operation.
type GetSupportHourInput struct {
_ struct{}
SupportHourID *int64
}
// GetSupportHourOutput represents the output of a GetSupportHour operation.
type GetSupportHourOutput struct {
_ struct{}
SupportHour *SupportHour
}
// GetSupportHour gets the support hours resource with specified id. https://api.ilert.com/api-docs/#tag/Support-Hours/paths/~1support-hours~1{id}/get
func (c *Client) GetSupportHour(input *GetSupportHourInput) (*GetSupportHourOutput, error) {
if input == nil {
return nil, errors.New("input is required")
}
if input.SupportHourID == nil {
return nil, errors.New("support hour id is required")
}
resp, err := c.httpClient.R().Get(fmt.Sprintf("%s/%d", apiRoutes.supportHours, *input.SupportHourID))
if err != nil {
return nil, err
}
if apiErr := getGenericAPIError(resp, 200); apiErr != nil {
return nil, apiErr
}
supportHour := &SupportHour{}
err = json.Unmarshal(resp.Body(), supportHour)
if err != nil {
return nil, err
}
return &GetSupportHourOutput{SupportHour: supportHour}, nil
}
// GetSupportHoursInput represents the input of a GetSupportHours operation.
type GetSupportHoursInput struct {
_ struct{}
// an integer specifying the starting point (beginning with 0) when paging through a list of entities
StartIndex *int
// the maximum number of results when paging through a list of entities.
// Maximum: 100
MaxResults *int
}
// GetSupportHoursOutput represents the output of a GetSupportHours operation.
type GetSupportHoursOutput struct {
_ struct{}
SupportHours []*SupportHour
}
// GetSupportHours lists existing support hours resources. https://api.ilert.com/api-docs/#tag/Support-Hours/paths/~1support-hours/get
func (c *Client) GetSupportHours(input *GetSupportHoursInput) (*GetSupportHoursOutput, error) {
q := url.Values{}
if input.StartIndex != nil {
q.Add("start-index", strconv.Itoa(*input.StartIndex))
}
if input.MaxResults != nil {
q.Add("max-results", strconv.Itoa(*input.MaxResults))
}
resp, err := c.httpClient.R().Get(fmt.Sprintf("%s?%s", apiRoutes.supportHours, q.Encode()))
if err != nil {
return nil, err
}
if apiErr := getGenericAPIError(resp, 200); apiErr != nil {
return nil, apiErr
}
supportHours := make([]*SupportHour, 0)
err = json.Unmarshal(resp.Body(), &supportHours)
if err != nil {
return nil, err
}
return &GetSupportHoursOutput{SupportHours: supportHours}, nil
}
// SearchSupportHourInput represents the input of a SearchSupportHour operation.
type SearchSupportHourInput struct {
_ struct{}
SupportHourName *string
}
// SearchSupportHourOutput represents the output of a SearchSupportHour operation.
type SearchSupportHourOutput struct {
_ struct{}
SupportHour *SupportHour
}
// SearchSupportHour gets the support hours resource with specified name.
func (c *Client) SearchSupportHour(input *SearchSupportHourInput) (*SearchSupportHourOutput, error) {
if input == nil {
return nil, errors.New("input is required")
}
if input.SupportHourName == nil {
return nil, errors.New("support hour name is required")
}
resp, err := c.httpClient.R().Get(fmt.Sprintf("%s/name/%s", apiRoutes.supportHours, *input.SupportHourName))
if err != nil {
return nil, err
}
if apiErr := getGenericAPIError(resp, 200); apiErr != nil {
return nil, apiErr
}
supportHour := &SupportHour{}
err = json.Unmarshal(resp.Body(), supportHour)
if err != nil {
return nil, err
}
return &SearchSupportHourOutput{SupportHour: supportHour}, nil
}
// UpdateSupportHourInput represents the input of a UpdateSupportHour operation.
type UpdateSupportHourInput struct {
_ struct{}
SupportHourID *int64
SupportHour *SupportHour
}
// UpdateSupportHourOutput represents the output of a UpdateSupportHour operation.
type UpdateSupportHourOutput struct {
_ struct{}
SupportHour *SupportHour
}
// UpdateSupportHour updates an existing support hours resource. https://api.ilert.com/api-docs/#tag/Support-Hours/paths/~1support-hours~1{id}/put
func (c *Client) UpdateSupportHour(input *UpdateSupportHourInput) (*UpdateSupportHourOutput, error) {
if input == nil {
return nil, errors.New("input is required")
}
if input.SupportHour == nil {
return nil, errors.New("support hour input is required")
}
if input.SupportHourID == nil {
return nil, errors.New("support hour id is required")
}
resp, err := c.httpClient.R().SetBody(input.SupportHour).Put(fmt.Sprintf("%s/%d", apiRoutes.supportHours, *input.SupportHourID))
if err != nil {
return nil, err
}
if apiErr := getGenericAPIError(resp, 200); apiErr != nil {
return nil, apiErr
}
supportHour := &SupportHour{}
err = json.Unmarshal(resp.Body(), supportHour)
if err != nil {
return nil, err
}
return &UpdateSupportHourOutput{SupportHour: supportHour}, nil
}
// DeleteSupportHourInput represents the input of a DeleteSupportHour operation.
type DeleteSupportHourInput struct {
_ struct{}
SupportHourID *int64
}
// DeleteSupportHourOutput represents the output of a DeleteSupportHour operation.
type DeleteSupportHourOutput struct {
_ struct{}
}
// DeleteSupportHour deletes the specified support hours resource. https://api.ilert.com/api-docs/#tag/Support-Hours/paths/~1support-hours~1{id}/delete
func (c *Client) DeleteSupportHour(input *DeleteSupportHourInput) (*DeleteSupportHourOutput, error) {
if input == nil {
return nil, errors.New("input is required")
}
if input.SupportHourID == nil {
return nil, errors.New("support hour id is required")
}
resp, err := c.httpClient.R().Delete(fmt.Sprintf("%s/%d", apiRoutes.supportHours, *input.SupportHourID))
if err != nil {
return nil, err
}
if apiErr := getGenericAPIError(resp, 204); apiErr != nil {
return nil, apiErr
}
return &DeleteSupportHourOutput{}, nil
}