From df88cc80b7799fa1da9a3333be96e7d525410566 Mon Sep 17 00:00:00 2001 From: skubiak Date: Fri, 9 Jan 2015 07:56:01 +0100 Subject: [PATCH] added emergency parameters --- .../de/svenkubiak/jpushover/JPushover.java | 55 ++++++++++++++++++- .../svenkubiak/jpushover/enums/Constants.java | 7 ++- 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/svenkubiak/jpushover/JPushover.java b/src/main/java/de/svenkubiak/jpushover/JPushover.java index daf3769..6f0a8a3 100644 --- a/src/main/java/de/svenkubiak/jpushover/JPushover.java +++ b/src/main/java/de/svenkubiak/jpushover/JPushover.java @@ -34,6 +34,9 @@ public class JPushover { private String pushoverUrl; private String pushoverUrlTitle; private String pushoverTimestamp; + private String pushoverRetry; + private String pushoverExpire; + private String pushoverCallback; private Priority pushoverPriority; private Sound pushoverSound; @@ -64,6 +67,30 @@ public class JPushover { this.pushoverUser = user; return this; } + + /** + * Specifies how often (in seconds) the Pushover servers will send the same notification to the user. + * Only required if priority is set to emergency. + * + * @param retry Number of seconds + * @return JPushover instance + */ + public JPushover retry(String retry) { + this.pushoverRetry = retry; + return this; + } + + /** + * Specifies how many seconds your notification will continue to be retried for (every retry seconds). + * Only required if priority is set to emergency. + * + * @param expire Number of seconds + * @return JPushover instance + */ + public JPushover expire(String expire) { + this.pushoverExpire = expire; + return this; + } /** * Your message @@ -161,6 +188,20 @@ public class JPushover { this.pushoverSound = sound; return this; } + + /** + * Callback parameter may be supplied with a publicly-accessible URL that the + * Pushover servers will send a request to when the user has acknowledged your + * notification. + * Only required if priority is set to emergency. + * + * @param callback + * @return + */ + public JPushover callback(String callback) { + this.pushoverCallback = callback; + return this; + } /** * Send the message to pushover @@ -170,6 +211,11 @@ public class JPushover { Preconditions.checkNotNull(this.pushoverUser, "User is required"); Preconditions.checkNotNull(this.pushoverMessage, "Message is required"); + if (Priority.EMERGENCY.equals(this.pushoverPriority)) { + Preconditions.checkNotNull(this.pushoverRetry, "Retry is required on priority emergency"); + Preconditions.checkNotNull(this.pushoverExpire, "Expire is required on priority emergency"); + } + List params = Form.form() .add(Constants.TOKEN.get(), this.pushoverToken) .add(Constants.USER.get(), this.pushoverUser) @@ -177,12 +223,15 @@ public class JPushover { .add(Constants.DEVICE.get(), this.pushoverDevice) .add(Constants.TITLE.get(), this.pushoverTitle) .add(Constants.URL.get(), this.pushoverUrl) + .add(Constants.RETRY.get(), this.pushoverRetry) + .add(Constants.EXPIRE.get(), this.pushoverExpire) + .add(Constants.CALLBACK.get(), this.pushoverCallback) .add(Constants.URLTITLE.get(), this.pushoverUrlTitle) - .add(Constants.PRIORITY.get(), this.pushoverPriority.get()) + .add(Constants.PRIORITY.get(), (this.pushoverPriority == null) ? null : this.pushoverPriority.get()) .add(Constants.TIMESTAMP.get(), this.pushoverTimestamp) - .add(Constants.SOUND.get(), this.pushoverSound.get()) + .add(Constants.SOUND.get(), (this.pushoverSound == null) ? null : this.pushoverSound.get()) .build(); - + HttpResponse httpResponse = null; JPushoverResponse jPushoverResponse = null; try { diff --git a/src/main/java/de/svenkubiak/jpushover/enums/Constants.java b/src/main/java/de/svenkubiak/jpushover/enums/Constants.java index 10e7eeb..874391d 100644 --- a/src/main/java/de/svenkubiak/jpushover/enums/Constants.java +++ b/src/main/java/de/svenkubiak/jpushover/enums/Constants.java @@ -16,8 +16,11 @@ public enum Constants { PRIORITY("priority"), TIMESTAMP("timestamp"), URL("url"), - URLTITLE("urltitle"); - + URLTITLE("urltitle"), + CALLBACK("callback"), + EXPIRE("expire"), + RETRY("retry"); + private final String value; Constants (String value) {