Refactorings
This commit is contained in:
parent
e57c945c3a
commit
61b6744d17
@ -24,9 +24,9 @@ public class Glance {
|
|||||||
private String title;
|
private String title;
|
||||||
private String text;
|
private String text;
|
||||||
private String subtext;
|
private String subtext;
|
||||||
|
private String proxyHost;
|
||||||
private int count;
|
private int count;
|
||||||
private int percent;
|
private int percent;
|
||||||
private String proxyHost;
|
|
||||||
private int proxyPort;
|
private int proxyPort;
|
||||||
|
|
||||||
public Glance withToken(String token) {
|
public Glance withToken(String token) {
|
||||||
@ -86,7 +86,7 @@ public class Glance {
|
|||||||
*/
|
*/
|
||||||
public Glance withSubtext(String subtext) {
|
public Glance withSubtext(String subtext) {
|
||||||
Objects.requireNonNull(subtext, "subtext can not be null");
|
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;
|
this.subtext = subtext;
|
||||||
return this;
|
return this;
|
||||||
|
@ -11,6 +11,7 @@ import de.svenkubiak.jpushover.enums.Sound;
|
|||||||
import de.svenkubiak.jpushover.http.PushoverRequest;
|
import de.svenkubiak.jpushover.http.PushoverRequest;
|
||||||
import de.svenkubiak.jpushover.http.PushoverResponse;
|
import de.svenkubiak.jpushover.http.PushoverResponse;
|
||||||
import de.svenkubiak.jpushover.utils.Urls;
|
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.
|
* Specifies how often (in seconds) the Pushover servers will send the same notification to the user.
|
||||||
* Only required if priority is set to emergency.
|
* Only required if priority is set to emergency.
|
||||||
|
* (optional)
|
||||||
*
|
*
|
||||||
* @param retry Number of seconds
|
* @param retry Number of seconds
|
||||||
* @return Message instance
|
* @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).
|
* Specifies how many seconds your notification will continue to be retried for (every retry seconds).
|
||||||
* Only required if priority is set to emergency.
|
* Only required if priority is set to emergency.
|
||||||
|
* (optional)
|
||||||
*
|
*
|
||||||
* @param expire Number of seconds
|
* @param expire Number of seconds
|
||||||
* @return Message instance
|
* @return Message instance
|
||||||
@ -170,6 +173,7 @@ public class Message {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A title for your supplementary URL, otherwise just the URL is shown
|
* A title for your supplementary URL, otherwise just the URL is shown
|
||||||
|
* (optional)
|
||||||
*
|
*
|
||||||
* @param urlTitle The url title
|
* @param urlTitle The url title
|
||||||
* @return Message instance
|
* @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,
|
* 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
|
* rather than the time your message is received by our API
|
||||||
|
* (optional)
|
||||||
*
|
*
|
||||||
* @param timestamp The Unix timestamp
|
* @param timestamp The Unix timestamp
|
||||||
* @return Message instance
|
* @return Message instance
|
||||||
@ -220,7 +225,8 @@ public class Message {
|
|||||||
* Callback parameter may be supplied with a publicly-accessible URL that the
|
* 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
|
* pushover servers will send a request to when the user has acknowledged your
|
||||||
* notification.
|
* notification.
|
||||||
* Only required if priority is set to emergency.
|
* Only used if priority is set to emergency.
|
||||||
|
* (optional)
|
||||||
*
|
*
|
||||||
* @param callback The callback URL
|
* @param callback The callback URL
|
||||||
* @return Message instance
|
* @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 proxyHost The host that should be used for the Proxy
|
||||||
* @param proxyPort The port 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.token, "Token is required for a message");
|
||||||
Objects.requireNonNull(this.user, "User 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");
|
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 (Priority.EMERGENCY.equals(this.priority)) {
|
||||||
if (this.retry == 0) {
|
if (this.retry == 0) {
|
||||||
@ -300,20 +307,16 @@ public class Message {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.message.length() > 1024) {
|
if (this.title != null) {
|
||||||
this.message.substring(0, 1023);
|
Validate.checkArgument(this.title.length() <= 250, "Title can not exceed more than 250 characters");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.title != null && this.title.length() > 250) {
|
if (this.url != null) {
|
||||||
this.title.substring(0, 249);
|
Validate.checkArgument(this.url.length() <= 512, "URL can not exceed more than 512 characters");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.url != null && this.url.length() > 512) {
|
if (this.urlTitle != null) {
|
||||||
this.url.substring(0, 511);
|
Validate.checkArgument(this.urlTitle.length() <= 100, "URL Title can not exceed more than 100 characters");
|
||||||
}
|
|
||||||
|
|
||||||
if (this.urlTitle != null && this.urlTitle.length() > 100) {
|
|
||||||
this.urlTitle.substring(0, 99);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NavigableMap<String, String> body = new TreeMap<>();
|
NavigableMap<String, String> body = new TreeMap<>();
|
||||||
|
@ -6,11 +6,11 @@ package de.svenkubiak.jpushover.enums;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public enum Priority {
|
public enum Priority {
|
||||||
LOWEST("-2"),
|
EMERGENCY("2"),
|
||||||
LOW("-1"),
|
|
||||||
NORMAL("0"),
|
|
||||||
HIGH("1"),
|
HIGH("1"),
|
||||||
EMERGENCY("2");
|
LOW("-1"),
|
||||||
|
LOWEST("-2"),
|
||||||
|
NORMAL("0");
|
||||||
|
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
||||||
|
@ -39,4 +39,4 @@ public enum Sound {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,29 +7,28 @@ package de.svenkubiak.jpushover.utils;
|
|||||||
*/
|
*/
|
||||||
public class Urls {
|
public class Urls {
|
||||||
public static String getGlanceUrl() {
|
public static String getGlanceUrl() {
|
||||||
String mode = System.getProperty("mode");
|
if (isTest()) {
|
||||||
if (("test").equals(mode)) {
|
|
||||||
return "http://127.0.0.1:8080/1/glances.json";
|
return "http://127.0.0.1:8080/1/glances.json";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "https://api.pushover.net/1/glances.json";
|
return "https://api.pushover.net/1/glances.json";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getMessageUrl() {
|
public static String getMessageUrl() {
|
||||||
String mode = System.getProperty("mode");
|
if (isTest()) {
|
||||||
if (("test").equals(mode)) {
|
|
||||||
return "http://127.0.0.1:8080/1/messages.json";
|
return "http://127.0.0.1:8080/1/messages.json";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "https://api.pushover.net/1/messages.json";
|
return "https://api.pushover.net/1/messages.json";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getValidationUrl() {
|
public static String getValidationUrl() {
|
||||||
String mode = System.getProperty("mode");
|
if (isTest()) {
|
||||||
if (("test").equals(mode)) {
|
|
||||||
return "http://127.0.0.1:8080/1/users/validate.json";
|
return "http://127.0.0.1:8080/1/users/validate.json";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "https://api.pushover.net/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);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user