-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalert.go
67 lines (47 loc) · 1.26 KB
/
alert.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
package dweetio
import (
"fmt"
"net/http"
)
//GET alert for a Thing
func (api *Dweetio) GetAlertFor(thing string) (dweets *Dweets, err error) {
if api.Key == "" {
return nil, fmt.Errorf("You need a LOCKED thing to get alerts")
}
uri := api.GetUri("/get/alert/for/", thing)
res, err := http.Get(uri)
//If error
api.ReturnError(err)
err = api.ReadData(res, &dweets)
//If error
api.ReturnError(err)
return dweets, nil
}
//REMOVE alert for a Thing
func (api *Dweetio) RemoveAlertFor(thing string) (dweets *Dweets, err error) {
if api.Key == "" {
return nil, fmt.Errorf("You need a LOCKED thing to remove alerts")
}
uri := api.GetUri("/remove/alert/for/", thing)
res, err := http.Get(uri)
//If error
api.ReturnError(err)
err = api.ReadData(res, &dweets)
//If error
api.ReturnError(err)
return dweets, nil
}
//CREATE alert for a Thing
func (api *Dweetio) SetAlertFor(thing string, recipients []string, condition string) (dweets *Dweets, err error) {
if api.Key == "" {
return nil, fmt.Errorf("You need a LOCKED thing to create alerts")
}
uri := api.GetAlertUri(recipients, thing, condition)
res, err := http.Get(uri)
//If error
api.ReturnError(err)
err = api.ReadData(res, &dweets)
//If error
api.ReturnError(err)
return dweets, nil
}