forked from DrFaust92/go-pingdom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
contact_types.go
78 lines (67 loc) · 2.3 KB
/
contact_types.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
package pingdom
import (
"encoding/json"
"fmt"
)
// NotificationTargets represents different ways a contact could be notified of alerts
type NotificationTargets struct {
SMS []SMSNotification `json:"sms,omitempty"`
Email []EmailNotification `json:"email,omitempty"`
APNS []APNSNotification `json:"apns,omitempty"`
AGCM []AGCMNotification `json:"agcm,omitempty"`
}
// SMSNotification represents a text message notification
type SMSNotification struct {
CountryCode string `json:"country_code"`
Number string `json:"number"`
Provider string `json:"provider"`
Severity string `json:"severity"`
}
// EmailNotification represents an email address notification
type EmailNotification struct {
Address string `json:"address"`
Severity string `json:"severity"`
}
// APNSNotification represents an APNS device notification
type APNSNotification struct {
Device string `json:"apns_device"`
Name string `json:"device_name"`
Severity string `json:"severity"`
}
// AGCMNotification represents an AGCM notification
type AGCMNotification struct {
AGCMID string `json:"agcm_id"`
Severity string `json:"severity"`
}
// ContactTeam represents an alerting team from the view of a Contact
type ContactTeam struct {
ID int `json:"id"`
Name string `json:"name"`
}
// Contact represents a Pingdom Contact.
type Contact struct {
ID int `json:"id"`
Name string `json:"name"`
NotificationTargets NotificationTargets `json:"notification_targets"`
Owner bool `json:"owner"`
Paused bool `json:"paused"`
Teams []ContactTeam `json:"teams"`
Type string `json:"type"`
}
// ValidContact determines whether a Contact contains valid fields.
func (c *Contact) ValidContact() error {
if c.Name == "" {
return fmt.Errorf("Invalid value for `Name`. Must contain non-empty string")
}
return nil
}
// RenderForJSONAPI returns the JSON formatted version of this object that may be submitted to Pingdom
func (c *Contact) RenderForJSONAPI() string {
u := map[string]interface{}{
"name": c.Name,
"notification_targets": c.NotificationTargets,
"paused": c.Paused,
}
jsonBody, _ := json.Marshal(u)
return string(jsonBody)
}