-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathrecipient.go
43 lines (35 loc) · 950 Bytes
/
recipient.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
package pushover
import "regexp"
var recipientRegexp *regexp.Regexp
func init() {
recipientRegexp = regexp.MustCompile(`^[A-Za-z0-9]{30}$`)
}
// Recipient represents the a recipient to notify.
type Recipient struct {
token string
}
// NewRecipient is the representation of the recipient to notify.
func NewRecipient(token string) *Recipient {
return &Recipient{token}
}
// Validates recipient token.
func (r *Recipient) validate() error {
// Check empty token
if r.token == "" {
return ErrEmptyRecipientToken
}
// Check invalid token
if !recipientRegexp.MatchString(r.token) {
return ErrInvalidRecipientToken
}
return nil
}
// RecipientDetails represents the receipt informations in case of emergency
// priority.
type RecipientDetails struct {
Status int `json:"status"`
Group int `json:"group"`
Devices []string `json:"devices"`
RequestID string `json:"request"`
Errors Errors `json:"errors"`
}