tiny fixes
[pharext/pharext.org] / app / Github / API.php
index 0f63a60f5b873a33abdfc07d78538de9a829ce27..522cf146c6b6090872917897c904d52270b1101e 100644 (file)
@@ -49,7 +49,8 @@ class API
        function __construct(Config $config, LoggerInterface $logger, Storage $tokens = null, Storage $cache = null) {
                $this->logger = $logger;
                $this->config = $config;
-               $this->client = new Client;
+               $this->client = new Client("curl", "github");
+               $this->client->configure($config->http->configure->toArray());
                $this->client->attach(new ClientObserver($logger));
                $this->tokens = $tokens ?: new Storage\Session;
                $this->cache = $cache;
@@ -168,6 +169,22 @@ class API
                return $call($callback);
        }
 
+       /**
+        * Check if the pharext webhook is set for the repo and return it
+        * @param object $repo
+        * @return stdClass hook
+        */
+       function checkRepoHook($repo) {
+               if ($repo->hooks) {
+                       foreach ($repo->hooks as $hook) {
+                               if ($hook->name === "web" && $hook->config->url === $this->config->hook->url) {
+                                       return $hook;
+                               }
+                       }
+               }
+               return null;
+       }
+
        function listHooks($repo, callable $callback) {
                $call = new API\Hooks\ListHooks($this, compact("repo"));
                return $call($callback);
@@ -212,4 +229,9 @@ class API
                $call = new API\Releases\CreateReleaseAsset($this, compact("url", "asset", "type"));
                return $call($callback);
        }
+       
+       function listReleaseAssets($repo, $id, callable $callback) {
+               $call = new API\Releases\ListReleaseAssets($this, compact("repo", "id"));
+               return $call($callback);
+       }
 }