public function testMountsClient()
 {
     $client = new Client();
     StaticClient::mount('FooBazBar', $client);
     $this->assertTrue(class_exists('FooBazBar'));
     $this->assertSame($client, $this->readAttribute('Guzzle\\Http\\StaticClient', 'client'));
 }
Exemple #2
0
 public static function execute()
 {
     // TODO: create configuration file for organization/client_id/client_secret
     $organization = 'doubleleft';
     $data = '# -------------------------------------------------------------' . PHP_EOL;
     $data .= '# WARNING: PROTECT PUBLIC ACCESS OF THIS FILE ON YOUR WEBSERVER' . PHP_EOL;
     $data .= '# -------------------------------------------------------------' . PHP_EOL;
     $data .= '# Lists of allowed openssh keys to consume API via commandline ' . PHP_EOL;
     $data .= '# ' . PHP_EOL;
     \Guzzle\Http\StaticClient::mount();
     $public_keys = array();
     foreach (self::get("/orgs/{$organization}/members") as $member) {
         foreach (self::getUserKeys($member['login']) as $key) {
             $data .= $key['key'] . PHP_EOL;
         }
     }
     file_put_contents(__DIR__ . '/../../' . self::DESTINATION_FILE, $data);
     echo "Github public keys downloaded successfully at '" . self::DESTINATION_FILE . "'." . PHP_EOL;
 }
use Symfony\Component\Yaml\Yaml;
use OCLC\Auth\WSKey;
use OCLC\Auth\AuthCode;
use OCLC\Auth\AccessToken;
use OCLC\User;
// The global configuration object.
// If you have not created a config.yaml file with your authentication parameters in it,
// copy app/config/sampleConfig.yaml to app/config/config.yaml and set the parameters.
global $config;
$config = Yaml::parse('app/config/config.yaml');
// Set the Guzzle options.
// Guzzle makes it easy to work with restful web services.
// http://guzzle.readthedocs.org/en/latest/
$guzzleOptions = array('config' => array('curl' => array(CURLOPT_SSLVERSION => 3)), 'allow_redirects' => array('strict' => true), 'timeout' => 60);
if (!class_exists('Guzzle')) {
    \Guzzle\Http\StaticClient::mount();
}
// We use sessions to persist our authentication between calls to the WMS Availability service.
session_start();
// Construct a new WSkey object using the key, secret and an options array that contains the services
// you want to access and your redirect_uri
$options = array('services' => array('WMS_Availability', 'refresh_token'));
$wskey = new WSKey($config['wskey'], $config['secret'], $options);
// if you don't have an Access Token already
if (empty($_SESSION['accessToken'])) {
    $accessToken = $wskey->getAccessTokenWithClientCredentials($config['institution'], $config['institution']);
    $_SESSION['accessToken'] = $accessToken;
} else {
    // Otherwise, get the existing access token from the session
    $accessToken = $_SESSION['accessToken'];
}