diff --git a/notification/pushover.go b/notification/pushover.go index 9b35232..023ff9d 100644 --- a/notification/pushover.go +++ b/notification/pushover.go @@ -17,9 +17,10 @@ import ( ) type Pushover struct { - UserKey string `json:"user_key"` - APIKey string `json:"api_key"` - DeviceName string `json:"device_name"` + Description string + UserKey string `json:"user_key"` + APIKey string `json:"api_key"` + DeviceName string `json:"device_name"` Prio int AcknowledgeURL string @@ -70,6 +71,10 @@ func (po Pushover) Exists() bool { } func (po *Pushover) String() string { + if po.Description != "" { + return po.Description + } + return fmt.Sprintf("%s, %s", po.UserKey, po.APIKey) } @@ -135,23 +140,30 @@ func (po *Pushover) Update(values url.Values) (err error) { updated := Pushover{} po.updated = &updated + // Prio updated.Prio, err = strconv.Atoi(values.Get("prio")) if err != nil { return werr.Wrap(err) } + // Description + updated.Description = strings.TrimSpace(values.Get("description")) + + // API (application) key givenAPIKey := values.Get("api_key") if strings.TrimSpace(givenAPIKey) == "" { return werr.New("API key cannot be empty") } updated.APIKey = strings.TrimSpace(givenAPIKey) + // User key givenUserKey := values.Get("user_key") if strings.TrimSpace(givenUserKey) == "" { return werr.New("User key cannot be empty") } updated.UserKey = strings.TrimSpace(givenUserKey) + // Device name updated.DeviceName = strings.TrimSpace(values.Get("device_name")) return } @@ -163,6 +175,7 @@ func (po *Pushover) Updated() Service { func (po *Pushover) Commit() { updatedPushover := po.updated.(*Pushover) po.Prio = updatedPushover.Prio + po.Description = updatedPushover.Description po.APIKey = updatedPushover.APIKey po.UserKey = updatedPushover.UserKey po.DeviceName = updatedPushover.DeviceName @@ -170,10 +183,12 @@ func (po *Pushover) Commit() { func (po Pushover) JSON() []byte { data := struct { - APIKey string `json:"api_key"` - UserKey string `json:"user_key"` - DeviceName string `json:"device_name"` + Description string + APIKey string `json:"api_key"` + UserKey string `json:"user_key"` + DeviceName string `json:"device_name"` }{ + po.Description, po.APIKey, po.UserKey, po.DeviceName, diff --git a/views/pages/notification/pushover.gotmpl b/views/pages/notification/pushover.gotmpl index e483b03..f4dd438 100644 --- a/views/pages/notification/pushover.gotmpl +++ b/views/pages/notification/pushover.gotmpl @@ -29,13 +29,16 @@ div.grid > div {
Prio:
-
User key:
+
Description
+ + +
User key: *
-
API (application) key:
+
API (application) key: *
-
Device name (optional):
+
Device name: