/
types.go
87 lines (73 loc) · 2.25 KB
/
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
79
80
81
82
83
84
85
86
87
package poclient
import (
"fmt"
"time"
)
type loginReply struct {
Status int `json:"status"`
Userid string `json:"id"`
Secret string `json:"secret"`
Errors []string `json:"errors"`
}
type devicesReply struct {
Status int `json:"status"`
Deviceid string `json:"id"`
Errors map[string][]string `json:"errors"`
}
type messagesReply struct {
Status int `json:"status"`
Errors []string `json:"errors"`
Messages []Message `json:"messages"`
}
type deleteOldMessagesReply struct {
Status int `json:"status"`
Errors []string `json:"errors"`
}
type user struct {
ID string
Secret string
}
type device struct {
ID string
}
// Message represents a message loaded from the API
// The fields are documented here: https://pushover.net/api/client#download
type Message struct {
RelativeID int `json:"id"`
UniqueID int `json:"umid"`
Title string `json:"title"`
Text string `json:"message"`
AppName string `json:"app"`
AppID int `json:"aid"`
IconID string `json:"icon"`
Timestamp int64 `json:"date"`
Date time.Time `json:"-"`
Priority int `json:"priority"`
Sound string `json:"sound"`
URL string `json:"url"`
URLTitle string `json:"url_title"`
Acknowledged convertibleBoolean `json:"acked"`
ReceiptCode string `json:"receipt"`
ContainsHTML convertibleBoolean `json:"html"`
}
// Taken from https://stackoverflow.com/questions/30856454/how-to-unmarshall-both-0-and-false-as-bool-from-json
type convertibleBoolean bool
func (bit *convertibleBoolean) UnmarshalJSON(data []byte) error {
asString := string(data)
if asString == "1" || asString == "true" {
*bit = true
} else if asString == "0" || asString == "false" {
*bit = false
} else {
return fmt.Errorf("Boolean unmarshal error: invalid input %s", asString)
}
return nil
}
type ErrorFrameError struct{}
func (e *ErrorFrameError) Error() string {
return "Received error frame"
}
type Missing2FAError struct{}
func (e *Missing2FAError) Error() string {
return "2 Factor Authentication required"
}