15c0314e9243ae935e23fc718b7f16b368317283
[pharext/pharext.org] / app / Github / API / Repos / ReadRepo.php
1 <?php
2
3 namespace app\Github\API\Repos;
4
5 use app\Github\API\Call;
6 use app\Github\Exception\RequestException;
7 use http\Client\Request;
8 use http\Client\Response;
9
10 class ReadRepo extends Call
11 {
12 function request() {
13 $url = $this->url->mod(uri_template("./repos/{+repo}", $this->args));
14 $request = new Request("GET", $url, [
15 "Authorization" => "token " . $this->api->getToken(),
16 "Accept" => $this->config->api->accept,
17 ]);
18 return $request;
19 }
20
21 function response(Response $response) {
22 if ($response->getResponseCode() >= 400 || null === ($json = json_decode($response->getBody()))) {
23 throw new RequestException($response);
24 }
25 $result = [$json];
26 $this->saveToCache($result);
27 return $result;
28 }
29 }