start refactoring to promises
[pharext/pharext.org] / app / Github / API / Users / ReadAuthUser.php
index b5c4fa92b78382c66a2052eedd3f6927e18d1160..01bd78c09ba705f4dea732e83a8f878b00220b83 100644 (file)
@@ -5,23 +5,24 @@ namespace app\Github\API\Users;
 use app\Github\API\Call;
 use app\Github\Exception\RequestException;
 use http\Client\Request;
+use http\Client\Response;
 
 class ReadAuthUser extends Call
 {
-       function enqueue(callable $callback) {
+       function request() {
                $url = $this->url->mod("./user");
                $request = new Request("GET", $url, [
                        "Authorization" => "token ". $this->api->getToken(),
                        "Accept" => $this->config->api->accept,
                ]);
-               $this->api->getClient()->enqueue($request, function($response) use($callback) {
-                       if ($response->getResponseCode() >= 400 || null === ($json = json_decode($response->getBody()))) {
-                               throw new RequestException($response);
-                       }
-                       $this->result = [$json];
-                       $this->saveToCache($this->result);
-                       $callback($json);
-                       return true;
-               });
+               return $request;
+       }
+       
+       function response(Response $response) {
+               if ($response->getResponseCode() >= 400 || null === ($json = json_decode($response->getBody()))) {
+                       throw new RequestException($response);
+               }
+               $this->saveToCache([$json]);
+               return [$json];
        }
 }