Example #1
0
 public function update(Entity\User $user)
 {
     $data = $this->github->getUserApi()->show($user->getName());
     $user->setEmail(isset($data['email']) ? $data['email'] : null);
     $user->setFullName(isset($data['name']) ? $data['name'] : null);
     $user->setCompany(isset($data['company']) ? $data['company'] : null);
     $user->setLocation(isset($data['location']) ? $data['location'] : null);
     $user->setBlog(isset($data['blog']) ? $data['blog'] : null);
     return true;
 }
Example #2
0
 public function update(Entity\User $user)
 {
     try {
         $data = $this->github->getUserApi()->show($user->getName());
     } catch (\phpGitHubApiRequestException $e) {
         if (404 == $e->getCode()) {
             // User has been removed
             return false;
         }
         return true;
     }
     $user->setEmail(isset($data['email']) ? $data['email'] : null);
     $user->setFullName(isset($data['name']) ? $data['name'] : null);
     $user->setCompany(isset($data['company']) ? $data['company'] : null);
     $user->setLocation(isset($data['location']) ? $data['location'] : null);
     $user->setBlog(isset($data['blog']) ? $data['blog'] : null);
     return true;
 }
<?php

require_once dirname(__FILE__) . '/vendor/lime.php';
require_once dirname(__FILE__) . '/../lib/phpGitHubApi.php';
$t = new lime_test(5);
$username = '******';
$token = 'fd8144e29b4a85e9487d1cacbcd4e26c';
$repo = 'php-github-api';
$api = new phpGitHubApi();
$t->comment('Get user with NO authentication');
$user = $api->getUserApi()->show($username);
$t->ok(!isset($user['plan']), 'User plan is not available');
$t->comment('Authenticate ' . $username . ' with default authentication method (should be username and token in URL)');
$api->authenticate($username, $token);
$t->comment('Get user with authentication');
$user = $api->getUserApi()->show($username);
$t->ok(isset($user['plan']), 'User plan is available');
$t->comment('Autentication: ' . $username . ' using HTTP Basic Authentication with token');
$api->authenticate($username, $token, phpGitHubApi::AUTH_HTTP_TOKEN);
$user = $api->getUserApi()->show($username);
$t->ok(isset($user['plan']), 'User plan is available');
$t->comment('Deauthenticate');
$api->deAuthenticate();
$user = $api->getUserApi()->show($username);
$t->ok(!isset($user['plan']), 'User plan is not available');
$t->comment('Authenticate ' . $username . ' with bad token');
$api->authenticate($username, 'bad-token');
$t->comment('Get user with bad authentication');
try {
    $user = $api->getUserApi()->show($username);
    $t->fail('Call with bad authentication throws a phpGitHubApiRequestException');
Example #4
0
if ($_POST['doCreate']) {
    if (!$_POST['username']) {
        throw new Exception('Forgot username.');
    }
    if (!$_POST['password']) {
        throw new Exception('Forgot password.');
    }
    if (!$_POST['repo']) {
        throw new Exception('Forgot repo.');
    }
    if (!is_array($_POST['hash']) || count($_POST['hash']) <= 0) {
        throw new Exception('No tags selected.');
    }
    $github = new phpGitHubApi();
    $github->authenticate($_POST['username'], $_POST['password'], phpGitHubApi::AUTH_HTTP_PASSWORD);
    $userInfo = $github->getUserApi()->show($_POST['username']);
    $github->deAuthenticate();
    //don't need to be auth'd any longer
    if (!isset($userInfo["private_gist_count"])) {
        throw new Exception('unauthorized');
    } else {
        try {
            $repoInfo = $github->getRepoApi()->show($_POST['username'], $_POST['repo']);
            if ($repoInfo['owner'] != $_POST['username']) {
                throw new Exception('You are not the owner of this repo.');
            }
            if ($repoInfo['fork'] || $repoInfo['parent']) {
                throw new Exception('You cannot add a forked repository.');
            }
            $availableTags = $github->getRepoApi()->getRepoTags($_POST['username'], $_POST['repo']);
            foreach ($_POST['hash'] as $hash) {
<?php

require_once dirname(__FILE__) . '/vendor/lime.php';
require_once dirname(__FILE__) . '/../lib/phpGitHubApi.php';
$t = new lime_test(16);
$username = '******';
$token = 'fd8144e29b4a85e9487d1cacbcd4e26c';
$github = new phpGitHubApi(true);
$t->comment('Search users');
$users = $github->getUserApi()->search($username);
$t->is(count($users), 1, 'Found one user');
$t->is(array_keys($users), array($username), 'Found ' . $username . ' user');
$t->is_deeply($github->searchUsers($username), $users, 'Both new and BC syntax work');
$t->comment('Show a user');
$user = $github->getUserApi()->show($username);
$t->is($user['login'], $username, 'Found infos about ' . $username . ' user');
$t->is_deeply($github->showUser($username), $user, 'Both new and BC syntax work');
$t->comment('Show a non-existing user');
try {
    $user = $github->getUserApi()->show('this-user-probably-doesnt-exist');
    $t->fail('Found no infos about this-user-probably-doesnt-exist user');
} catch (phpGitHubApiRequestException $e) {
    $t->pass('Found no infos about this-user-probably-doesnt-exist user');
}
$t->comment('Get following users');
$users = $github->getUserApi()->getFollowing('ornicar');
$t->ok(count($users), 'Found ' . 'ornicar' . ' following users');
$t->comment('Get follower users');
$users = $github->getUserApi()->getFollowers('ornicar');
$t->ok(count($users), 'Found ' . 'ornicar' . ' followers users');
$t->comment('Authenticate ' . $username);