/** * Factory method to create a new TogglClient * * The following array keys and values are available options: * - base_url: Base URL of web service * - username: username or API key * - password: password (if empty, then username is a API key) * * See https://www.toggl.com/public/api#api_token for more information on the api token * * @param array|Collection $config Configuration data * * @return self */ public static function factory($config = array()) { $default = array('base_url' => 'https://www.toggl.com/api/{apiVersion}', 'debug' => false, 'apiVersion' => 'v8', 'api_key' => '', 'username' => '', 'password' => ''); $required = array('api_key', 'username', 'password', 'base_url', 'apiVersion'); $config = Collection::fromConfig($config, $default, $required); $client = new self($config->get('base_url'), $config); // Attach a service description to the client if ($config->get('apiVersion') == 'v8') { $description = ServiceDescription::factory(__DIR__ . '/services_v8.json'); } else { die('Only v8 is supported at this time'); } $client->setDescription($description); $client->setDefaultHeaders(array("Content-type" => "application/json")); if (!empty($config->get('api_key'))) { $config->set('username', $config->get('api_key')); $config->set('password', 'api_token'); } if (empty($config->get('password'))) { $config->set('password', 'api_token'); } $authPlugin = new CurlAuthPlugin($config->get('username'), $config->get('password')); $client->addSubscriber($authPlugin); if ($config->get('debug')) { $client->addSubscriber(LogPlugin::getDebugPlugin()); } return $client; }
/** * Initializes the HTTP Client */ private function initializeClient() { $this->client = new GuzzleClient($this->config->getBaseUrl()); $this->client->setDefaultOption('headers', $this->getHeaders()); $this->client->getConfig()->set('curl.options', array(CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4)); if ($this->config->getDebug()) { $this->client->addSubscriber(LogPlugin::getDebugPlugin()); } }
/** * CreateConnection operation example * * @example Aws\DirectConnect\DirectConnectClient::createConnection */ public function testCreatesConnection() { $client = $this->getServiceBuilder()->get('directconnect', true); $client->getEventDispatcher()->addSubscriber(LogPlugin::getDebugPlugin()); self::log('Create a connection'); // @begin $result = $client->createConnection(array('bandwidth' => '1Gbps', 'connectionName' => 'PHPTest', 'location' => 'EqDC2')); $connectionId = $result['connectionId']; // @end $this->assertEquals(ConnectionState::REQUESTED, $result['connectionState']); return $connectionId; }
/** * @return Client */ protected function buildGitHubClient() { $httpClient = new HttpClient(['base_url' => $this->config['base_url']]); $client = new Client($httpClient); if (false !== getenv('GITHUB_DEBUG')) { $logPlugin = LogPlugin::getDebugPlugin(); $httpClient = $client->getHttpClient(); $httpClient->addSubscriber($logPlugin); } $client->setOption('base_url', $this->config['base_url']); $this->url = rtrim($this->config['base_url'], '/'); $this->domain = rtrim($this->config['repo_domain_url'], '/'); return $client; }
public static function factory($config = array()) { // default config values $default = array('base_url' => 'https://localbitcoins.com/oauth2/', 'debug' => false); $config = Collection::fromConfig($config, $default, array('base_url')); // client with required keys $client = new self($config->get('base_url'), $config); // optiona debugging if ($config->get('debug')) { $client->addSubscriber(LogPlugin::getDebugPlugin()); } // load the service description $client->setDescription(ServiceDescription::factory(__DIR__ . '/Resources/oauth.json')); return $client; }
/** * factory * * @param array $config * @return \self */ public static function factory($config = []) { $default = ['useClientCert' => false, 'domain' => "cybozu.com", 'logfile' => __DIR__ . '/../../../app/logs/kintone.log', 'useLog' => true]; $required = ['domain', 'subdomain', 'login', 'password']; $config = Collection::fromConfig($config, $default, $required); $client = new self(parent::getApiPathBase($config), $config); $client->addSubscriber(new KintoneAuth($config->toArray())); $client->addSubscriber(new KintoneError($config->toArray())); $client->setDescription(ServiceDescription::factory(__DIR__ . "/Resources/config/kintone.json")); if ($config->get('useLog')) { $logPlugin = LogPlugin::getDebugPlugin(TRUE, fopen($config->get('logfile'), 'a')); $client->addSubscriber($logPlugin); } return $client; }
public function testHasHelpfulStaticFactoryMethod() { $s = fopen('php://temp', 'r+'); $client = new Client(); $client->addSubscriber(LogPlugin::getDebugPlugin(true, $s)); $request = $client->put('http://foo.com', array('Content-Type' => 'Foo'), 'Bar'); $request->setresponse(new Response(200), true); $request->send(); rewind($s); $contents = stream_get_contents($s); $this->assertContains('# Request:', $contents); $this->assertContainsIns('PUT / HTTP/1.1', $contents); $this->assertContains('# Response:', $contents); $this->assertContainsIns('HTTP/1.1 200 OK', $contents); $this->assertContains('# Errors:', $contents); }
/** * Factory method to create a new TogglClient * * The following array keys and values are available options: * - base_url: Base URL of web service * - api_key: API key * * See https://www.toggl.com/public/api#api_token for more information on the api token * * @param array|Collection $config Configuration data * * @return ReportsClient */ public static function factory($config = array()) { $default = array('base_url' => 'https://www.toggl.com/reports/api/{apiVersion}', 'debug' => false, 'apiVersion' => 'v2'); $required = array('api_key', 'base_url', 'apiVersion'); $config = Collection::fromConfig($config, $default, $required); $serviceDescriptionFile = __DIR__ . '/reporting_' . $config->get('apiVersion') . '.json'; $description = ServiceDescription::factory($serviceDescriptionFile); $client = new self($config->get('base_url'), $config); $client->setDescription($description); $client->setDefaultHeaders(array("Content-type" => "application/json")); $authPlugin = new CurlAuthPlugin($config->get('api_key'), 'api_token'); $client->addSubscriber($authPlugin); if ($config->get('debug')) { $client->addSubscriber(LogPlugin::getDebugPlugin()); } return $client; }
public static function factory($config = array()) { // default config values $default = array('base_url' => 'https://localbitcoins.com/api', 'debug' => false); $config = Collection::fromConfig($config, $default, array('base_url')); $client = new self($config->get('base_url'), $config); $client->setDescription(ServiceDescription::factory(__DIR__ . '/Resources/localbtc.json')); // optiona debugging if ($config->get('debug')) { $client->addSubscriber(LogPlugin::getDebugPlugin()); } // oauth2 hook $client->getEventDispatcher()->addListener('request.before_send', function (Event $event) use($config) { $event['request']->getQuery()->set('access_token', $config['access_token']); }); return $client; }
/** * @param string $outputFile * @return NuxeoClient */ public function debug($outputFile = null) { $stream = $outputFile ? fopen($outputFile, 'w+b') : null; $this->httpClient->addSubscriber(LogPlugin::getDebugPlugin(true, $stream)); return $this; }
protected function visit_debug(RequestInterface $request, $value, $flags) { if (class_exists('Guzzle\\Plugin\\Log\\LogPlugin')) { $request->addSubscriber(LogPlugin::getDebugPlugin()); } else { // @codeCoverageIgnoreStart $request->getCurlOptions()->set(CURLOPT_VERBOSE, true); // @codeCoverageIgnoreEnd } }
public function init() { $httpClient = new HttpClient(); // Setup logging. // Transfer GitHub API logging to the Phing log. $task = $this; $logPlugin = new LogPlugin(new ClosureLogAdapter(function ($message, $priority, $extras) use($task) { $logLevelPriorities = array(LOG_EMERG => Project::MSG_ERR, LOG_ALERT => Project::MSG_ERR, LOG_CRIT => Project::MSG_ERR, LOG_ERR => Project::MSG_ERR, LOG_WARNING => Project::MSG_WARN, LOG_NOTICE => Project::MSG_INFO, LOG_INFO => Project::MSG_VERBOSE, LOG_DEBUG => Project::MSG_DEBUG); $task->log($message, $logLevelPriorities[$priority]); })); $httpClient->client->addSubscriber($logPlugin); // Add the debug logger when the debug output level has been set. if (Phing::getMsgOutputLevel() == Project::MSG_DEBUG) { $httpClient->client->addSubscriber(LogPlugin::getDebugPlugin()); } $this->client = new Client($httpClient); }
private function createClient() { Utils::log('Authenticate'); $secret = array('username' => Utils::getEnvVar(Enum::ENV_USERNAME), 'apiKey' => Utils::getEnvVar(Enum::ENV_API_KEY)); $identityEndpoint = Utils::getIdentityEndpoint(); // Do connection stuff $client = new Rackspace($identityEndpoint, $secret); $client->setUserAgent($client->getUserAgent() . '/' . Enum::USER_AGENT); // enable logging if ($this->debugMode) { $client->addSubscriber(LogPlugin::getDebugPlugin()); } $client->authenticate(); Utils::logf(' Using identity endpoint: %s', $identityEndpoint); Utils::logf(' Using region: %s', Utils::getRegion()); Utils::logf(' Token generated: %s', (string) $client->getToken()); return $client; }
/** * @param $customerKey * @return \Guzzle\Http\Client * @throws Exception\RuntimeException */ protected static function getPreparedGuzzleClient($customerKey) { $guzzle = new \Guzzle\Http\Client(); $guzzle->setConfig(array('customerKey' => $customerKey, 'redirect.disable' => true)); if (self::$HTTP_DEBUG === TRUE) { if (class_exists('\\Guzzle\\Plugin\\Log\\LogPlugin')) { $guzzle->addSubscriber(\Guzzle\Plugin\Log\LogPlugin::getDebugPlugin()); return $guzzle; } else { throw new \Searchperience\Common\Exception\RuntimeException('Please run "composer install --dev" to install "guzzle/plugin-log"'); } } return $guzzle; }
/** * Adds a LogPlugin to a Guzzle service client object * * This will cause any requests created by the client to log all * requests sent and received. * * @param Guzzle\Service\Client $client The Guzzle service client */ protected function logClient(Client $client) { $client->addSubscriber(LogPlugin::getDebugPlugin()); }
<?php use Guzzle\Plugin\Log\LogPlugin; use Smaft\OktaSdk\Exception\ApiErrorException; use Smaft\OktaSdk\Model\Profile; use Smaft\OktaSdk\OktaClient; require __DIR__ . '/../vendor/autoload.php'; $client = new OktaClient(require __DIR__ . '/../config.php'); $client->addSubscriber(LogPlugin::getDebugPlugin()); $email = 'isaac.brock'; $profile = new Profile(); $profile->setFirstName('Isaac'); $profile->setLastName('Brock'); $profile->setEmail($email); $profile->setLogin($email); $profile->setMobilePhone('555-415-1337'); $command = $client->getCommand('CreateUser', ['profile' => $profile, 'activate' => true]); try { $user = $command->execute(); } catch (ApiErrorException $e) { var_dump($e->getErrorId(), $e->getErrorCode(), $e->getErrorLink(), $e->getErrorSummary(), $e->getErrorCauses()); throw $e; }