Added rate limit information
This commit is contained in:
parent
b22d64648b
commit
ff4bc44f3e
2
pom.xml
2
pom.xml
@ -191,7 +191,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
<version>3.10</version>
|
<version>3.11</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -11,6 +11,7 @@ import java.time.Duration;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NavigableMap;
|
import java.util.NavigableMap;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.OptionalLong;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -29,11 +30,18 @@ public class PushoverRequest {
|
|||||||
jPushoverResponse
|
jPushoverResponse
|
||||||
.httpStatus(httpResponse.statusCode())
|
.httpStatus(httpResponse.statusCode())
|
||||||
.response(httpResponse.body())
|
.response(httpResponse.body())
|
||||||
.isSuccessful((httpResponse.statusCode() == 200) ? true : false);
|
.isSuccessful((httpResponse.statusCode() == 200) ? true : false)
|
||||||
|
.limit(getHeaderValue(httpResponse, "X-Limit-App-Limit").orElse(0))
|
||||||
|
.remaining(getHeaderValue(httpResponse, "X-Limit-App-Remaining").orElse(0))
|
||||||
|
.reset(getHeaderValue(httpResponse, "X-Limit-App-Reset").orElse(0));
|
||||||
|
|
||||||
return jPushoverResponse;
|
return jPushoverResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private OptionalLong getHeaderValue(HttpResponse<String> httpResponse, String header) {
|
||||||
|
return httpResponse.headers().firstValueAsLong(header);
|
||||||
|
}
|
||||||
|
|
||||||
private HttpResponse<String> getResponse(String body, String url, String proxyHost, int proxyPort) throws IOException, InterruptedException {
|
private HttpResponse<String> getResponse(String body, String url, String proxyHost, int proxyPort) throws IOException, InterruptedException {
|
||||||
var httpRequest = HttpRequest.newBuilder()
|
var httpRequest = HttpRequest.newBuilder()
|
||||||
.uri(URI.create(url))
|
.uri(URI.create(url))
|
||||||
|
@ -7,8 +7,11 @@ package de.svenkubiak.jpushover.http;
|
|||||||
*/
|
*/
|
||||||
public class PushoverResponse {
|
public class PushoverResponse {
|
||||||
private String pushoverResponse;
|
private String pushoverResponse;
|
||||||
private int pushoverHttpStatus;
|
|
||||||
private boolean pushoverSuccessful;
|
private boolean pushoverSuccessful;
|
||||||
|
private int pushoverHttpStatus;
|
||||||
|
private long pushoverLimit;
|
||||||
|
private long pushoverRemaining;
|
||||||
|
private long pushoverReset;
|
||||||
|
|
||||||
public PushoverResponse response(String response) {
|
public PushoverResponse response(String response) {
|
||||||
this.pushoverResponse = response;
|
this.pushoverResponse = response;
|
||||||
@ -25,6 +28,21 @@ public class PushoverResponse {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PushoverResponse limit(long limit) {
|
||||||
|
this.pushoverLimit = limit;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PushoverResponse remaining(long remaining) {
|
||||||
|
this.pushoverRemaining = remaining;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PushoverResponse reset(long reset) {
|
||||||
|
this.pushoverReset = reset;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The pushover response
|
* @return The pushover response
|
||||||
*/
|
*/
|
||||||
@ -45,4 +63,25 @@ public class PushoverResponse {
|
|||||||
public boolean isSuccessful() {
|
public boolean isSuccessful() {
|
||||||
return pushoverSuccessful;
|
return pushoverSuccessful;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The API rate limit
|
||||||
|
*/
|
||||||
|
public long getLimit() {
|
||||||
|
return pushoverLimit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The remaining allowed API requests
|
||||||
|
*/
|
||||||
|
public long getRemaining() {
|
||||||
|
return pushoverRemaining;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The API rate limit reset timestamp
|
||||||
|
*/
|
||||||
|
public long getReset() {
|
||||||
|
return pushoverReset;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user