/** * 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; }
/** * 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; }
/** * @param string $serviceDescription * @param array $config * @return \Guzzle\Service\Client */ public static function factory($config = array()) { if (!isset($config['serviceDescription'])) { throw new \Exception("Cannot create a twuzzle client without a service description"); } $oauthConfig = array(); if (!isset($config['consumerKey'])) { throw new \Exception("Cannot create an twuzzle client without a consumer key"); } else { $oauthConfig['consumer_key'] = $config['consumerKey']; } if (!isset($config['consumerSecret'])) { throw new \Exception("Cannot create an twuzzle client without a consumer secret"); } else { $oauthConfig['consumer_secret'] = $config['consumerSecret']; } if (isset($config['token']) && !empty($config['token'])) { $oauthConfig['token'] = $config['token']; } if (isset($config['tokenSecret']) && !empty($config['tokenSecret'])) { $oauthConfig['token_secret'] = $config['tokenSecret']; } $client = new self(); $client->setDescription(ServiceDescription::factory($config['serviceDescription'])); $oauth = new OauthPlugin($oauthConfig); $client->addSubscriber($oauth); return $client; }
/** * @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; }
/** * {@inheritdoc} */ public static function factory($config = array()) { $default = array('url' => false, 'munchkin_id' => false, 'version' => 1, 'bulk' => false); $required = array('client_id', 'client_secret', 'version'); $config = Collection::fromConfig($config, $default, $required); $url = $config->get('url'); if (!$url) { $munchkin = $config->get('munchkin_id'); if (!$munchkin) { throw new \Exception('Must provide either a URL or Munchkin code.'); } $url = sprintf('https://%s.mktorest.com', $munchkin); } $grantType = new Credentials($url, $config->get('client_id'), $config->get('client_secret')); $auth = new Oauth2Plugin($grantType); if ($config->get('bulk') === true) { $restUrl = sprintf('%s/bulk/v%d', rtrim($url, '/'), $config->get('version')); } else { $restUrl = sprintf('%s/rest/v%d', rtrim($url, '/'), $config->get('version')); } $client = new self($restUrl, $config); $client->addSubscriber($auth); $client->setDescription(ServiceDescription::factory(__DIR__ . '/service.json')); $client->setDefaultOption('headers/Content-Type', 'application/json'); return $client; }
public static function factory($config = array()) { // The following values are required when creating the client $required = array('base_url', 'username', 'password'); // Merge in default settings and validate the config $config = Collection::fromConfig($config, array(), $required); // Create a new sData client $client = new self($config->get('base_url'), $config); // JSON by default $client->setDefaultOption('query/format', 'json'); // Authentication $client->setDefaultOption('auth', array($config->get('username'), $config->get('password'), 'Basic')); // Strip the BOM from results $client->addSubscriber(new StripBomPlugin()); // Optional logging if ($config->get('log')) { $client->getEventDispatcher()->addListener('request.before_send', function (Event $event) { $req = $event['request']; \Log::info('sData', ['request' => $req->getMethod() . ' ' . $req->getResource()]); }); } // Set the service description $services = \Config::get('sdata::services'); if (!empty($services)) { $client->setDescription(ServiceDescription::factory($services)); } // Done return $client; }
/** * 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; }
/** * Factory Method to build new Client * * @param array $config * @return MeetupOAuthClient */ public static function factory($config = array()) { $configuration = static::buildConfig($config); $client = new self($configuration->get('base_url'), $configuration); $client->addSubscriber(new OauthPlugin(array('consumer_key' => $configuration->get('consumer_key'), 'consumer_secret' => $configuration->get('consumer_secret'), 'token' => $configuration->get('token'), 'token_secret' => $configuration->get('token_secret')))); static::loadDefinitions($client); static::toggleRateLimitingPlugin($client, $config); return $client; }
/** * Factory Method to build new Client * * @param array $config * @return MeetupKeyAuthClient */ public static function factory($config = array()) { $configuration = static::buildConfig($config); $client = new self($configuration->get('base_url'), $configuration); $client->addSubscriber(new KeyAuthPlugin($configuration->get('key'))); static::loadDefinitions($client); static::toggleRateLimitingPlugin($client, $config); return $client; }
public static function factory($config = array()) { $default = array(); $required = array('base_url', 'consumer_key', 'consumer_secret', 'token', 'token_secret'); $config = Collection::fromConfig($config, $default, $required); $client = new self($config->get('base_url'), $config); $client->addSubscriber(new OauthPlugin($config->toArray())); $client->setDescription(ServiceDescription::factory(__DIR__ . '/../service/basekit.json')); return $client; }
public static function factory($config = array()) { $resolver = new OptionsResolver(); static::setDefaultOptions($resolver); $config = $resolver->resolve($config); $client = new self($config['base_url'], array('request.options' => array('headers' => array('Content-Type' => 'application/json')))); $client->addSubscriber(new Plugin($config['application_key'], $config['application_secret'], $config['consumer_key'])); $client->setDescription(ServiceDescription::factory(realpath(__DIR__ . '/../../../config/description.json'))); return $client; }
public static function factory($config = array()) { $config = Collection::fromConfig($config, self::getDefaultConfig(), ['api_token', 'service_description']); $client = new self($config->get('base_url'), $config); $client->setDescription($client->getServiceDescriptionFromFile($config->get('service_description'))); $client->setDefaultOption('auth', [$config->get('api_token'), null, 'basic']); $client->addSubscriber($client); $client->setErrorHandler(); return $client; }
/** * Create an instance of the client * * @param array $config * * @return \GuzzleAmazonWebservices\ProductAdvertising */ public static function factory($config = array()) { $defaults = array('base_url' => '{{scheme}}://{{locale}}/onca/xml', 'scheme' => 'http', 'locale' => self::LOCALE_US, 'version' => self::VERSION); $required = array('access_key', 'secret_key', 'associate_tag'); $config = Inspector::prepareConfig($config, $defaults, $required); $signature = new SignatureV2($config->get('access_key'), $config->get('secret_key')); $client = new self($config->get('base_url'), $config->get('access_key'), $config->get('secret_key'), $config->get('associate_tag'), $config->get('version')); $client->setConfig($config); $client->addSubscriber(new SignaturePlugin($signature, $config->get('version'))); return $client; }
/** * Factory method to create a new BlimpClient * * The following array keys and values are available options: * - base_url: Base URL of web service * - username: API username * - password: API password * * @param array|Collection $config Configuration data * * @return self */ public static function factory($config = array()) { $default = array('base_url' => 'https://go.urbanairship.com/api/'); $required = array('base_url', 'appKey', 'appSecret'); $config = Collection::fromConfig($config, $default, $required); $client = new self($config->get('base_url'), $config); // Attach a service description to the client $description = ServiceDescription::factory(__DIR__ . '/service.php'); $client->setDescription($description); $client->addSubscriber(new CurlAuthPlugin($config->get('appKey'), $config->get('appSecret'))); return $client; }
public static function factory($config = array()) { $defaults = array('base_url' => 'https://api.twitter.com/{version}/', 'version' => '1.1'); $required = array('base_url', 'version', 'consumer_key', 'consumer_secret', 'token', 'token_secret'); $config = Collection::fromConfig($config, $defaults, $required); $client = new self($config->get('base_url'), $config); // Attach a service description to the client $description = ServiceDescription::factory(__DIR__ . '/client.json'); $client->setDescription($description); $client->addSubscriber(new OauthPlugin(array('consumer_key' => $config['consumer_key'], 'consumer_secret' => $config['consumer_secret'], 'token' => $config['token'], 'token_secret' => $config['token_secret']))); return $client; }
/** * 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; }
public static function factory($config = array()) { ParserRegistry::getInstance()->registerParser('uri_template', new MyrrixUriTemplate(ParserRegistry::getInstance()->getParser('uri_template'))); $default = array('base_url' => 'http://{hostname}:{port}', 'hostname' => 'localhost', 'port' => 8080, 'username' => null, 'password' => null); $required = array('hostname', 'port', 'base_url', 'username', 'password'); $config = Collection::fromConfig($config, $default, $required); $client = new self($config->get('base_url'), $config); $client->setDescription(ServiceDescription::factory(__DIR__ . DIRECTORY_SEPARATOR . 'service.json')); $client->setDefaultHeaders(array('Accept' => 'text/html')); $authPlugin = new CurlAuthPlugin($config['username'], $config['password']); $client->addSubscriber($authPlugin); 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; }
/** * @param array $config * @return Client */ public static function factory($config = array()) { $default = array('url' => self::DEFAULT_API_URL); $required = array('token'); $config = Collection::fromConfig($config, $default, $required); $config['curl.options'] = array(CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_0); $config['request.options'] = array('headers' => array('X-StorageApi-Token' => $config->get('token'))); $client = new self($config->get('url'), $config); // Attach a service description to the client $description = ServiceDescription::factory(__DIR__ . '/service.json'); $client->setDescription($description); $client->setBaseUrl($config->get('url')); // Setup exponential backoff $backoffPlugin = BackoffPlugin::getExponentialBackoff(); $client->addSubscriber($backoffPlugin); 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; }
/** * Factory method to create a new Client * * The following array keys and values are available options: * - url: Base URL of web service * - token: Storage API token * * @param array|Collection $config Configuration data * * @return self */ public static function factory($config = []) { $default = ['url' => 'https://syrup.keboola.com/gooddata-writer']; $required = ['token']; $config = Collection::fromConfig($config, $default, $required); $config['request.options'] = ['headers' => ['X-StorageApi-Token' => $config->get('token')], 'config' => ['curl' => [CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_0]]]; $client = new self($config->get('url'), $config); // Attach a service description to the client $description = ServiceDescription::factory(__DIR__ . '/service.json'); $client->setDescription($description); $client->setBaseUrl($config->get('url')); // Setup exponential backoff // 503 retry always, other errors five times $backoffPlugin = new BackoffPlugin(new TruncatedBackoffStrategy(5, new HttpBackoffStrategy(null, new CurlBackoffStrategy(null, new ExponentialBackoffStrategy())))); $client->addSubscriber($backoffPlugin); return $client; }
public static function factory($config = array()) { try { $default = array('base_url' => '{scheme}://{host}:{port}', 'scheme' => 'http', 'host' => 'localhost', 'port' => '8080', 'alfPath' => 'alfresco'); $required = array('username', 'password'); $config = Collection::fromConfig($config, $default, $required); $client = new self($config->get('base_url'), $config); $client->client = $client; $client->username = $config->get('username'); $client->password = $config->get('password'); $authPlugin = new CurlAuthPlugin('admin', 'geheim!'); $client->addSubscriber($authPlugin); $description = ServiceDescription::factory(__DIR__ . '/Description/Alfresco.json'); $client->setDescription($description); return $client; } catch (\Exception $e) { echo $e->getMessage(); } }
/** * Factory method to create a new HealthGraphClient * * @param array|Collection $config Configuration data. Array keys: * base_url - Base URL of web service * * @return HealthGraphClient * * @TODO update factory method and docblock for parameters */ public static function factory($config = array()) { $default = array('base_url' => 'https://api.runkeeper.com', 'logger' => FALSE); $required = array('base_url'); $config = Collection::fromConfig($config, $default, $required); $client = new self($config->get('base_url')); $client->setConfig($config); $client->setDescription(ServiceDescription::factory(__DIR__ . DIRECTORY_SEPARATOR . 'client.json')); // Set the iterator resource factory based on the provided iterators config $clientClass = get_class(); $prefix = substr($clientClass, 0, strrpos($clientClass, '\\')); $client->setResourceIteratorFactory(new HealthGraphIteratorFactory(array("{$prefix}\\Common\\Iterator"))); if ($config->get('logger')) { $adapter = new \Guzzle\Log\PsrLogAdapter($config->get('logger')); $logPlugin = new \Guzzle\Plugin\Log\LogPlugin($adapter, \Guzzle\Log\MessageFormatter::DEBUG_FORMAT); $client->addSubscriber($logPlugin); } return $client; }
/** * @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; }