11 * @var \app\Github\API
30 function __construct(API
$api, array $args = []) {
32 $this->config
= $api->getConfig();
34 $this->url
= new Url("https://api.github.com/", null, 0);
37 function __toString() {
38 $parts = explode("\\", get_class($this));
39 return strtolower(end($parts));
42 abstract function getRequest();
43 abstract function getException($message, $code, $previous = null);
45 function __invoke(callable
$callback) {
46 $this->enqueue($callback);
47 return $this->api
->getClient();
50 protected function wrap(callable
$callback) {
51 return function($response) use($callback) {
52 $rc = $response->getResponseCode();
55 if ($response->getHeader("Content-Type", Header
::class)->match("application/json", Header
::MATCH_WORD
)) {
56 $message = json_decode($response->getBody())->message
;
58 $message = $response->getBody();
60 throw $this->getException($message, $rc);
63 $json = json_decode($response->getBody());
65 if (isset($json->error
)) {
66 throw $this->getException($json->error_description
, $rc);
75 function enqueue(callable
$callback) {
76 $request = $this->getRequest();
77 $wrapper = $this->wrap($callback);
78 return $this->api
->getClient()->enqueue($request, $wrapper);