Пример #1
0
<?php

use GithubService\GithubArtaxService\GithubService;
use ArtaxServiceBuilder\ResponseCache\NullResponseCache;
use Amp\Artax\Client as ArtaxClient;
use ArtaxServiceBuilder\BadResponseException;
use ArtaxServiceBuilder\Oauth2Token;
use GithubService\Hydrator\HydratorException;
require_once "testBootstrap.php";
$injector = createProvider();
$reactor = \Amp\reactor();
$cache = new NullResponseCache();
$client = new ArtaxClient();
$client->setOption(ArtaxClient::OP_MS_CONNECT_TIMEOUT, 5000);
$client->setOption(ArtaxClient::OP_MS_KEEP_ALIVE_TIMEOUT, 1000);
$githubAPI = new GithubService($client, $reactor, $cache, "Danack/test");
$token = @file_get_contents("../../GithubToken.txt");
$oauthToken = null;
if ($token) {
    $oauthToken = new Oauth2Token($token);
}
try {
    $tagListRequest = $githubAPI->listRepoTags(null, "Danack", "GithubArtaxService");
    $tagList = $tagListRequest->execute();
    foreach ($tagList as $tag) {
        /** @var $tag \GithubService\Model\Tag */
        printf("tag name %s, commmit %s \n", $tag->name, $tag->commit->sha);
    }
    $emojiResult = $githubAPI->listEmojis(null)->execute();
    foreach ($emojiResult->emojis as $emoji) {
        echo $emoji->name . " \n";
Пример #2
0
 /**
  * @param GithubService $api
  * @param $accessResponse
  */
 function processAddEmail(GithubService $api, $accessResponse)
 {
     $newEmail = getVariable('email');
     $emailCommand = $api->addUserEmails(new Oauth2Token($accessResponse->accessToken), [$newEmail]);
     $allowedScopes = getAuthorisations();
     if (false) {
         //This isn't working yet.
         $emailCommand->checkScopeRequirement($allowedScopes);
     }
     $emailCommand->execute();
     $request = $emailCommand->createRequest();
     $request->setBody(json_encode([$newEmail]));
     $response = $emailCommand->dispatch($request);
 }
<?php

$autoloader = (require __DIR__ . '/../vendor/autoload.php');
use GithubService\GithubArtaxService\GithubService;
use Amp\Artax\Client as ArtaxClient;
use ArtaxServiceBuilder\ResponseCache\FileResponseCache;
use GithubService\AuthToken\NullToken;
$github = new GithubService(new ArtaxClient(), \Amp\reactor(), new FileResponseCache(__DIR__ . "/fileCache"), 'Danack/GithubArtaxService');
$command = $github->listRepoTags(new NullToken(), 'php', 'php-src');
$listRepoTags = $command->execute();
$statusCode = $command->getOriginalResponse()->getStatus();
if ($statusCode == 304) {
    echo "YAY! 304 response so data read from cache. This request did not count against the rate limit.\n";
} else {
    echo "Cache miss.\n";
}
$rateLimit = $github->getRateLimit();
//Alternatively you can create the rate limit object from the original response
//$rateLimit = \GithubService\RateLimit::createFromResponse($command->getOriginalResponse());
if ($rateLimit) {
    echo sprintf("Rate limit info:\n  Remaining: %d\n  Reset time: %d\n", $rateLimit->remaining, $rateLimit->resetTime);
} else {
    echo "No rate limit information was in the response.\n";
}
<?php

$autoloader = (require __DIR__ . '/../vendor/autoload.php');
use GithubService\GithubArtaxService\GithubService;
use Amp\Artax\Client as ArtaxClient;
use ArtaxServiceBuilder\ResponseCache\NullResponseCache;
use GithubService\Model\Tags;
use GithubService\AuthToken\NullToken;
function displayTags(Tags $repoTags)
{
    foreach ($repoTags as $nextRepoTag) {
        echo "Found tag: " . $nextRepoTag->name . "\n";
    }
}
$github = new GithubService(new ArtaxClient(), \Amp\reactor(), new NullResponseCache(), 'Danack/GithubArtaxService');
echo "Tags on first page:\n";
//Get the first page of data
$command = $github->listRepoTags(new NullToken(), 'php', 'php-src');
$repoTags = $command->execute();
displayTags($repoTags);
use ArtaxServiceBuilder\ResponseCache\NullResponseCache;
use GithubService\AuthToken\NullToken;
use GithubService\GithubArtaxService\GithubService;
use GithubService\Model\Tags;
// Create the appropriate Amp reactor for your system. This depends on
// which extensions you have loaded:
// uv extension -  UvReactor;
// libevent extension - LibeventReactor;
// otherwise a NativeReactor is used.
$reactor = \Amp\reactor();
$artaxClient = new ArtaxClient();
// The reactor keeps running while the socket is open. Set a short
// timeout to avoid waiting around too long
$artaxClient->setOption(\Amp\Artax\Client::OP_MS_KEEP_ALIVE_TIMEOUT, 1);
// Create the GithubService with the prepared client
$github = new GithubService($artaxClient, $reactor, new NullResponseCache(), 'Danack/GithubArtaxService');
//Get the first page of data
$command = $github->listRepoTags(new NullToken(), 'php', 'php-src');
$listRepoTagsCallback = function (Exception $exception = null, Tags $repoTags, Response $response = null) use($github) {
    if ($exception) {
        echo "An error occurred: " . $exception->getMessage();
        return;
    }
    echo "Tags on first page:\n";
    foreach ($repoTags as $repoTag) {
        echo "Found tag: " . $repoTag->name . "\n";
    }
    $pages = $repoTags->pager->getAllKnownPages();
    foreach ($pages as $page) {
        $command = $github->listRepoTagsPaginate(new NullToken(), $page);
        $callback = getListRepoTagsPagingCallback($page);
<?php

use GithubService\AuthToken\Oauth2Token;
use GithubService\GithubArtaxService\GithubService;
use Amp\Artax\Client as ArtaxClient;
use ArtaxServiceBuilder\ResponseCache\NullResponseCache;
$autoloader = (require __DIR__ . '/../vendor/autoload.php');
$github = new GithubService(new ArtaxClient(), \Amp\reactor(), new NullResponseCache(), 'Danack/GithubArtaxService');
$tokenFileLocation = __DIR__ . "/../../github_oauth_token.txt";
$existingToken = @file_get_contents($tokenFileLocation);
$existingToken = trim($existingToken);
if ($existingToken) {
    echo "Using token from file {$tokenFileLocation} \n";
    $token = new Oauth2Token($existingToken);
} else {
    echo "Enter username:\n";
    $username = trim(fgets(STDIN));
    echo "Enter password (warning - not masked for this example):\n";
    $password = trim(fgets(STDIN));
    /**
     * @param $instruction
     * @return string
     */
    $enterPasswordCallback = function ($instruction) {
        echo $instruction . "\n";
        $oneTimePassword = trim(fgets(STDIN));
        return $oneTimePassword;
    };
    $noteURL = 'http://www.github.com/danack/GithubArtaxService';
    $note = "Testing Oauth creation: " . time();
    //This must be unique to create a new Oaut key
Пример #7
0
 public function showAuthorizations(GithubService $api, AccessResponse $accessResponse)
 {
     try {
         echo "<p>This function is likely to fail. It appears that Github do not support it through the api with bearer tokens.</p>";
         //$api = new GithubAPI(GITHUB_USER_AGENT);
         $authCommand = $api->getAuthorizations(new Oauth2Token($accessResponse->accessToken));
         $authorisations = $authCommand->execute();
         foreach ($authorisations->getIterator() as $authorisation) {
             echo "Application: " . $authorisation->application . "<br/>";
             echo "Scopes:" . implode($authorisation->scopes) . "<br/>";
             echo "<br/>";
         }
     } catch (\GithubService\GithubArtaxService\GithubArtaxServiceException $gae) {
         echo "<p>Error in showAuthorizations: ";
         echo $gae->getMessage();
         echo "</p>";
     }
 }