gh
gh copied to clipboard
Rate limit helpers
i.e. see how many requests you have left in the current period, and another function to automatically wait until you have another request
Related to this, I think it would be helpful to have a simple .wait
parameter to gh()
, which specifies the wait period in seconds between API calls. This would allow the user to rely upon the .limit = Inf
existing functionality without getting an error due to the API rate being exceeded. The point is to avoid the user to have to write their own loops using gh_next()
etc.
E.g., avoid:
> moodle_commmits_12months = gh("GET /repos/:owner/:repo/commits", owner = "moodle", repo = "moodle", since = year_ago, .limit = Inf)
ℹ Running gh query, got 66600 records of about 77700Error in gh_process_response(raw) :
GitHub API error (403): 403 Forbidden
Message: API rate limit exceeded for MY_IP. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)
Read more at https://developer.github.com/v3/#rate-limiting
(Note there is a lack of newline here making the error message hard to read.)
By using something like:
moodle_commmits_12months = gh("GET /repos/:owner/:repo/commits", owner = "moodle", repo = "moodle", since = year_ago, .limit = Inf, .wait = 10)
@Deleetdk I guess #113 will address that?
We could also resolve this by switching to httr2, since that has a helpers (https://httr2.r-lib.org/reference/req_retry.html and https://httr2.r-lib.org/reference/req_throttle.html) built in.