-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.go
More file actions
94 lines (78 loc) · 1.94 KB
/
Copy pathmain.go
File metadata and controls
94 lines (78 loc) · 1.94 KB
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
package main
import (
"context"
"fmt"
"os"
"github.com/StatusCakeDev/statuscake-go"
"github.com/StatusCakeDev/statuscake-go/credentials"
)
func main() {
var apiToken string
if apiToken = os.Getenv("STATUSCAKE_API_TOKEN"); apiToken == "" {
panic("STATUSCAKE_API_TOKEN not set in environment")
}
bearer := credentials.NewBearerWithStaticToken(apiToken)
client := statuscake.NewClient(statuscake.WithRequestCredentials(bearer))
res, err := client.CreateContactGroup(context.Background()).
Name("Operations Team").
EmailAddresses([]string{
"johnsmith@example.com",
"janesmith@example.com",
}).
Integrations([]string{
"1",
"2",
"3",
}).
MobileNumbers([]string{
"447712345678",
"447987462344",
}).
PingURL("https://ping.example.com").
Execute()
if err != nil {
printError(err)
return
}
groupID := res.Data.NewID
fmt.Printf("CONTACT GROUP ID: %s\n", groupID)
group, err := client.GetContactGroup(context.Background(), groupID).Execute()
if err != nil {
printError(err)
}
fmt.Printf("CONTACT GROUP: %+v\n", group.Data)
err = client.UpdateContactGroup(context.Background(), groupID).
Name("Development Team").
EmailAddresses([]string{}). // Remove all email addresses.
Integrations([]string{
"4",
"5",
"6",
}).
MobileNumbers([]string{
"447891998195",
}).
PingURL("https://ping.example.com/groups").
Execute()
if err != nil {
printError(err)
}
group, err = client.GetContactGroup(context.Background(), groupID).Execute()
if err != nil {
printError(err)
}
fmt.Printf("UPDATED CONTACT GROUP: %+v\n", group.Data)
groups, err := client.ListContactGroups(context.Background()).Execute()
if err != nil {
printError(err)
}
fmt.Printf("CONTACT GROUPS: %+v\n", groups.Data)
err = client.DeleteContactGroup(context.Background(), groupID).Execute()
if err != nil {
printError(err)
}
}
func printError(err error) {
fmt.Println(err)
fmt.Printf("%+v\n", statuscake.Errors(err))
}