Skip to content

Commit

Permalink
Merge pull request #14 from kieronedwards/issue-13
Browse files Browse the repository at this point in the history
issue-13: corrected header values as seem to have changed on github
  • Loading branch information
simplesteph authored May 3, 2020
2 parents 5cfd9c1 + eb4be70 commit 348dd80
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
12 changes: 8 additions & 4 deletions src/main/java/com/simplesteph/kafka/GitHubAPIHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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();
Expand Down Expand Up @@ -108,4 +112,4 @@ public void sleepIfNeed() throws InterruptedException {
sleep();
}
}
}
}
10 changes: 5 additions & 5 deletions src/test/java/com/simplesteph/kafka/GitHubSourceTaskTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand Down Expand Up @@ -43,10 +44,9 @@ public void test() throws UnirestException {
if (httpResponse.getStatus() != 403) {
assertEquals(200, httpResponse.getStatus());
Set<String> 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);
Expand All @@ -55,4 +55,4 @@ public void test() throws UnirestException {
assertEquals(2072, issue.getNumber().intValue());
}
}
}
}

0 comments on commit 348dd80

Please sign in to comment.