jcabi-github icon indicating copy to clipboard operation
jcabi-github copied to clipboard

Pagination and Rate limit

Open simplesteph opened this issue 7 years ago • 2 comments

Hi,

How can I control how many results I get at the same time? My call is

        String twoDaysAgo = ZonedDateTime.now().minusDays(2).format( DateTimeFormatter.ISO_INSTANT );
        enumMap.put(Issues.Qualifier.SINCE, now);
        Iterable<Issue> issuesIterator = repo.issues().search(Issues.Sort.UPDATED, Search.Order.DESC, enumMap );
        issuesIterator.iterator().forEachRemaining(i -> System.out.println(i.label()));

And then I'm getting the error:

{"message":"API rate limit exceeded for 122.XXX.XXX.XXX. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)","documentation_url":"https://developer.github.com/v3/#rate-limiting"}>
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)
	at com.jcabi.http.response.RestResponse.assertStatus(RestResponse.java:111)
	at com.jcabi.github.RtValuePagination$Items.fetch(RtValuePagination.java:193)
	at com.jcabi.github.RtValuePagination$Items.hasNext(RtValuePagination.java:179)
	at java.util.Iterator.forEachRemaining(Iterator.java:115)
  1. How can I specify the page size to be 100 ? (max authorised)
  2. How can I throttle my iteratable to respect the rate limiting? This should be done under the hood ideally?

simplesteph avatar Apr 25 '17 00:04 simplesteph

@yegor256 please, pay attention to this issue

0crat avatar Apr 25 '17 00:04 0crat

@simplesteph you may use LimitedIterable from Cactoos:

new LimitedIterable<>(issues, 100).iterator().forEachRemaining(
  i -> System.out.println(i.label())
);

yegor256 avatar Jul 18 '17 10:07 yegor256