-
Notifications
You must be signed in to change notification settings - Fork 1
/
user_duty_preference.go
245 lines (211 loc) · 8.36 KB
/
user_duty_preference.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
package ilert
import (
"encoding/json"
"errors"
"fmt"
)
// UserNotificationPreference definition https://api.ilert.com/api-docs/#tag/Notification-Preferences
type UserDutyPreference struct {
ID int64 `json:"id,omitempty"`
Method string `json:"method"`
Contact *UserContactShort `json:"contact"` // is either UserEmailContact or UserPhoneNumberContact
BeforeMin int64 `json:"beforeMin"`
Type string `json:"type"`
}
// UserDutyPreferenceMethodAll defines user duty notification preference method list
var UserDutyPreferenceMethodAll = []string{
UserPreferenceMethod.Email,
UserPreferenceMethod.Sms,
UserPreferenceMethod.Push,
UserPreferenceMethod.WhatsApp,
UserPreferenceMethod.Telegram,
}
// UserDutyPreferenceType defines user duty notification preference type
var UserDutyPreferenceType = struct {
OnCall string
}{
OnCall: "ON_CALL",
}
// UserDutyPreferenceTypeAll defines user duty notification preference type list
var UserDutyPreferenceTypeAll = []string{
UserDutyPreferenceType.OnCall,
}
// CreateUserDutyPreferenceInput represents the input of a CreateUserDutyPreference operation.
type CreateUserDutyPreferenceInput struct {
_ struct{}
UserID *int64
UserDutyPreference *UserDutyPreference
}
// CreateUserDutyPreferenceOutput represents the output of a CreateUserDutyPreference operation.
type CreateUserDutyPreferenceOutput struct {
_ struct{}
UserDutyPreference *UserDutyPreference
}
// CreateUserDutyPreference creates a new duty notification preference for a user. Requires ADMIN privileges or user id equals your current user. https://api.ilert.com/api-docs/#tag/Notification-Preferences/paths/~1users~1{user-id}~1notification-preferences~1duties/post
func (c *Client) CreateUserDutyPreference(input *CreateUserDutyPreferenceInput) (*CreateUserDutyPreferenceOutput, error) {
if input == nil {
return nil, errors.New("input is required")
}
if input.UserID == nil {
return nil, errors.New("user id is required")
}
if input.UserDutyPreference == nil {
return nil, errors.New("user duty notification preference input is required")
}
url := fmt.Sprintf("%s/%d/notification-preferences/duties", apiRoutes.users, *input.UserID)
resp, err := c.httpClient.R().SetBody(input.UserDutyPreference).Post(url)
if err != nil {
return nil, err
}
if apiErr := getGenericAPIError(resp, 201); apiErr != nil {
return nil, apiErr
}
preference := &UserDutyPreference{}
err = json.Unmarshal(resp.Body(), preference)
if err != nil {
return nil, err
}
return &CreateUserDutyPreferenceOutput{UserDutyPreference: preference}, nil
}
// GetUserDutyPreferenceInput represents the input of a GetUserDutyPreference operation.
type GetUserDutyPreferenceInput struct {
_ struct{}
UserID *int64
UserDutyPreferenceID *int64
}
// GetUserDutyPreferenceOutput represents the output of a GetUserDutyPreference operation.
type GetUserDutyPreferenceOutput struct {
_ struct{}
UserDutyPreference *UserDutyPreference
}
// GetUserDutyPreference gets an duty notification preference of a user by id. https://api.ilert.com/api-docs/#tag/Notification-Preferences/paths/~1users~1{user-id}~1notification-preferences~1duties~1{id}/get
func (c *Client) GetUserDutyPreference(input *GetUserDutyPreferenceInput) (*GetUserDutyPreferenceOutput, error) {
if input == nil {
return nil, errors.New("input is required")
}
if input.UserID == nil {
return nil, errors.New("user id is required")
}
if input.UserDutyPreferenceID == nil {
return nil, errors.New("user duty notification preference id is required")
}
url := fmt.Sprintf("%s/%d/notification-preferences/duties/%d", apiRoutes.users, *input.UserID, *input.UserDutyPreferenceID)
resp, err := c.httpClient.R().Get(url)
if err != nil {
return nil, err
}
if apiErr := getGenericAPIError(resp, 200); apiErr != nil {
return nil, apiErr
}
preference := &UserDutyPreference{}
err = json.Unmarshal(resp.Body(), preference)
if err != nil {
return nil, err
}
return &GetUserDutyPreferenceOutput{UserDutyPreference: preference}, nil
}
// GetUserDutyPreferencesInput represents the input of a GetUserDutyPreferences operation.
type GetUserDutyPreferencesInput struct {
_ struct{}
UserID *int64
}
// GetUserDutyPreferencesOutput represents the output of a GetUserDutyPreferences operation.
type GetUserDutyPreferencesOutput struct {
_ struct{}
UserDutyPreferences []*UserDutyPreference
}
// GetUserDutyPreferences lists existing duty notification preferences of a user. https://api.ilert.com/api-docs/#tag/Notification-Preferences/paths/~1users~1{user-id}~1notification-preferences~1duties/get
func (c *Client) GetUserDutyPreferences(input *GetUserDutyPreferencesInput) (*GetUserDutyPreferencesOutput, error) {
if input == nil {
return nil, errors.New("input is required")
}
if input.UserID == nil {
return nil, errors.New("user id is required")
}
url := fmt.Sprintf("%s/%d/notification-preferences/duties", apiRoutes.users, *input.UserID)
resp, err := c.httpClient.R().Get(url)
if err != nil {
return nil, err
}
if apiErr := getGenericAPIError(resp, 200); apiErr != nil {
return nil, apiErr
}
preferences := make([]*UserDutyPreference, 0)
err = json.Unmarshal(resp.Body(), &preferences)
if err != nil {
return nil, err
}
return &GetUserDutyPreferencesOutput{UserDutyPreferences: preferences}, nil
}
// UpdateUserDutyPreferenceInput represents the input of a UpdateUserDutyPreference operation.
type UpdateUserDutyPreferenceInput struct {
_ struct{}
UserID *int64
UserDutyPreferenceID *int64
UserDutyPreference *UserDutyPreference
}
// UpdateUserDutyPreferenceOutput represents the output of a UpdateUserDutyPreference operation.
type UpdateUserDutyPreferenceOutput struct {
_ struct{}
UserDutyPreference *UserDutyPreference
}
// UpdateUserDutyPreference updates an existing duty notification preference of a user. https://api.ilert.com/api-docs/#tag/Notification-Preferences/paths/~1users~1{user-id}~1notification-preferences~1duties~1{id}/put
func (c *Client) UpdateUserDutyPreference(input *UpdateUserDutyPreferenceInput) (*UpdateUserDutyPreferenceOutput, error) {
if input == nil {
return nil, errors.New("input is required")
}
if input.UserID == nil {
return nil, errors.New("user id is required")
}
if input.UserDutyPreferenceID == nil {
return nil, errors.New("user duty notification preference id is required")
}
if input.UserDutyPreference == nil {
return nil, errors.New("user input is required")
}
url := fmt.Sprintf("%s/%d/notification-preferences/duties/%d", apiRoutes.users, *input.UserID, *input.UserDutyPreferenceID)
resp, err := c.httpClient.R().SetBody(input.UserDutyPreference).Put(url)
if err != nil {
return nil, err
}
if apiErr := getGenericAPIError(resp, 200); apiErr != nil {
return nil, apiErr
}
preference := &UserDutyPreference{}
err = json.Unmarshal(resp.Body(), preference)
if err != nil {
return nil, err
}
return &UpdateUserDutyPreferenceOutput{UserDutyPreference: preference}, nil
}
// DeleteUserDutyPreferenceInput represents the input of a DeleteUserDutyPreference operation.
type DeleteUserDutyPreferenceInput struct {
_ struct{}
UserID *int64
UserDutyPreferenceID *int64
}
// DeleteUserDutyPreferenceOutput represents the output of a DeleteUserDutyPreference operation.
type DeleteUserDutyPreferenceOutput struct {
_ struct{}
}
// DeleteUserDutyPreference deletes the specified duty notification preference of a user. https://api.ilert.com/api-docs/#tag/Notification-Preferences/paths/~1users~1{user-id}~1notification-preferences~1duties~1{id}/delete
func (c *Client) DeleteUserDutyPreference(input *DeleteUserDutyPreferenceInput) (*DeleteUserDutyPreferenceOutput, error) {
if input == nil {
return nil, errors.New("input is required")
}
if input.UserID == nil {
return nil, errors.New("user id is required")
}
if input.UserDutyPreferenceID == nil {
return nil, errors.New("user duty notification preference id is required")
}
url := fmt.Sprintf("%s/%d/notification-preferences/duties/%d", apiRoutes.users, *input.UserID, *input.UserDutyPreferenceID)
resp, err := c.httpClient.R().Delete(url)
if err != nil {
return nil, err
}
if apiErr := getGenericAPIError(resp, 204); apiErr != nil {
return nil, apiErr
}
return &DeleteUserDutyPreferenceOutput{}, nil
}