Skip to content

Commit 348dd80

Browse files
authored
Merge pull request #14 from kieronedwards/issue-13
issue-13: corrected header values as seem to have changed on github
2 parents 5cfd9c1 + eb4be70 commit 348dd80

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/main/java/com/simplesteph/kafka/GitHubAPIHttpClient.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public class GitHubAPIHttpClient {
2727

2828
GitHubSourceConnectorConfig config;
2929

30+
public static final String X_RATELIMIT_LIMIT_HEADER="X-Ratelimit-Limit";
31+
public static final String X_RATELIMIT_REMAINING_HEADER="X-Ratelimit-Remaining";
32+
public static final String X_RATELIMIT_RESET_HEADER="X-Ratelimit-Reset";
33+
3034
public GitHubAPIHttpClient(GitHubSourceConnectorConfig config){
3135
this.config = config;
3236
}
@@ -39,9 +43,9 @@ protected JSONArray getNextIssues(Integer page, Instant since) throws Interrupte
3943

4044
// deal with headers in any case
4145
Headers headers = jsonResponse.getHeaders();
42-
XRateLimit = Integer.valueOf(headers.getFirst("X-RateLimit-Limit"));
43-
XRateRemaining = Integer.valueOf(headers.getFirst("X-RateLimit-Remaining"));
44-
XRateReset = Integer.valueOf(headers.getFirst("X-RateLimit-Reset"));
46+
XRateLimit = Integer.valueOf(headers.getFirst(X_RATELIMIT_LIMIT_HEADER));
47+
XRateRemaining = Integer.valueOf(headers.getFirst(X_RATELIMIT_REMAINING_HEADER));
48+
XRateReset = Integer.valueOf(headers.getFirst(X_RATELIMIT_RESET_HEADER));
4549
switch (jsonResponse.getStatus()){
4650
case 200:
4751
return jsonResponse.getBody().getArray();
@@ -108,4 +112,4 @@ public void sleepIfNeed() throws InterruptedException {
108112
sleep();
109113
}
110114
}
111-
}
115+
}

src/test/java/com/simplesteph/kafka/GitHubSourceTaskTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.Map;
1313
import java.util.Set;
1414

15+
import static com.simplesteph.kafka.GitHubAPIHttpClient.*;
1516
import static com.simplesteph.kafka.GitHubSourceConnectorConfig.*;
1617
import static org.junit.Assert.*;
1718

@@ -43,10 +44,9 @@ public void test() throws UnirestException {
4344
if (httpResponse.getStatus() != 403) {
4445
assertEquals(200, httpResponse.getStatus());
4546
Set<String> headers = httpResponse.getHeaders().keySet();
46-
assertTrue(headers.contains("ETag"));
47-
assertTrue(headers.contains("X-RateLimit-Limit"));
48-
assertTrue(headers.contains("X-RateLimit-Remaining"));
49-
assertTrue(headers.contains("X-RateLimit-Reset"));
47+
assertTrue(headers.contains(X_RATELIMIT_LIMIT_HEADER));
48+
assertTrue(headers.contains(X_RATELIMIT_REMAINING_HEADER));
49+
assertTrue(headers.contains(X_RATELIMIT_RESET_HEADER));
5050
assertEquals(batchSize.intValue(), httpResponse.getBody().getArray().length());
5151
JSONObject jsonObject = (JSONObject) httpResponse.getBody().getArray().get(0);
5252
Issue issue = Issue.fromJson(jsonObject);
@@ -55,4 +55,4 @@ public void test() throws UnirestException {
5555
assertEquals(2072, issue.getNumber().intValue());
5656
}
5757
}
58-
}
58+
}

0 commit comments

Comments
 (0)