-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpushover.go
95 lines (79 loc) · 2.18 KB
/
pushover.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
// Package pushover implements access to the Pushover API
//
// This documentation can be considered a supplement to the
// official Pushover API documentation at
// https://pushover.net/api. Refer to that official
// documentation for the details on how to us these
// library functions.
package pushover
import (
"fmt"
)
const (
keyCallback = "callback"
keyDevice = "device"
keyDevices = "devices"
keyErrors = "errors"
keyExpire = "expire"
keyGroup = "group"
keyHTML = "html"
keyLicenses = "licenses"
keyMessage = "message"
keyMonospace = "monospace"
keyPriority = "priority"
keyReceipt = "receipt"
keyRequest = "request"
keyRetry = "retry"
keySound = "sound"
keyStatus = "status"
keyTimestamp = "timestamp"
keyTitle = "title"
keyToken = "token"
keyURL = "url"
keyURLTitle = "url_title"
keyUser = "user"
)
// ErrInvalidRequest indicates invalid request data
// was sent to a library function
type ErrInvalidRequest struct{}
func (ir *ErrInvalidRequest) Error() string {
return "Invalid request"
}
// ErrInvalidResponse indicates an invalid response body
// was received from the Pushover API
type ErrInvalidResponse struct{}
func (ir *ErrInvalidResponse) Error() string {
return "Invalid response"
}
var messagesURL = "https://api.pushover.net/1/messages.json"
var validateURL = "https://api.pushover.net/1/users/validate.json"
func mapKeyToInt(key string, m map[string]interface{}) (int, bool) {
var value float64
var result int
var ok bool
if value, ok = m[key].(float64); ok {
result = int(value)
}
return result, ok
}
func interfaceArrayToStringArray(key string, m map[string]interface{}) []string {
var interfaceArray []interface{}
var stringArray []string
var ok bool
if interfaceArray, ok = m[key].([]interface{}); ok {
stringArray = make([]string, len(interfaceArray))
for i, v := range interfaceArray {
stringArray[i] = fmt.Sprintf("%v", v)
}
} else {
stringArray = []string{}
}
return stringArray
}
func interfaceMapToStringMap(inMap map[string]interface{}) map[string]string {
outMap := make(map[string]string)
for k, v := range inMap {
outMap[k] = fmt.Sprintf("%v", v)
}
return outMap
}