Minor refactoring
This commit is contained in:
parent
0df3313722
commit
ad5612366d
@ -1,4 +1,4 @@
|
|||||||
image: meridianbancorg/maven-jdk11
|
image: adoptopenjdk/maven-openjdk11
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- test
|
- test
|
||||||
|
11
pom.xml
11
pom.xml
@ -200,17 +200,6 @@
|
|||||||
<artifactId>minimal-json</artifactId>
|
<artifactId>minimal-json</artifactId>
|
||||||
<version>0.9.5</version>
|
<version>0.9.5</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.commons</groupId>
|
|
||||||
<artifactId>commons-lang3</artifactId>
|
|
||||||
<version>3.8.1</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>4.12</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
<snapshotRepository>
|
<snapshotRepository>
|
||||||
|
@ -11,13 +11,14 @@ import java.time.Duration;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import com.eclipsesource.json.Json;
|
import com.eclipsesource.json.Json;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import de.svenkubiak.jpushover.enums.Constants;
|
import de.svenkubiak.jpushover.enums.Constants;
|
||||||
import de.svenkubiak.jpushover.enums.Priority;
|
import de.svenkubiak.jpushover.enums.Priority;
|
||||||
import de.svenkubiak.jpushover.enums.Sound;
|
import de.svenkubiak.jpushover.enums.Sound;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
|
* Minimalist convenient class for sending messages to Pushover
|
||||||
*
|
*
|
||||||
* @author svenkubiak
|
* @author svenkubiak
|
||||||
*
|
*
|
||||||
@ -265,7 +266,7 @@ public class JPushover {
|
|||||||
var valid = false;
|
var valid = false;
|
||||||
if (httpResponse.statusCode() == HTTP_OK) {
|
if (httpResponse.statusCode() == HTTP_OK) {
|
||||||
var response = httpResponse.body();
|
var response = httpResponse.body();
|
||||||
if (StringUtils.isNotBlank(response) && response.contains("\"status\":1")) {
|
if (response != null && response.contains("\"status\":1")) {
|
||||||
valid = true;
|
valid = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -278,8 +279,8 @@ public class JPushover {
|
|||||||
*
|
*
|
||||||
* @return JPushoverResponse instance
|
* @return JPushoverResponse instance
|
||||||
*
|
*
|
||||||
* @throws IOException if validation fails
|
* @throws IOException if sending the message fails
|
||||||
* @throws InterruptedException if validation fails
|
* @throws InterruptedException if sending the message fails
|
||||||
*/
|
*/
|
||||||
public final JPushoverResponse push() throws IOException, InterruptedException {
|
public final JPushoverResponse push() throws IOException, InterruptedException {
|
||||||
Objects.requireNonNull(this.pushoverToken, "Token is required for a message");
|
Objects.requireNonNull(this.pushoverToken, "Token is required for a message");
|
||||||
@ -309,7 +310,7 @@ public class JPushover {
|
|||||||
|
|
||||||
var httpResponse = getResponse(body.toString(), Constants.MESSAGES_URL.toString());
|
var httpResponse = getResponse(body.toString(), Constants.MESSAGES_URL.toString());
|
||||||
|
|
||||||
JPushoverResponse jPushoverResponse = new JPushoverResponse().isSuccessful(false);
|
var jPushoverResponse = new JPushoverResponse().isSuccessful(false);
|
||||||
jPushoverResponse
|
jPushoverResponse
|
||||||
.httpStatus(httpResponse.statusCode())
|
.httpStatus(httpResponse.statusCode())
|
||||||
.response(httpResponse.body())
|
.response(httpResponse.body())
|
||||||
@ -319,16 +320,16 @@ public class JPushover {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private HttpResponse<String> getResponse(String body, String url) throws IOException, InterruptedException {
|
private HttpResponse<String> getResponse(String body, String url) throws IOException, InterruptedException {
|
||||||
HttpRequest httpRequest = HttpRequest.newBuilder()
|
var httpRequest = HttpRequest.newBuilder()
|
||||||
.uri(URI.create(url))
|
.uri(URI.create(url))
|
||||||
.timeout(Duration.ofSeconds(5))
|
.timeout(Duration.ofSeconds(5))
|
||||||
.header("Content-Type", "application/json")
|
.header("Content-Type", "application/json")
|
||||||
.POST(HttpRequest.BodyPublishers.ofString(body))
|
.POST(HttpRequest.BodyPublishers.ofString(body))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
HttpClient.Builder httpClientBuilder = HttpClient.newBuilder();
|
var httpClientBuilder = HttpClient.newBuilder();
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(this.proxyHost) && this.proxyPort > 0) {
|
if (this.proxyHost != null && this.proxyPort > 0) {
|
||||||
httpClientBuilder.proxy(ProxySelector.of(new InetSocketAddress(this.proxyHost, this.proxyPort)));
|
httpClientBuilder.proxy(ProxySelector.of(new InetSocketAddress(this.proxyHost, this.proxyPort)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user