setToken() публичный Метод

public setToken ( Milo\Github\OAuth\Token $token = NULL ) : self
$token Milo\Github\OAuth\Token
Результат self
Пример #1
0
 /**
  * Creates a new instance of the API library to use later.
  *
  * @throws InvalidArgumentException
  */
 protected function createApiInstance()
 {
     $configToken = $this->getConfig('token');
     if ($configToken === null) {
         throw new InvalidArgumentException('API token has not been set in the config.');
     }
     $token = new Token($configToken);
     $this->api = new Api();
     $this->api->setToken($token);
 }
Пример #2
0
include '../php/github-api.php';
use Milo\Github;
$contributorcache = "../cache/contributors.json";
$cachetime = 60 * 60 * 12;
// 12 hours
$contributors;
if (file_exists($contributorcache) && time() - $cachetime < filemtime($contributorcache)) {
    // $cachedata = file_get_contents($contributorcache);
    // $contributors = json_decode($cachedata);
} else {
    $contributors = array();
    $contributorsMin = array();
    try {
        $api = new Github\Api();
        $token = new Github\OAuth\Token("{{site.github_key}}");
        $api->setToken($token);
        foreach ($api->paginator('/repos/amplab/tachyon/contributors') as $response) {
            array_push($contributors, $api->decode($response));
        }
        foreach ($contributors as $contributorPage) {
            foreach ($contributorPage as $contributor) {
                array_push($contributorsMin, array('login' => $contributor->login, 'avatar_url' => $contributor->avatar_url, 'contributions' => $contributor->contributions));
            }
        }
        $contributors = $contributorsMin;
    } catch (Exception $e) {
        //echo $e->getMessage();
    }
    $fp = fopen($contributorcache, "w");
    fwrite($fp, json_encode($contributorsMin));
    fclose($fp);