/** * @return \Github\Client */ public function client() { // create client $client = new \Github\HttpClient\CachedHttpClient(); $client->setCache(new \Github\HttpClient\Cache\FilesystemCache(__DIR__ . '/../tmp/github-cache')); $client = new \Github\Client($client); if (empty(Yii::$app->params['github_token'])) { throw new Exception('Config param "github_token" is not configured!'); } if (empty(Yii::$app->params['github_username'])) { throw new Exception('Config param "github_username" is not configured!'); } // authenticate $client->authenticate(Yii::$app->params['github_token'], '', \Github\Client::AUTH_HTTP_TOKEN); return $client; }
/** * * @param array $config * @param ServiceLocatorInterface $serviceLocator $serviceLocator * @throws \Exception * @todo Handle exceptions as it should!!! GO FOR IT! */ public function __construct(array $config) { $this->config = $config; $client = new \Github\HttpClient\CachedHttpClient(); $client->setCache(new \Github\HttpClient\Cache\FilesystemCache('./data/cache/github-api-cache')); if (!empty($config['user_connect']['username']) && !empty($config['user_connect']['password'])) { $client->authenticate($config['user_connect']['username'], $config['user_connect']['password'], \Github\Client::AUTH_HTTP_PASSWORD); } elseif (!empty($config['oauth']['oauth_consumer_key']) && !empty($config['oauth']['oauth_consumer_secret'])) { echo "no oauth"; throw new \Exception('Oauth Not supported yet'); } else { throw new \Exception('No configuration provided for Github connector'); } try { $this->client = new \Github\Client($client); } catch (\Github\Exception\InvalidArgumentException $e) { throw $e; //die("Argumentos invalidos para la conexion"); } }
protected function github_single($sha) { $client = new \Github\Client(new \Github\HttpClient\CachedHttpClient(array('cache_dir' => '/tmp/github-api-cache'))); $client = new \Github\HttpClient\CachedHttpClient(); $client->setCache(new \Github\HttpClient\Cache\FilesystemCache('/tmp/github-api-cache')); $client = new \Github\Client($client); $result = $commit = $client->api('repo')->commits()->show('shihjay2', 'nosh-core', $sha); return $result; }
<?php require_once 'sessionStart.php'; // This file is generated by Composer require_once 'vendor/autoload.php'; $client = new \Github\Client(new \Github\HttpClient\CachedHttpClient(array('cache_dir' => '/tmp/github-api-cache'))); // Or select directly which cache you want to use $client = new \Github\HttpClient\CachedHttpClient(); $client->setCache(new \Github\HttpClient\Cache\FilesystemCache('/tmp/github-api-cache')); $client = new \Github\Client($client);