Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 057c32d

Browse filesBrowse files
committed
added API to retrieve rate limit.
1 parent 33657c9 commit 057c32d
Copy full SHA for 057c32d

File tree

Expand file treeCollapse file tree

4 files changed

+40
-0
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+40
-0
lines changed
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.kohsuke.github;
2+
3+
/**
4+
* Rate limit.
5+
* @author Kohsuke Kawaguchi
6+
*/
7+
public class GHRateLimit {
8+
/**
9+
* Remaining calls that can be made.
10+
*/
11+
public int remaining;
12+
/**
13+
* Alotted API call per hour.
14+
*/
15+
public int limit;
16+
17+
@Override
18+
public String toString() {
19+
return remaining+"/"+limit;
20+
}
21+
}

‎src/main/java/org/kohsuke/github/GitHub.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GitHub.java
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,13 @@ private InputStream wrapStream(HttpURLConnection uc, InputStream in) throws IOEx
358358
}
359359
}
360360

361+
/**
362+
* Gets the current rate limit.
363+
*/
364+
public GHRateLimit getRateLimit() throws IOException {
365+
return retrieveWithAuth3("/rate_limit",JsonRateLimit.class).rate;
366+
}
367+
361368
/**
362369
* Gets the {@link GHUser} that represents yourself.
363370
*/
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.kohsuke.github;
2+
3+
/**
4+
* @author Kohsuke Kawaguchi
5+
*/
6+
class JsonRateLimit {
7+
GHRateLimit rate;
8+
}

‎src/test/java/org/kohsuke/AppTest.java

Copy file name to clipboardExpand all lines: src/test/java/org/kohsuke/AppTest.java
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public void testCredentialValid() throws IOException {
3636
assertFalse(GitHub.connect("totally","bogus").isCredentialValid());
3737
}
3838

39+
public void testRateLimit() throws IOException {
40+
System.out.println(GitHub.connect().getRateLimit());
41+
}
42+
3943
public void testFetchPullRequest() throws Exception {
4044
GitHub gh = GitHub.connect();
4145
GHRepository r = gh.getOrganization("jenkinsci").getRepository("jenkins");

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.