3 namespace app\Github\Fetch
;
5 use app\Github\Exception\ReposFetchFailed
;
8 use http\Client\Request
;
11 class Repos
extends Fetch
13 function getRequest() {
14 $url = $this->url
->mod([
15 "path" => "/user/repos",
16 "query" => new QueryString([
17 "page" => $this->getPage()
20 return new Request("GET", $url, [
21 "Accept" => "application/vnd.github.v3+json",
22 "Authorization" => "token " . $this->api
->getToken(),
26 function getException($message, $code, $previous = null) {
27 return new ReposFetchFailed($message, $code, $previous);
30 function getCacheKey() {
31 return $this->api
->getCacheKey("repos", $this->page
);
34 protected function wrap(callable
$callback) {
35 return parent
::wrap(function($json, $links) use($callback) {
36 if (($cache = $this->getStorage($ttl))) {
37 foreach ($json as $repo) {
38 $key = $this->api
->getCacheKey(sprintf("repo:%s", $repo->full_name
));
39 $cache->set($key, [$repo, $links], $ttl);
43 $callback($json, $links);