diff --git a/src/main/java/de/svenkubiak/jpushover/apis/Glance.java b/src/main/java/de/svenkubiak/jpushover/apis/Glance.java index 33c5d07..6f477ec 100644 --- a/src/main/java/de/svenkubiak/jpushover/apis/Glance.java +++ b/src/main/java/de/svenkubiak/jpushover/apis/Glance.java @@ -24,9 +24,9 @@ public class Glance { private String title; private String text; private String subtext; + private String proxyHost; private int count; private int percent; - private String proxyHost; private int proxyPort; public Glance withToken(String token) { @@ -86,7 +86,7 @@ public class Glance { */ public Glance withSubtext(String subtext) { Objects.requireNonNull(subtext, "subtext can not be null"); - Validate.checkArgument(subtext.length() <= 100, "subtext must not exceed a length of 100 characters"); + Validate.checkArgument(subtext.length() <= 100, "Subtext must not exceed a length of 100 characters"); this.subtext = subtext; return this; diff --git a/src/main/java/de/svenkubiak/jpushover/apis/Message.java b/src/main/java/de/svenkubiak/jpushover/apis/Message.java index 01f5d73..d394636 100644 --- a/src/main/java/de/svenkubiak/jpushover/apis/Message.java +++ b/src/main/java/de/svenkubiak/jpushover/apis/Message.java @@ -11,6 +11,7 @@ import de.svenkubiak.jpushover.enums.Sound; import de.svenkubiak.jpushover.http.PushoverRequest; import de.svenkubiak.jpushover.http.PushoverResponse; import de.svenkubiak.jpushover.utils.Urls; +import de.svenkubiak.jpushover.utils.Validate; /** * @@ -71,6 +72,7 @@ public class Message { /** * Specifies how often (in seconds) the Pushover servers will send the same notification to the user. * Only required if priority is set to emergency. + * (optional) * * @param retry Number of seconds * @return Message instance @@ -83,6 +85,7 @@ public class Message { /** * Specifies how many seconds your notification will continue to be retried for (every retry seconds). * Only required if priority is set to emergency. + * (optional) * * @param expire Number of seconds * @return Message instance @@ -170,6 +173,7 @@ public class Message { /** * A title for your supplementary URL, otherwise just the URL is shown + * (optional) * * @param urlTitle The url title * @return Message instance @@ -182,6 +186,7 @@ public class Message { /** * A Unix timestamp of your message's date and time to display to the user, * rather than the time your message is received by our API + * (optional) * * @param timestamp The Unix timestamp * @return Message instance @@ -220,7 +225,8 @@ public class Message { * 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. + * Only used if priority is set to emergency. + * (optional) * * @param callback The callback URL * @return Message instance @@ -231,7 +237,7 @@ public class Message { } /** - * Uses the given proxy for HTTP requests + * Uses a given proxy for the HTTP requests to Pushover * * @param proxyHost The host that should be used for the Proxy * @param proxyPort The port that should be used for the Proxy @@ -289,6 +295,7 @@ public class Message { Objects.requireNonNull(this.token, "Token is required for a message"); Objects.requireNonNull(this.user, "User is required for a message"); Objects.requireNonNull(this.message, "Message is required for a message"); + Validate.checkArgument(this.message.length() <= 1024, "Message can not exceed more than 1024 characters"); if (Priority.EMERGENCY.equals(this.priority)) { if (this.retry == 0) { @@ -300,20 +307,16 @@ public class Message { } } - if (this.message.length() > 1024) { - this.message.substring(0, 1023); + if (this.title != null) { + Validate.checkArgument(this.title.length() <= 250, "Title can not exceed more than 250 characters"); } - if (this.title != null && this.title.length() > 250) { - this.title.substring(0, 249); + if (this.url != null) { + Validate.checkArgument(this.url.length() <= 512, "URL can not exceed more than 512 characters"); } - if (this.url != null && this.url.length() > 512) { - this.url.substring(0, 511); - } - - if (this.urlTitle != null && this.urlTitle.length() > 100) { - this.urlTitle.substring(0, 99); + if (this.urlTitle != null) { + Validate.checkArgument(this.urlTitle.length() <= 100, "URL Title can not exceed more than 100 characters"); } NavigableMap body = new TreeMap<>(); diff --git a/src/main/java/de/svenkubiak/jpushover/enums/Priority.java b/src/main/java/de/svenkubiak/jpushover/enums/Priority.java index 86faf5d..6936344 100644 --- a/src/main/java/de/svenkubiak/jpushover/enums/Priority.java +++ b/src/main/java/de/svenkubiak/jpushover/enums/Priority.java @@ -6,11 +6,11 @@ package de.svenkubiak.jpushover.enums; * */ public enum Priority { - LOWEST("-2"), - LOW("-1"), - NORMAL("0"), + EMERGENCY("2"), HIGH("1"), - EMERGENCY("2"); + LOW("-1"), + LOWEST("-2"), + NORMAL("0"); private final String value; diff --git a/src/main/java/de/svenkubiak/jpushover/enums/Sound.java b/src/main/java/de/svenkubiak/jpushover/enums/Sound.java index 0e8ed6d..350901d 100644 --- a/src/main/java/de/svenkubiak/jpushover/enums/Sound.java +++ b/src/main/java/de/svenkubiak/jpushover/enums/Sound.java @@ -39,4 +39,4 @@ public enum Sound { public String toString() { return this.value; } -} +} \ No newline at end of file diff --git a/src/main/java/de/svenkubiak/jpushover/utils/Urls.java b/src/main/java/de/svenkubiak/jpushover/utils/Urls.java index 85445e4..517333b 100644 --- a/src/main/java/de/svenkubiak/jpushover/utils/Urls.java +++ b/src/main/java/de/svenkubiak/jpushover/utils/Urls.java @@ -7,29 +7,28 @@ package de.svenkubiak.jpushover.utils; */ public class Urls { public static String getGlanceUrl() { - String mode = System.getProperty("mode"); - if (("test").equals(mode)) { + if (isTest()) { return "http://127.0.0.1:8080/1/glances.json"; } - return "https://api.pushover.net/1/glances.json"; } public static String getMessageUrl() { - String mode = System.getProperty("mode"); - if (("test").equals(mode)) { + if (isTest()) { return "http://127.0.0.1:8080/1/messages.json"; } - return "https://api.pushover.net/1/messages.json"; } public static String getValidationUrl() { - String mode = System.getProperty("mode"); - if (("test").equals(mode)) { + if (isTest()) { return "http://127.0.0.1:8080/1/users/validate.json"; } - return "https://api.pushover.net/1/users/validate.json"; } + + private static boolean isTest() { + String mode = System.getProperty("mode"); + return ("test").equals(mode); + } } \ No newline at end of file