refactor guthub api
[pharext/pharext.org] / app / Github / API / Users / ReadAuthToken.php
1 <?php
2
3 namespace app\Github\API\Users;
4
5 use app\Github\API\Call;
6 use app\Github\Exception\RequestException;
7 use http\Client\Request;
8 use http\QueryString;
9
10 class ReadAuthToken extends Call
11 {
12 function enqueue(callable $callback) {
13 $request = new Request("POST", "https://github.com/login/oauth/access_token", [
14 "Accept" => "application/json",
15 ]);
16 $request->getBody()->append(new QueryString($this->args));
17 $this->api->getClient()->enqueue($request, function($response) use($callback) {
18 if ($response->getResponseCode() >= 400 || null === ($json = json_decode($response->getBody()))) {
19 throw new RequestException($response);
20 }
21 $callback($json);
22 return true;
23 });
24 }
25 }