#5 Fixed null url / urlTile
This commit is contained in:
@ -20,27 +20,25 @@ import de.svenkubiak.jpushover.utils.Urls;
|
|||||||
public class Message {
|
public class Message {
|
||||||
private static final String MESSAGE_URL = Urls.getMessageUrl();
|
private static final String MESSAGE_URL = Urls.getMessageUrl();
|
||||||
private static final String VALIDATION_URL = Urls.getValidationUrl();
|
private static final String VALIDATION_URL = Urls.getValidationUrl();
|
||||||
private Priority priority;
|
private Priority priority = Priority.NORMAL;
|
||||||
private Sound sound;
|
private Sound sound = Sound.PUSHOVER;
|
||||||
private String token;
|
private String token;
|
||||||
private String user;
|
private String user;
|
||||||
private String message;
|
private String message;
|
||||||
private String device;
|
private String device;
|
||||||
private String title;
|
private String title;
|
||||||
private String url;
|
private String url = "";
|
||||||
private String urlTitle;
|
private String urlTitle = "";
|
||||||
private String timestamp;
|
|
||||||
private String retry;
|
|
||||||
private String expire;
|
|
||||||
private String callback;
|
private String callback;
|
||||||
private String proxyHost;
|
private String proxyHost;
|
||||||
private int proxyPort;
|
private int proxyPort;
|
||||||
|
private int retry;
|
||||||
|
private int expire;
|
||||||
|
private int timestamp;
|
||||||
private boolean html;
|
private boolean html;
|
||||||
private boolean monospace;
|
private boolean monospace;
|
||||||
|
|
||||||
public Message() {
|
public Message() {
|
||||||
this.withSound(Sound.PUSHOVER);
|
|
||||||
this.withPriority(Priority.NORMAL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -77,7 +75,7 @@ public class Message {
|
|||||||
* @param retry Number of seconds
|
* @param retry Number of seconds
|
||||||
* @return Message instance
|
* @return Message instance
|
||||||
*/
|
*/
|
||||||
public final Message withRetry(final String retry) {
|
public final Message withRetry(final int retry) {
|
||||||
this.retry = retry;
|
this.retry = retry;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -89,7 +87,7 @@ public class Message {
|
|||||||
* @param expire Number of seconds
|
* @param expire Number of seconds
|
||||||
* @return Message instance
|
* @return Message instance
|
||||||
*/
|
*/
|
||||||
public final Message withExpire(final String expire) {
|
public final Message withExpire(final int expire) {
|
||||||
this.expire = expire;
|
this.expire = expire;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -188,7 +186,7 @@ public class Message {
|
|||||||
* @param timestamp The Unix timestamp
|
* @param timestamp The Unix timestamp
|
||||||
* @return Message instance
|
* @return Message instance
|
||||||
*/
|
*/
|
||||||
public final Message withTimestamp(final String timestamp) {
|
public final Message withTimestamp(final int timestamp) {
|
||||||
this.timestamp = timestamp;
|
this.timestamp = timestamp;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -293,27 +291,50 @@ public class Message {
|
|||||||
Objects.requireNonNull(this.message, "Message is required for a message");
|
Objects.requireNonNull(this.message, "Message is required for a message");
|
||||||
|
|
||||||
if (Priority.EMERGENCY.equals(this.priority)) {
|
if (Priority.EMERGENCY.equals(this.priority)) {
|
||||||
Objects.requireNonNull(this.retry, "Retry is required on priority emergency");
|
if (this.retry == 0) {
|
||||||
Objects.requireNonNull(this.expire, "Expire is required on priority emergency");
|
this.retry = 60;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.expire == 0) {
|
||||||
|
this.expire = 3600;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NavigableMap<String, String> body = new TreeMap<>();
|
NavigableMap<String, String> body = new TreeMap<>();
|
||||||
body.put(Param.TOKEN.toString(), this.token);
|
body.put(Param.TOKEN.toString(), this.token);
|
||||||
body.put(Param.USER.toString(), this.user);
|
body.put(Param.USER.toString(), this.user);
|
||||||
body.put(Param.MESSAGE.toString(), this.message);
|
body.put(Param.MESSAGE.toString(), this.message);
|
||||||
body.put(Param.DEVICE.toString(), this.device);
|
|
||||||
body.put(Param.TITLE.toString(), this.title);
|
|
||||||
body.put(Param.URL.toString(), this.url);
|
body.put(Param.URL.toString(), this.url);
|
||||||
body.put(Param.RETRY.toString(), this.retry);
|
|
||||||
body.put(Param.EXPIRE.toString(), this.expire);
|
|
||||||
body.put(Param.CALLBACK.toString(), this.callback);
|
|
||||||
body.put(Param.URL_TITLE.toString(), this.urlTitle);
|
body.put(Param.URL_TITLE.toString(), this.urlTitle);
|
||||||
body.put(Param.PRIORITY.toString(), this.priority.toString());
|
body.put(Param.PRIORITY.toString(), this.priority.toString());
|
||||||
body.put(Param.TIMESTAMP.toString(), this.timestamp);
|
|
||||||
body.put(Param.SOUND.toString(), this.sound.toString());
|
body.put(Param.SOUND.toString(), this.sound.toString());
|
||||||
body.put(Param.HTML.toString(), this.html ? "1" : "0");
|
body.put(Param.HTML.toString(), this.html ? "1" : "0");
|
||||||
body.put(Param.MONOSPACE.toString(), this.monospace ? "1" : "0");
|
body.put(Param.MONOSPACE.toString(), this.monospace ? "1" : "0");
|
||||||
|
|
||||||
|
if (this.device != null) {
|
||||||
|
body.put(Param.DEVICE.toString(), this.device);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.title != null) {
|
||||||
|
body.put(Param.TITLE.toString(), this.title);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.callback != null) {
|
||||||
|
body.put(Param.CALLBACK.toString(), this.callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.timestamp > 0) {
|
||||||
|
body.put(Param.TIMESTAMP.toString(), String.valueOf(this.timestamp));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.retry > 0) {
|
||||||
|
body.put(Param.RETRY.toString(), String.valueOf(this.retry));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.expire > 0) {
|
||||||
|
body.put(Param.EXPIRE.toString(), String.valueOf(this.expire));
|
||||||
|
}
|
||||||
|
|
||||||
return new PushoverRequest().push(MESSAGE_URL, body, this.proxyHost, this.proxyPort);
|
return new PushoverRequest().push(MESSAGE_URL, body, this.proxyHost, this.proxyPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -353,15 +374,15 @@ public class Message {
|
|||||||
return urlTitle;
|
return urlTitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTimestamp() {
|
public int getTimestamp() {
|
||||||
return timestamp;
|
return timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRetry() {
|
public int getRetry() {
|
||||||
return retry;
|
return retry;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getExpire() {
|
public int getExpire() {
|
||||||
return expire;
|
return expire;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ public class PushoverRequest {
|
|||||||
Objects.requireNonNull(body, "body can not be null");
|
Objects.requireNonNull(body, "body can not be null");
|
||||||
|
|
||||||
var httpResponse = getResponse(toJson(body), url, proxyHost, proxyPort);
|
var httpResponse = getResponse(toJson(body), url, proxyHost, proxyPort);
|
||||||
|
|
||||||
var jPushoverResponse = new PushoverResponse().isSuccessful(false);
|
var jPushoverResponse = new PushoverResponse().isSuccessful(false);
|
||||||
|
|
||||||
jPushoverResponse
|
jPushoverResponse
|
||||||
|
@ -95,19 +95,19 @@ public class MessageTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testConstruct() throws IOException, InterruptedException {
|
public void testConstruct() throws IOException, InterruptedException {
|
||||||
//given
|
//given
|
||||||
|
int proxyPort = 8080;
|
||||||
|
int timestamp = 0;
|
||||||
|
int expire = 0;
|
||||||
|
int retry = 0;
|
||||||
String callback = "callback";
|
String callback = "callback";
|
||||||
String device = "device";
|
String device = "device";
|
||||||
String expire = "expire";
|
|
||||||
String message = "message";
|
String message = "message";
|
||||||
String retry = "retry";
|
|
||||||
String user = "user";
|
String user = "user";
|
||||||
String urlTitle = "urlTitle";
|
String urlTitle = "urlTitle";
|
||||||
String timestamp = "timestamp";
|
|
||||||
String proxyHost = "proxyhost";
|
String proxyHost = "proxyhost";
|
||||||
String title = "tile";
|
String title = "tile";
|
||||||
String token = "token";
|
String token = "token";
|
||||||
String url = "https://www.url.url";
|
String url = "https://www.url.url";
|
||||||
int proxyPort = 8080;
|
|
||||||
Priority priority = Priority.HIGH;
|
Priority priority = Priority.HIGH;
|
||||||
Sound sound = Sound.BUGLE;
|
Sound sound = Sound.BUGLE;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user