sonar refactorings

This commit is contained in:
Sven Kubiak 2015-01-07 20:11:23 +01:00
parent a9b8eea2e6
commit c9b7f0ade2
5 changed files with 48 additions and 51 deletions

View File

@ -21,16 +21,16 @@ import de.svenkubiak.jpushover.enums.Sound;
public class JPushover { public class JPushover {
private static final Logger LOG = LoggerFactory.getLogger(JPushover.class); private static final Logger LOG = LoggerFactory.getLogger(JPushover.class);
private String token; private String pushoverToken;
private String user; private String pushoverUser;
private String message; private String pushoverMessage;
private String device; private String pushoverDevice;
private String title; private String pushoverTitle;
private String url; private String pushoverUrl;
private String urlTitle; private String pushoverUrlTitle;
private String timestamp; private String pushoverTimestamp;
private Priority priority; private Priority pushoverPriority;
private Sound sound; private Sound pushoverSound;
public JPushover(){ public JPushover(){
} }
@ -43,7 +43,7 @@ public class JPushover {
* @return JPushover instance * @return JPushover instance
*/ */
public JPushover token(String token) { public JPushover token(String token) {
this.token = token; this.pushoverToken = token;
return this; return this;
} }
@ -56,7 +56,7 @@ public class JPushover {
* @return JPushover instance * @return JPushover instance
*/ */
public JPushover user(String user) { public JPushover user(String user) {
this.user = user; this.pushoverUser = user;
return this; return this;
} }
@ -68,7 +68,7 @@ public class JPushover {
* @return JPushover instance * @return JPushover instance
*/ */
public JPushover message(String message) { public JPushover message(String message) {
this.message = message; this.pushoverMessage = message;
return this; return this;
} }
@ -81,7 +81,7 @@ public class JPushover {
* @return JPushover instance * @return JPushover instance
*/ */
public JPushover device(String device) { public JPushover device(String device) {
this.device = device; this.pushoverDevice = device;
return this; return this;
} }
@ -93,7 +93,7 @@ public class JPushover {
* @return JPushover instance * @return JPushover instance
*/ */
public JPushover title(String title) { public JPushover title(String title) {
this.title = title; this.pushoverTitle = title;
return this; return this;
} }
@ -105,7 +105,7 @@ public class JPushover {
* @return JPushover instance * @return JPushover instance
*/ */
public JPushover url(String url) { public JPushover url(String url) {
this.url = url; this.pushoverUrl = url;
return this; return this;
} }
@ -116,7 +116,7 @@ public class JPushover {
* @return JPushover instance * @return JPushover instance
*/ */
public JPushover urlTitle(String urlTitle) { public JPushover urlTitle(String urlTitle) {
this.urlTitle = urlTitle; this.pushoverUrlTitle = urlTitle;
return this; return this;
} }
@ -128,22 +128,19 @@ public class JPushover {
* @return JPushover instance * @return JPushover instance
*/ */
public JPushover timestamp(String timestamp) { public JPushover timestamp(String timestamp) {
this.timestamp = timestamp; this.pushoverTimestamp = timestamp;
return this; return this;
} }
/** /**
* Send as LOWESET to generate no notification/alert, * Priority of the message based on the @see <a href="https://pushover.net/api#priority">documentation</a>
* LOW to always send as a quiet notification,
* NORMAL to display as high-priority and bypass the user's quiet hours,
* or emergence to also require confirmation from the user
* (optional) * (optional)
* *
* @param priority * @param priority
* @return JPushover instance * @return JPushover instance
*/ */
public JPushover priority(Priority priority) { public JPushover priority(Priority priority) {
this.priority = priority; this.pushoverPriority = priority;
return this; return this;
} }
@ -156,7 +153,7 @@ public class JPushover {
* @return JPushover instance * @return JPushover instance
*/ */
public JPushover sound(Sound sound) { public JPushover sound(Sound sound) {
this.sound = sound; this.pushoverSound = sound;
return this; return this;
} }
@ -164,27 +161,27 @@ public class JPushover {
* Send the message to pushover * Send the message to pushover
*/ */
public JPushoverResponse push() { public JPushoverResponse push() {
Preconditions.checkNotNull(this.token, "Token is required"); Preconditions.checkNotNull(this.pushoverToken, "Token is required");
Preconditions.checkNotNull(this.user, "User is required"); Preconditions.checkNotNull(this.pushoverUser, "User is required");
Preconditions.checkNotNull(this.message, "Message is required"); Preconditions.checkNotNull(this.pushoverMessage, "Message is required");
List<NameValuePair> params = Form.form() List<NameValuePair> params = Form.form()
.add(Constants.TOKEN.value(), this.token) .add(Constants.TOKEN.get(), this.pushoverToken)
.add(Constants.USER.value(), this.user) .add(Constants.USER.get(), this.pushoverUser)
.add(Constants.MESSAGE.value(), this.message) .add(Constants.MESSAGE.get(), this.pushoverMessage)
.add(Constants.DEVICE.value(), this.device) .add(Constants.DEVICE.get(), this.pushoverDevice)
.add(Constants.TITLE.value(), this.title) .add(Constants.TITLE.get(), this.pushoverTitle)
.add(Constants.URL.value(), this.url) .add(Constants.URL.get(), this.pushoverUrl)
.add(Constants.URLTITLE.value(), this.urlTitle) .add(Constants.URLTITLE.get(), this.pushoverUrlTitle)
.add(Constants.PRIORITY.value(), this.priority.value()) .add(Constants.PRIORITY.get(), this.pushoverPriority.get())
.add(Constants.TIMESTAMP.value(), this.timestamp) .add(Constants.TIMESTAMP.get(), this.pushoverTimestamp)
.add(Constants.SOUND.value(), this.sound.value()) .add(Constants.SOUND.get(), this.pushoverSound.get())
.build(); .build();
HttpResponse httpResponse = null; HttpResponse httpResponse = null;
JPushoverResponse jPushoverResponse = null; JPushoverResponse jPushoverResponse = null;
try { try {
httpResponse = Request.Post(Constants.PUSHOVER_URL.value()).bodyForm(params, Consts.UTF_8).execute().returnResponse(); httpResponse = Request.Post(Constants.PUSHOVER_URL.get()).bodyForm(params, Consts.UTF_8).execute().returnResponse();
if (httpResponse != null) { if (httpResponse != null) {
int status = httpResponse.getStatusLine().getStatusCode(); int status = httpResponse.getStatusLine().getStatusCode();

View File

@ -1,25 +1,25 @@
package de.svenkubiak.jpushover; package de.svenkubiak.jpushover;
public class JPushoverResponse { public class JPushoverResponse {
private String response; private String pushoverResponse;
private int httpStatus; private int pushoverHttpStatus;
private boolean successful; private boolean pushoverSuccessful;
public JPushoverResponse(){ public JPushoverResponse(){
} }
public JPushoverResponse response(String response) { public JPushoverResponse response(String response) {
this.response = response; this.pushoverResponse = response;
return this; return this;
} }
public JPushoverResponse httpStatus(int httpStatus) { public JPushoverResponse httpStatus(int httpStatus) {
this.httpStatus = httpStatus; this.pushoverHttpStatus = httpStatus;
return this; return this;
} }
public JPushoverResponse isSuccessful(boolean successful) { public JPushoverResponse isSuccessful(boolean successful) {
this.successful = successful; this.pushoverSuccessful = successful;
return this; return this;
} }
@ -28,7 +28,7 @@ public class JPushoverResponse {
* @return String * @return String
*/ */
public String getResponse() { public String getResponse() {
return response; return pushoverResponse;
} }
/** /**
@ -36,7 +36,7 @@ public class JPushoverResponse {
* @return int * @return int
*/ */
public int getHttpStatus() { public int getHttpStatus() {
return httpStatus; return pushoverHttpStatus;
} }
/** /**
@ -44,6 +44,6 @@ public class JPushoverResponse {
* @return boolen * @return boolen
*/ */
public boolean isSuccessful() { public boolean isSuccessful() {
return successful; return pushoverSuccessful;
} }
} }

View File

@ -11,7 +11,7 @@ public enum Constants {
PRIORITY("priority"), PRIORITY("priority"),
TIMESTAMP("timestamp"), TIMESTAMP("timestamp"),
URL("url"), URL("url"),
URLTITLE("urltile"); URLTITLE("urltitle");
private final String value; private final String value;
@ -19,7 +19,7 @@ public enum Constants {
this.value = value; this.value = value;
} }
public String value() { public String get() {
return this.value; return this.value;
} }
} }

View File

@ -13,7 +13,7 @@ public enum Priority {
this.value = value; this.value = value;
} }
public String value() { public String get() {
return this.value; return this.value;
} }
} }

View File

@ -30,7 +30,7 @@ public enum Sound {
this.value = value; this.value = value;
} }
public String value() { public String get() {
return this.value; return this.value;
} }
} }