public function __construct(array $options)
 {
     $options = Collection::fromConfig($options, self::$defaultOptions, self::$requiredOptions);
     $this->client = MeasurementProtocolClient::factory(array('ssl' => $options->get(self::OPT_SSL)));
     $this->registerPlugin(new DataSetter(array(HitInterface::FIELD_VERSION => 1, HitInterface::FIELD_TRACKING_ID => $options->get(self::OPT_TRACKING_ID))));
     $this->registerPlugins($options->get(self::OPT_PLUGINS));
 }
 public static function factory($config = array())
 {
     if (isset($config['developer_mode']) && is_bool($config['developer_mode'])) {
         $developerMode = $config['developer_mode'];
     } else {
         $developerMode = false;
     }
     $baseUrl = array('https://api.auspost.com.au', 'https://devcentre.auspost.com.au/myapi');
     // Ignore unnecessary user-specified configuration values
     if ($developerMode) {
         unset($config['email_address']);
         unset($config['password']);
     }
     unset($config['base_url']);
     $default = array('developer_mode' => $developerMode, 'base_url' => $baseUrl[$developerMode], 'email_address' => '*****@*****.**', 'password' => 'password');
     $required = array('developer_mode', 'base_url', 'email_address', "password");
     $config = Collection::fromConfig($config, $default, $required);
     $client = new self($config->get('base_url'), $config);
     $client->getConfig()->setPath('request.options/headers/Authorization', 'Basic ' . base64_encode($config->get('email_address') . ':' . $config->get('password')));
     $client->setDescription(ServiceDescription::factory(__DIR__ . '/service.json'));
     $client->setSslVerification(false);
     $client->getEventDispatcher()->addListener('request.before_send', function (Event $event) {
         $request = $event['request'];
         $request->addCookie('OBBasicAuth', 'fromDialog');
     });
     return $client;
 }
示例#3
0
 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;
 }
 /**
  * Gets Config Collection instance
  *
  * @param unknown $config
  * @return \Guzzle\Common\Collection
  */
 public static function getConfigCollection($config)
 {
     $default = array('base_url' => 'http://manage.encoding.com');
     $required = array('userid', 'userkey');
     $config = Collection::fromConfig($config, $default, array('base_url', 'userid', 'userkey'));
     return $config;
 }
示例#5
0
 public static function factory($config = array(), $required = array())
 {
     if (!defined('static::ENDPOINT')) {
         throw new Exception\ServiceEndpointException('A client must have an endpoint');
     }
     $default = array('base_url' => '{scheme}://{domain}/' . static::ENDPOINT);
     $required = array_merge(array('scheme', 'domain', 'base_url'), $required);
     $config = Collection::fromConfig($config, $default, $required);
     $client = new static($config->get('base_url'), $config);
     $refClass = new \ReflectionClass(get_called_class());
     $serviceDefinitionPath = dirname($refClass->getFileName());
     $classNamePieces = explode('\\', get_called_class());
     $serviceDefinitionFile = array_pop($classNamePieces) . '.json';
     switch (true) {
         case is_readable(dirname($serviceDefinitionPath) . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . $serviceDefinitionFile):
             $serviceDefinition = $serviceDefinitionPath . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . $serviceDefinitionFile;
             break;
         case is_readable($serviceDefinitionPath . DIRECTORY_SEPARATOR . $serviceDefinitionFile):
             $serviceDefinition = $serviceDefinitionPath . DIRECTORY_SEPARATOR . $serviceDefinitionFile;
             break;
         default:
             throw new Exception\ClientConfigurationException('A client must have a service definition. Could not read the file "' . $serviceDefinition . '"');
     }
     $description = ServiceDescription::factory($serviceDefinition);
     $client->setDescription($description);
     return $client;
 }
示例#6
0
 /**
  * @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;
 }
示例#7
0
 /**
  * Processes the configuration passed to self::factory()
  *
  * @param array|Guzzle\Common\Collection $config
  *
  * @return Guzzle\Common\Collection
  */
 public function processConfig($config)
 {
     $required = array('authentication');
     $default = array('api_version' => 2, 'base_url' => 'https://{subdomain}.desk.com/api/v{api_version}/');
     $baseUrl = $default['base_url'];
     if (isset($config['base_url'])) {
         $baseUrl = $config['base_url'];
     }
     // Subdomain is required, if the base URL is the default (not
     // set), or if it contains "{subdomain}" in it
     if (strpos($baseUrl, '{subdomain}') !== false) {
         $required[] = 'subdomain';
     }
     // Authentication is required, either OAuth or Basic
     // If none specified, try to autodetect it
     if (!isset($config['authentication'])) {
         if (isset($config['username']) && isset($config['password'])) {
             // If username and password are set, use basic auth
             $config['authentication'] = 'basic';
         } elseif (isset($config['consumer_key']) && isset($config['consumer_secret']) && isset($config['token']) && isset($config['token_secret'])) {
             // Otherwise, use OAuth if we have enough data
             $config['authentication'] = 'oauth';
         }
     }
     return Collection::fromConfig($config, $default, $required);
 }
示例#8
0
 /**
  * @param array $config
  * @param string $configSection
  */
 public function __construct($config, $configSection = null)
 {
     $this->endpoint = $this->getConfigurationItem($config, $configSection, "endpoint");
     $this->username = $this->getConfigurationItem($config, $configSection, "username");
     $this->password = $this->getConfigurationItem($config, $configSection, "password");
     $this->guzzleConfig = Collection::fromConfig(array("base_url" => $this->endpoint, "username" => $this->username, "password" => $this->password));
 }
示例#9
0
 /**
  * @param array $config
  */
 public function __construct(array $config = array())
 {
     $defaults = array('conf_dir' => 'conf', 'conf_files' => array());
     $required = array('conf_dir', 'conf_files');
     $this->config = \Guzzle\Common\Collection::fromConfig($config, $defaults, $required);
     $this->config['conf_dir'] = rtrim($this->config['conf_dir'], '/\\');
 }
示例#10
0
 /**
  * @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;
 }
 /**
  * @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;
 }
示例#12
0
 /**
  * {@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;
 }
示例#13
0
 public static function factory($config = array())
 {
     // provide a hash of default client configuration options
     $default = array('base_url' => 'http://127.0.0.1/', 'api_id' => 1, 'private_key' => 'fbdce19f94b158e72ae6020cc5126642a9d42d086419c015ad2b6dd429312410');
     // the following values are required when creating the client
     $required = array('base_url', 'api_id', 'private_key');
     // merge in default settings and validate the config
     $config = \Guzzle\Common\Collection::fromConfig($config, $default, $required);
     // create a new client
     $client = new self($config->get('base_url'), $config);
     $client->setDefaultOption('headers/API_ID', $config->get('api_id'));
     $client->getEventDispatcher()->addListener('client.create_request', function (\Guzzle\Common\Event $event) use($config) {
         // Guzzle\Http\Message\Request
         $data = $event['request']->getQuery();
         // Guzzle\Http\Message\EntityEnclosingRequest
         if ($event['request'] instanceof Guzzle\Http\Message\EntityEnclosingRequest) {
             $data->overwriteWith($event['request']->getPostFields());
         }
         $time = (string) time();
         $message = $time . $config->get('api_id') . implode($data->toArray());
         $hash = hash_hmac('sha256', $message, $config->get('private_key'));
         $event['request']->setHeader('API_TIME', $time)->setHeader('API_HASH', $hash);
         unset($data, $time, $message, $hash);
     });
     return $client;
 }
示例#14
0
 /**
  * {@inheritdoc}
  *
  * @return \Acquia\Network\AcquiaNetworkClient
  */
 public static function factory($config = array())
 {
     $defaults = array('base_url' => 'https://rpc.acquia.com', 'server_address' => isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '', 'http_host' => isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '', 'https' => false, 'network_id' => '', 'network_key' => '');
     // Instantiate the Acquia Search plugin.
     $config = Collection::fromConfig($config, $defaults);
     return new static($config->get('base_url'), $config->get('network_id'), $config->get('network_key'), $config);
 }
 public function __construct($baseUrl = '', $config = null)
 {
     $default = array();
     $required = array('apikey');
     $config = Collection::fromConfig($config, $default, $required);
     parent::__construct($baseUrl, $config);
 }
示例#16
0
 /**
  * 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;
 }
 /**
  * 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'));
     return $client;
 }
 /**
  * Basic factory method to create a new client. Extend this method in subclasses to build more complex clients.
  *
  * @param array|Collection $config Configuration data
  *
  * @return Client
  */
 public static function factory($config = array())
 {
     $defaults = array();
     $required = array('base_url', 'login', 'password');
     $config = Collection::fromConfig($config, $defaults, $required);
     $client = new self($config['base_url'], $config);
     return $client;
 }
 public static function factory($config = null)
 {
     $default = array('auth_token' => null, 'scheme' => 'http', 'base_url' => '{scheme}://{service}.3taps.com');
     $required = array('auth_token');
     $config = Collection::fromConfig($config, $default, $required);
     $services = array('services' => array('abstract_service' => array('params' => array('auth_token' => $config->get('auth_token'), 'base_url' => $config->get('base_url'), 'scheme' => $config->get('scheme'))), 'reference' => array('extends' => 'abstract_service', 'class' => 'Rbaker\\ThreeTaps\\Reference\\ReferenceClient', 'params' => array('service' => 'reference')), 'search' => array('extends' => 'abstract_service', 'class' => 'Rbaker\\ThreeTaps\\Search\\SearchClient', 'params' => array('service' => 'search')), 'polling' => array('extends' => 'abstract_service', 'class' => 'Rbaker\\ThreeTaps\\Polling\\PollingClient', 'params' => array('service' => 'polling'))));
     return ServiceBuilder::factory($services);
 }
 /**
  * {@inheritdoc}
  *
  * @return \Magento\Client\Xmlrpc\MagentoXmlrpcClient
  */
 public static function factory($config = array())
 {
     $defaults = array('session' => '');
     $required = array('base_url', 'api_user', 'api_key', 'session');
     // Instantiate the Acquia Search plugin.
     $config = Collection::fromConfig($config, $defaults, $required);
     return new static($config->get('base_url'), $config);
 }
示例#21
0
 /**
  * {@inheritdoc}
  *
  * @return self
  */
 public static function factory($config = array())
 {
     $default = array('base_url' => '{scheme}://itunes.apple.com/{country}/', 'scheme' => 'https', self::CURL_OPTIONS => array(CURLOPT_ENCODING => 'gzip'));
     $required = array('country');
     $config = Collection::fromConfig($config, $default, $required);
     $client = new static($config->get('base_url'), $config);
     return $client;
 }
 /**
  * Factory method to create the HttpClient
  *
  * The following array keys and values are available options:
  * - url     : Base URL of web service
  * - port    : Port of web service
  * - scheme  : URI scheme: http or https
  * - username: API username
  * - password: API password
  *
  * @param array|Collection $options Configuration data
  *
  * @return self
  */
 public static function factory($options = array())
 {
     $default = array('base_url' => '{scheme}://{username}:{password}@{host}:{port}', 'scheme' => 'http', 'username' => 'guest', 'password' => 'guest', 'port' => '15672');
     $required = array('username', 'password', 'host', 'base_url');
     $config = Collection::fromConfig($options, $default, $required);
     $client = new self($config->get('base_url'), $config);
     return $client;
 }
 /**
  * Factory method to create a new PredictionIOClient
  *
  * Configuration data is an array with these keys:
  * * appkey - App key of your PredictionIO app (required)
  * * apiurl - URL of API endpoint (optional)
  *
  * @param array|Collection $config Configuration data.
  *
  * @return PredictionIOClient
  */
 public static function factory($config = array())
 {
     $default = array('apiurl' => 'http://localhost:8000');
     $required = array('appkey');
     $config = Collection::fromConfig($config, $default, $required);
     $client = new self($config->get('apiurl'), $config);
     return $client;
 }
 /**
  * Initialization function.
  * Here a config array must be passed with the client configuration
  * Sensible values are set by default, but further configuration could also
  * be set.
  *
  * A list of required fields is also set (with no default value set)
  */
 public static function init($config = array())
 {
     $default = array('base_url' => '{scheme}://{hostname}:{port}/api/{version}/{client_endpoint}', 'scheme' => 'http', 'hostname' => 'localhost', 'port' => 9292, 'version' => 'v1', 'includes_json_root' => true, 'json_root' => 'subject');
     $required = array('client_endpoint', 'subclient_endpoint');
     $config = Collection::fromConfig($config, $default, $required);
     static::$client = new Client($config->get('base_url'), $config);
     static::$initialized = true;
 }
示例#25
0
 public function build()
 {
     $config = Collection::fromConfig($this->config, array('base_url' => self::BASE_URL_DEFAULT), array('base_url', 'key', 'secret'));
     $serviceName = substr($this->clientNamespace, strrpos($this->clientNamespace, '\\') + 1);
     $clientClass = $this->clientNamespace . '\\' . $serviceName . 'Client';
     /** @var \Guzzle\Service\ClientInterface $client */
     $client = new $clientClass(new Credentials($config->get('key'), $config->get('secret')), new Signature(), $config);
     return $client;
 }
 /**
  * {@inheritdoc}
  *
  * @return static
  */
 public static function factory($config = array())
 {
     $default = array('base_url' => 'https://graph.facebook.com/');
     $config = Collection::fromConfig($config, $default, array());
     $client = new static($config->get('base_url'), $config);
     $description = ServiceDescription::factory(__DIR__ . '/Resources/client.json');
     $client->setDescription($description);
     return $client;
 }
示例#27
0
 /**
  * {@inheritdoc}
  */
 public function __construct($baseUrl = '', $config = null)
 {
     $default = array();
     $required = array('username', 'password');
     $config = Collection::fromConfig($config, $default, $required);
     parent::__construct($baseUrl, $config);
     $this->setDescription(ServiceDescription::factory(__DIR__ . DIRECTORY_SEPARATOR . 'client.json'));
     $this->addSubscriber(new CurlAuthPlugin($config->get('username'), $config->get('password')));
 }
 public static function factory($config = array())
 {
     $config = Collection::fromConfig($config, array(), array());
     $client = new self($config->get('base_url'), $config);
     // Attach a service description to the client
     $description = ServiceDescription::factory(__DIR__ . '/client.json');
     $client->setDescription($description);
     return $client;
 }
示例#29
0
 /**
  * @param	String	$service_url	Service URL
  * @param	Array	$config		Configuration array containing these parameters:
  *  - string    'private_key'   The API private key from your account
  *  - string    'public_key'    The API public key from your account     
  */
 public function __construct($service_url = '', $config = array())
 {
     $config = Collection::fromConfig($config, array('api_path' => '/api/v3'), array('private_key', 'public_key'));
     parent::__construct($service_url . $config['api_path'], $config);
     $description = ServiceDescription::factory(__DIR__ . '/client.json');
     $this->setDescription($description);
     $ModerationSignature = new ModerationSignature(array('private_key' => $config['private_key'], 'public_key' => $config['public_key']));
     $this->addSubscriber($ModerationSignature);
 }
 /**
  * Creates a basic 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('app_id'), $config->get('api_key'));
     $client->setUserAgent('intercom-php/1.4.0', true);
     return $client;
 }