diff --git a/src/main/java/com/simplesteph/kafka/GitHubAPIHttpClient.java b/src/main/java/com/simplesteph/kafka/GitHubAPIHttpClient.java index 3e17a09..79bcc64 100644 --- a/src/main/java/com/simplesteph/kafka/GitHubAPIHttpClient.java +++ b/src/main/java/com/simplesteph/kafka/GitHubAPIHttpClient.java @@ -27,6 +27,10 @@ public class GitHubAPIHttpClient { GitHubSourceConnectorConfig config; + public static final String X_RATELIMIT_LIMIT_HEADER="X-Ratelimit-Limit"; + public static final String X_RATELIMIT_REMAINING_HEADER="X-Ratelimit-Remaining"; + public static final String X_RATELIMIT_RESET_HEADER="X-Ratelimit-Reset"; + public GitHubAPIHttpClient(GitHubSourceConnectorConfig config){ this.config = config; } @@ -39,9 +43,9 @@ protected JSONArray getNextIssues(Integer page, Instant since) throws Interrupte // deal with headers in any case Headers headers = jsonResponse.getHeaders(); - XRateLimit = Integer.valueOf(headers.getFirst("X-RateLimit-Limit")); - XRateRemaining = Integer.valueOf(headers.getFirst("X-RateLimit-Remaining")); - XRateReset = Integer.valueOf(headers.getFirst("X-RateLimit-Reset")); + XRateLimit = Integer.valueOf(headers.getFirst(X_RATELIMIT_LIMIT_HEADER)); + XRateRemaining = Integer.valueOf(headers.getFirst(X_RATELIMIT_REMAINING_HEADER)); + XRateReset = Integer.valueOf(headers.getFirst(X_RATELIMIT_RESET_HEADER)); switch (jsonResponse.getStatus()){ case 200: return jsonResponse.getBody().getArray(); @@ -108,4 +112,4 @@ public void sleepIfNeed() throws InterruptedException { sleep(); } } -} \ No newline at end of file +} diff --git a/src/test/java/com/simplesteph/kafka/GitHubSourceTaskTest.java b/src/test/java/com/simplesteph/kafka/GitHubSourceTaskTest.java index fca0cb0..ee15344 100644 --- a/src/test/java/com/simplesteph/kafka/GitHubSourceTaskTest.java +++ b/src/test/java/com/simplesteph/kafka/GitHubSourceTaskTest.java @@ -12,6 +12,7 @@ import java.util.Map; import java.util.Set; +import static com.simplesteph.kafka.GitHubAPIHttpClient.*; import static com.simplesteph.kafka.GitHubSourceConnectorConfig.*; import static org.junit.Assert.*; @@ -43,10 +44,9 @@ public void test() throws UnirestException { if (httpResponse.getStatus() != 403) { assertEquals(200, httpResponse.getStatus()); Set headers = httpResponse.getHeaders().keySet(); - assertTrue(headers.contains("ETag")); - assertTrue(headers.contains("X-RateLimit-Limit")); - assertTrue(headers.contains("X-RateLimit-Remaining")); - assertTrue(headers.contains("X-RateLimit-Reset")); + assertTrue(headers.contains(X_RATELIMIT_LIMIT_HEADER)); + assertTrue(headers.contains(X_RATELIMIT_REMAINING_HEADER)); + assertTrue(headers.contains(X_RATELIMIT_RESET_HEADER)); assertEquals(batchSize.intValue(), httpResponse.getBody().getArray().length()); JSONObject jsonObject = (JSONObject) httpResponse.getBody().getArray().get(0); Issue issue = Issue.fromJson(jsonObject); @@ -55,4 +55,4 @@ public void test() throws UnirestException { assertEquals(2072, issue.getNumber().intValue()); } } -} \ No newline at end of file +}