本文整理汇总了PHP中self::setUserAgent方法的典型用法代码示例。如果您正苦于以下问题:PHP self::setUserAgent方法的具体用法?PHP self::setUserAgent怎么用?PHP self::setUserAgent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类self
的用法示例。
在下文中一共展示了self::setUserAgent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: factory
/**
* @param array $config
* @return \Guzzle\Service\Client|BasecampClient
* @throws \Guzzle\Common\Exception\InvalidArgumentException
*/
public static function factory($config = array())
{
$default = array('base_url' => 'https://basecamp.com/{user_id}/api/{version}/', 'version' => 'v1', 'auth' => 'http', 'token' => null, 'username' => null, 'password' => null);
$required = array('user_id', 'app_name', 'app_contact');
$config = Collection::fromConfig($config, $default, $required);
$client = new self($config->get('base_url'), $config);
if ($config['auth'] === 'http') {
if (!isset($config['username'], $config['password'])) {
throw new InvalidArgumentException("Config must contain username and password when using http auth");
}
$authorization = 'Basic ' . base64_encode($config['username'] . ':' . $config['password']);
}
if ($config['auth'] === 'oauth') {
if (!isset($config['token'])) {
throw new InvalidArgumentException("Config must contain token when using oauth");
}
$authorization = sprintf('Bearer %s', $config['token']);
}
if (!isset($authorization)) {
throw new InvalidArgumentException("Config must contain valid authentication method");
}
// Attach a service description to the client
$description = ServiceDescription::factory(__DIR__ . '/Resources/service.php');
$client->setDescription($description);
// Set required User-Agent
$client->setUserAgent(sprintf('%s (%s)', $config['app_name'], $config['app_contact']));
$client->getEventDispatcher()->addListener('request.before_send', function (Event $event) use($authorization) {
$event['request']->addHeader('Authorization', $authorization);
});
return $client;
}
示例2: factory
/**
* @param array $config
* @return \Guzzle\Service\Client|ImageRelayClient
* @throws \Guzzle\Common\Exception\InvalidArgumentException
*/
public static function factory($config = array())
{
$default = array('base_url' => 'https://{imagerelay_url}/api/v2/', 'imagerelay_url' => 'subdomain.imagerelay.com');
$config = Collection::fromConfig($config, $default);
$client = new self($config->get('base_url'), $config);
if ($config['auth'] === 'http') {
if (!isset($config['username'], $config['password'])) {
throw new InvalidArgumentException("Username and password required when using http auth.");
}
$authorization = 'Basic ' . base64_encode($config['username'] . ':' . $config['password']);
}
if ($config['auth'] === 'oauth') {
if (!isset($config['token'])) {
throw new InvalidArgumentException("Access token required when using oauth.");
}
$authorization = sprintf('Bearer %s', $config['token']);
}
if (!isset($authorization)) {
throw new InvalidArgumentException("Must use either http or oauth authentication method.");
}
// Attach a service description to the client
$description = ServiceDescription::factory(__DIR__ . '/Resources/api.php');
$client->setDescription($description);
// Set required User-Agent
$client->setUserAgent(sprintf('%s (%s)', $config['app_name'], $config['app_contact']));
$client->getEventDispatcher()->addListener('request.before_send', function (Event $event) use($authorization) {
$event['request']->addHeader('Authorization', $authorization);
});
return $client;
}
示例3: factory
/**
* @param array $config
* @return \Guzzle\Service\Client|BasecampClient
* @throws \Guzzle\Common\Exception\InvalidArgumentException
*/
public static function factory($config = array())
{
$default = array('base_url' => 'https://basecamp.com/', 'version' => 'v1', 'token' => null, 'user_agent' => null, 'auth_method' => 'oauth');
$required = [];
$config = Collection::fromConfig($config, $default, $required);
$client = new self($config->get('base_url'), $config);
if (empty($config['token'])) {
throw new InvalidArgumentException("Config must contain token when using oath");
}
$authorization = sprintf('Bearer %s', $config['token']);
if (!isset($authorization)) {
throw new InvalidArgumentException("Config must contain valid authentication method");
}
// Attach a service description to the client
$description = ServiceDescription::factory(__DIR__ . '/Resources/service.php');
$client->setDescription($description);
// Set required User-Agent
$client->setUserAgent($config['user_agent']);
$client->getEventDispatcher()->addListener('request.before_send', function (Event $event) use($authorization) {
$event['request']->addHeader('Authorization', $authorization);
});
// Add cache plugin
$cachePlugin = new CachePlugin(['storage' => new DefaultCacheStorage(new DoctrineCacheAdapter(new ApcCache()))]);
$client->addSubscriber($cachePlugin);
return $client;
}
示例4: factory
/**
* Factory method to create the client, add the service description, and set
* the user again
*
* @param array $config
*
* @return Client
*/
public static function factory($config = array())
{
$client = new self();
$description = ServiceDescription::factory(__DIR__ . '/Config/endpoints.json');
$client->setDescription($description);
$client->setUserAgent('Shelf/' . Version::VERSION, true);
return $client;
}
示例5: factory
/**
* Creates a basic auth client with the supplied configuration options
*
* @param array $config
* @return Client|IntercomBasicAuthClient
*/
public static function factory($config = [])
{
$client = new self();
$config = Collection::fromConfig($config, $client->getDefaultConfig(), static::$required);
$client->configure($config);
$client->setBasicAuth($config->get('app_id'), $config->get('api_key'));
$client->setUserAgent('intercom-php/1.2.3', true);
return $client;
}
示例6: factory
/**
* Creates a basic auth client with the supplied configuration options
*
* @param array $config
* @return Client|TestFairyBasicAuthClient
*/
public static function factory($config = array())
{
$client = new self();
$config = Collection::fromConfig($config, $client->getDefaultConfig(), static::$required);
$client->configure($config);
$client->setBasicAuth($config->get('email'), $config->get('api_key'));
$client->setUserAgent('testfairy-php/1.0.0', true);
return $client;
}
示例7: factory
/**
* Creates a client token auth client with the supplied configuration options
*
* @param array $config
* @return Client|IntercomBasicAuthClient
*/
public static function factory($config = array())
{
$client = new self();
$config = Collection::fromConfig($config, $client->getDefaultConfig(), static::$required);
$client->configure($config);
$client->setBasicAuth($config->get('client_uuid'), $config->get('client_key'));
$client->setUserAgent('intercom-php/1.4.0', true);
$client->setDefaultOption('query/app_id', $config->get('app_id'));
return $client;
}
示例8: factory
/**
* {@inheritDoc}
*/
public static function factory($config = array())
{
$defaultOptions = array('base_url' => '{scheme}://{hostname}', 'hostname' => 'api.mgrt.net', 'scheme' => 'https');
$requiredOptions = array('public_key', 'private_key');
$config = Collection::fromConfig($config, $defaultOptions, $requiredOptions);
$description = ServiceDescription::factory(__DIR__ . '/Resources/service.php');
$client = new self($config->get('base_url'), $config);
$client->setDefaultOption('auth', array($config['public_key'], $config['private_key'], 'Basic'));
$client->setDescription($description);
$client->setUserAgent(sprintf('mgrt-php/%s guzzle/%s PHP/%s', \Mgrt\Version::VERSION, \Guzzle\Common\Version::VERSION, PHP_VERSION));
return $client;
}
示例9: factory
/**
* Factory method to create a new MediawikiApiClient
*
* @param array|Collection $config Configuration data. Array keys:
* base_url - Base URL of web service
*
* @throws InvalidArgumentException
* @return MediawikiApiClient
*/
public static function factory($config = array())
{
$required = array('base_url');
$config = Collection::fromConfig($config, array(), $required);
$client = new self($config->get('base_url'));
$cookiePlugin = new CookiePlugin(new ArrayCookieJar());
$client->addSubscriber($cookiePlugin);
$client->setConfig($config);
$client->setUserAgent('addwiki-guzzle-mediawiki-client');
$client->setDescription(ServiceDescription::factory(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'mediawiki.json'));
return $client;
}
示例10: factory
/**
* Factory method to create a new Swagger Docs client.
* @param array|Collection $config Configuration data
* @return SwaggerClient
*/
public static function factory($config = array())
{
// no default base url, but must be passed
$default = array();
$required = array('base_url');
// Merge in default settings and validate the config
$config = Collection::fromConfig($config, $default, $required);
// Create a new instance of self
$client = new self($config->get('base_url'), $config);
// describe service from JSON file.
$service = ServiceDescription::factory(__DIR__ . '/Resources/service.json');
// Prefix Loco identifier to user agent string
$client->setUserAgent($service->getName() . '/' . $service->getApiVersion(), true);
return $client->setDescription($service);
}
示例11: factory
/**
* @param array $config
* @return SistrixClient
* @throws \Guzzle\Common\Exception\InvalidArgumentException
*/
public static function factory($config = array())
{
$default = array('base_url' => 'http://api.sistrix.net/', 'format' => 'json');
$required = array('api_key');
foreach ($required as $value) {
if (empty($config[$value])) {
throw new InvalidArgumentException("Argument '{$value}' must not be blank.");
}
}
$config = Collection::fromConfig($config, $default, $required);
$client = new self($config->get('base_url'), $config);
$client->setDefaultOption('query', array('api_key' => $config->get('api_key'), 'format' => $config->get('format')));
$client->setDescription(ServiceDescription::factory(__DIR__ . '/Resources/ServiceDescriptionSistrix.json'));
$client->setUserAgent('OnlineMarketingApiToolkit');
return $client;
}
示例12: factory
public static function factory($config = [])
{
$client = new self();
$config = Collection::fromConfig($config, $client->getDefaultConfig(), static::$required);
$client->configure($config);
$client->setUserAgent(self::USER_AGENT, true);
self::$consumer_key = $config->get('consumer_key');
self::$consumer_secret = $config->get('consumer_secret');
self::$application_name = $config->get('application_name');
// add a listener to alter every requests and authenticate them through Semantria weird oAuth
$client->getEventDispatcher()->addListener('command.before_send', function (Event $event) use($client) {
$command = $event['command'];
$request = $client->oAuthRequest($command->getRequest());
});
return $client;
}
示例13: factory
/**
* @param array $config
* @return MozClient
* @throws \Guzzle\Common\Exception\InvalidArgumentException
*/
public static function factory($config = array())
{
$default = array('base_url' => 'http://lsapi.seomoz.com', 'expiresSeconds' => '3600');
$required = array('AccessID', 'SecretKey');
foreach ($required as $value) {
if (empty($config[$value])) {
throw new InvalidArgumentException("Argument '{$value}' must not be blank.");
}
}
$config = Collection::fromConfig($config, $default, $required);
$credentials = self::calculateCredentials($config->get('AccessID'), $config->get('SecretKey'), $config->get('expiresInterval'));
$client = new self($config->get('base_url'), $config);
$client->setDefaultOption('query', array('AccessID' => $config->get('AccessID'), 'Expires' => $credentials['expires'], 'Signature' => $credentials['signature']));
$client->setDescription(ServiceDescription::factory(__DIR__ . '/Resources/ServiceDescriptionMoz.json'));
$client->setUserAgent('OnlineMarketingApiToolkit');
return $client;
}
示例14: factory
/**
* @param array $config
* @return SeokicksClient
* @throws \Guzzle\Common\Exception\InvalidArgumentException
*/
public static function factory($config = array())
{
$default = array("base_url" => "http://www.seokicks.de/SEOkicksService/V1/");
$required = array('appid');
foreach ($required as $value) {
if (empty($config[$value])) {
throw new InvalidArgumentException("Argument '{$value}' must not be blank.");
}
}
$config = Collection::fromConfig($config, $default, $required);
$client = new self($config->get('base_url'), $config);
$client->setDefaultOption('query', array('appid' => $config['appid']));
$client->setDescription(ServiceDescription::factory(__DIR__ . '/Resources/ServiceDescriptionSeokicks.json'));
$client->setUserAgent('OnlineMarketingApiToolkit');
/*
* Seokicks send javascript and not json as response
*/
$plugin = new ForceContenttypePlugin();
$client->addSubscriber($plugin);
return $client;
}
示例15: factory
/**
* {@inheritDoc}
*/
public static function factory($config = array())
{
$defaults = array('base_url' => 'https://www.mtxserv.fr/api/{version}/', 'version' => 'v1', 'grant_type' => 'https://www.mtxserv.fr/grants/api_key', 'has_authentification' => true, 'oauth2_token' => 'https://www.mtxserv.fr/oauth/v2/token');
$required = array('client_id', 'client_secret', 'api_key');
$config = Collection::fromConfig($config, $defaults, $required);
$client = new self($config->get('base_url'), $config);
// Set services descriptions
$client->setDescription(ServiceDescription::factory(__DIR__ . '/Resources/product.php'));
$client->setDescription(ServiceDescription::factory(__DIR__ . '/Resources/admin.php'));
$client->setDescription(ServiceDescription::factory(__DIR__ . '/Resources/viewer.php'));
$client->setDescription(ServiceDescription::factory(__DIR__ . '/Resources/game.php'));
// Add authentification
if ($config->get('has_authentification')) {
$client->getEventDispatcher()->addListener('request.before_send', function (\Guzzle\Common\Event $event) use($config) {
$event['request']->getQuery()->set('access_token', Client::retrieveAccessToken($config));
});
}
// Set user agent
$client->setUserAgent('mTxServ SDK PHP');
return $client;
}