-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathnotification.go
92 lines (72 loc) · 2.57 KB
/
notification.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
package client
type NotificationType string
const (
NotificationTypeSlack NotificationType = "Slack"
NotificationTypeTeams NotificationType = "Teams"
NotificationTypeEmail NotificationType = "Email"
NotificationTypeWebhook NotificationType = "Webhook"
)
type Notification struct {
Id string `json:"id"`
CreatedBy string `json:"createdBy"`
CreatedByUser User `json:"createdByUser"`
OrganizationId string `json:"organizationId"`
Name string `json:"name"`
Type NotificationType `json:"type"`
Value string `json:"value"`
}
type NotificationCreatePayload struct {
Name string `json:"name"`
Type NotificationType `json:"type"`
Value string `json:"value"`
WebhookSecret string `json:"webhookSecret,omitempty"`
}
type NotificationCreatePayloadWith struct {
NotificationCreatePayload
OrganizationId string `json:"organizationId"`
}
type NotificationUpdatePayload struct {
Name string `json:"name,omitempty"`
Type NotificationType `json:"type,omitempty"`
Value string `json:"value,omitempty"`
WebhookSecret **string `json:"webhookSecret,omitempty" tfschema:"-"`
}
func (client *ApiClient) Notifications() ([]Notification, error) {
organizationId, err := client.OrganizationId()
if err != nil {
return nil, err
}
var result []Notification
if err := client.http.Get("/notifications/endpoints", map[string]string{"organizationId": organizationId}, &result); err != nil {
return nil, err
}
return result, nil
}
func (client *ApiClient) NotificationCreate(payload NotificationCreatePayload) (*Notification, error) {
var result Notification
organizationId, err := client.OrganizationId()
if err != nil {
return nil, err
}
payloadWithOrganizationId := NotificationCreatePayloadWith{
NotificationCreatePayload: payload,
OrganizationId: organizationId,
}
if err = client.http.Post("/notifications/endpoints", payloadWithOrganizationId, &result); err != nil {
return nil, err
}
return &result, nil
}
func (client *ApiClient) NotificationDelete(id string) error {
if err := client.http.Delete("/notifications/endpoints/"+id, nil); err != nil {
return err
}
return nil
}
func (client *ApiClient) NotificationUpdate(id string, payload NotificationUpdatePayload) (*Notification, error) {
var result Notification
if err := client.http.Patch("/notifications/endpoints/"+id, payload, &result); err != nil {
return nil, err
}
return &result, nil
}