-
Notifications
You must be signed in to change notification settings - Fork 53
Pagination
Miloslav Hůla edited this page Dec 4, 2021
·
5 revisions
The GitHub API documentation describes how to deal with a traversing over huge amount of data.
Pagination easily wipes out your rate limit. Using the CachedClient and Paginator::limit() (described below) helps you.
This is a shortcut for a Milo\Github\Paginator creation for GET requests. The method arguments are the same as for Api::get().
foreach ($api->paginator('/repos/nette/di/commits')->limit(10) as $response) {
var_dump($api->decode($response));
}Class Milo\Github\Paginator helps you to iterate throught the GitHub API. It implements PHP Iterator, so it is easily usable with foreach() loop. Method limit() limits the iteration loop. Iteration stops when exceeded.
use Milo\Github;
$api = new Github\Api;
$request = $api->createRequest(
Github\Http\Request::HEAD, '/repos/{owner}/{repo}/commits',
[
'owner' => 'nette',
'repo' => 'nette',
'page' => 4,
'per_page' => 5,
]
);
$paginator = new Github\Paginator($api, $request);
foreach ($paginator->limit(5) as $page => $response) {
...
}Class contains few static methods which help you with a manual pagination:
Paginator::parsePage($url)Paginator::parseLink($link, $rel)