Added rate limit information
This commit is contained in:
parent
b22d64648b
commit
ff4bc44f3e
2
pom.xml
2
pom.xml
@ -191,7 +191,7 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.10</version>
|
||||
<version>3.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -11,6 +11,7 @@ import java.time.Duration;
|
||||
import java.util.Map;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.Objects;
|
||||
import java.util.OptionalLong;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -29,11 +30,18 @@ public class PushoverRequest {
|
||||
jPushoverResponse
|
||||
.httpStatus(httpResponse.statusCode())
|
||||
.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;
|
||||
}
|
||||
|
||||
|
||||
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 {
|
||||
var httpRequest = HttpRequest.newBuilder()
|
||||
.uri(URI.create(url))
|
||||
|
@ -7,9 +7,12 @@ package de.svenkubiak.jpushover.http;
|
||||
*/
|
||||
public class PushoverResponse {
|
||||
private String pushoverResponse;
|
||||
private int pushoverHttpStatus;
|
||||
private boolean pushoverSuccessful;
|
||||
|
||||
private int pushoverHttpStatus;
|
||||
private long pushoverLimit;
|
||||
private long pushoverRemaining;
|
||||
private long pushoverReset;
|
||||
|
||||
public PushoverResponse response(String response) {
|
||||
this.pushoverResponse = response;
|
||||
return this;
|
||||
@ -24,6 +27,21 @@ public class PushoverResponse {
|
||||
this.pushoverSuccessful = successful;
|
||||
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
|
||||
@ -45,4 +63,25 @@ public class PushoverResponse {
|
||||
public boolean isSuccessful() {
|
||||
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