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; }
/** * Static factory method used to turn an array or collection of configuration data into an instantiated object. * * @param array|Collection $config Configuration data * @return KinveyClient */ public static function factory($config = array()) { $client = new self($config['baseURL'], $config); $client->setDefaultOption('headers/Content-Type', 'application/json'); $client->setDefaultOption('X-Kinvey-API-Version', 2); $client->setAuthMode($config['defaultAuthMode']); $client = self::registerPlugins($client); return $client; }
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; }
/** * {@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; }
/** * Creates a client token 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('client_uuid'), $config->get('client_key')); $client->setDefaultOption('query/app_id', $config->get('app_id')); return $client; }
/** * 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; }
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; }
/** * Factory method to create a new Bitpay client * * @param array $config * * @return BitpayClient */ public static function factory($config = array()) { $default = array('base_url' => 'https://bitpay.com/api'); $required = array('apiKey'); $config = Collection::fromConfig($config, $default, $required); $client = new self($config->get('base_url'), $config); $client->setDescription(ServiceDescription::factory(__DIR__ . DIRECTORY_SEPARATOR . 'client.json')); $client->setDefaultOption('auth', array($config['apiKey'], '', 'Basic')); return $client; }
public static function factory($config = array()) { $default = array('base_url' => ''); $required = array('base_url', 'scheme', 'auth_token', 'service'); $config = Collection::fromConfig($config, $default, $required); $client = new self($config->get('base_url'), $config); $description = ServiceDescription::factory(__DIR__ . '/Resources/search.json'); $client->setDescription($description); $client->setDefaultOption('query', array('auth_token' => $config->get('auth_token'))); return $client; }
/** * {@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; }
/** * Factory method to create the client * * @param array $config * @return Client|SparkreelClient */ public static function factory($config = array()) { $default = array('base_url' => '{scheme}://{hostname}/v1', 'scheme' => 'https', 'hostname' => 'api.sparkreel.com'); $required = array('base_url', 'api_key'); $config = Collection::fromConfig($config, $default, $required); $client = new self($config->get('base_url'), $config); // set X-API-Key header $client->setDefaultOption('headers/X-API-Key', $config->get('api_key')); // Attach a service description to the client $description = ServiceDescription::factory(__DIR__ . '/Resources/v0.json'); $client->setDescription($description); return $client; }
/** * Factory method to create the client * * @param array $config * @return Client */ public static function factory($config = array()) { $default = array('base_url' => '{scheme}://{hostname}/oauth', 'scheme' => 'https', 'hostname' => 'www.sparkreel.com'); $required = array('base_url', 'client_id', 'client_secret'); $config = Collection::fromConfig($config, $default, $required); $client = new self($config->get('base_url'), $config); // Attach a service description to the client $description = ServiceDescription::factory(dirname(__DIR__) . '/Resources/OAuth2.json'); $client->setDescription($description); // send client_id & client_secret as Basic auth $client->setDefaultOption('auth', array($config->get('client_id'), $config->get('client_secret'), 'Basic')); return $client; }
public static function factory($config = array()) { $default = array('host' => 'api.trak.io/v1', 'https' => true); $config = array_merge($config, $default); $required = array('token', 'host', 'https'); self::validate($required, $config); $config = Collection::fromConfig($config, $default, $required); $client = new self(($config->get('https') ? 'https://' : 'http://') . $config->get('host'), $config); $client->setDefaultOption('headers/X-Token', $config->get('token')); $config->hasKey('distinct_id') ? $client->distinct_id($config->get('distinct_id')) : null; $config->hasKey('channel') ? $client->channel($config->get('channel')) : null; $client->setDescription(ServiceDescription::factory(__DIR__ . '/Resources/config/client.json')); return $client; }
public static function factory($config = array()) { // Provide a hash of default client configuration options $default = array('base_url' => 'https://maps.googleapis.com/maps/api/place'); // The following values are required when creating the client $required = array('key'); // Merge in default settings and validate the config $config = Collection::fromConfig($config, $default, $required); // Create a new Google Places API Client $client = new self($config->get('base_url'), $config); $client->setDefaultOption('query', array('key' => $config['key'], 'language' => $config['language'])); // Set the service description $client->setDescription(ServiceDescription::factory(__DIR__ . '/../config/service_description.json')); return $client; }
public static function factory($config = array()) { $default = array('base_url' => 'https://api.foursquare.com/v2/'); $required = array('client_id', 'client_secret'); 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('client_id' => $config['client_id'], 'client_secret' => $config['client_secret'], 'v' => '20130707')); $client->setDescription(ServiceDescription::factory(__DIR__ . '/../Resources/config/client.json')); return $client; }
/** * @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; }
/** * Factory to create new instance. * * @param array $config * * @returns \Staades\StaadesClient */ public static function factory($config = array()) { // Provide a hash of default client configuration options $default = array('base_url' => 'http://api.staades.net/{version}/', 'version' => '2.0'); // The following values are required when creating the client $required = array('base_url', 'app_key', 'api_key'); // Merge in default settings and validate the config $config = Collection::fromConfig($config, $default, $required); // Create a new Staades client $client = new self($config->get('base_url'), $config); $file = 'staades_api_2_0.php'; $client->setDescription(ServiceDescription::factory(__DIR__ . "/Resources/{$file}")); // Set the content type header to use "application/json" for all requests $client->setDefaultOption('headers', array('Content-Type' => 'application/json')); return $client; }
/** * @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; }
public static function factory($opts = array()) { $default = array('sandbox' => true, 'xsd' => true); $required = array('sandbox', 'user', 'pass'); $config = Collection::fromConfig($opts, $default, $required); if ($config->get('xsd') === true) { $config->set('xsd', file_get_contents(__DIR__ . '/Resources/schema.xsd')); } if ($config->get('sandbox') === true) { $baseUrl = 'https://exttest.cybertip.org/ispws/'; } else { $baseUrl = 'https://report.cybertip.org/ispws/.'; } $client = new self($baseUrl, $config); $client->setDefaultOption('auth', array($config['user'], $config['pass'], 'Any')); $client->getConfig()->set('curl.options', array('body_as_string' => true)); $description = ServiceDescription::factory(__DIR__ . '/Resources/service.php'); $client->setDescription($description); $client->getEventDispatcher()->addListener('command.after_prepare', array($client, 'onCommandAfterPrepare')); 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; }
/** * Factory to create new KeenIOClient instance. * * @param array $config * * @returns \KeenIO\Client\KeenIOClient */ public static function factory($config = array()) { $default = array('baseUrl' => 'https://api.keen.io/{version}/', 'version' => '3.0', 'masterKey' => null, 'writeKey' => null, 'readKey' => null, 'projectId' => null); // Create client configuration $config = self::parseConfig($config, $default); $config = Collection::fromConfig($config, $default); // Because each API Resource uses a separate type of API Key, we need to expose them all in // `commands.params`. Doing it this way allows the Service Definitions to set what API Key is used. $parameters = array(); foreach (array('masterKey', 'writeKey', 'readKey') as $key) { $parameters[$key] = $config->get($key); } $config->set('command.params', $parameters); // Create the new Keen IO Client with our Configuration $client = new self($config->get('baseUrl'), $config); // Set the Service Definition from the versioned file $file = 'keen-io-' . str_replace('.', '_', $client->getConfig('version')) . '.php'; $client->setDescription(ServiceDescription::factory(__DIR__ . "/Resources/{$file}")); // Set the content type header to use "application/json" for all requests $client->setDefaultOption('headers', array('Content-Type' => 'application/json')); return $client; }
/** * Factory to create new GiantBombClient instance. * * @param array $config * * @returns \GiantBomb\Client\GiantBombClient */ public static function factory($config = array()) { $default = array('baseUrl' => "http://www.giantbomb.com/", 'version' => '1.0', 'apiKey' => null, 'format' => 'json', 'limit' => 100, 'offset' => 0, 'cache' => null); // Validate the configuration options self::validateConfig($config); // Create client configuration $config = Collection::fromConfig($config, $default); // Create the new GiantBomb Client with our Configuration $client = new self($config->get('baseUrl'), $config); if ($config->get('cache') !== null) { $client->createCache($config->get('cache')); } // Set the Service Definition from the versioned file $file = 'giant-bomb-' . str_replace('.', '_', $client->getConfig('version')) . '.json'; $client->setDescription(ServiceDescription::factory(__DIR__ . "/../Resources/config/{$file}")); $parameters = array(); foreach (array('apiKey', 'format') as $key) { $parameters[$key] = $config->get($key); } $config->set('command.params', $parameters); $client->setDefaultOption('query', array('api_key' => $config->get('apiKey'), 'format' => $config->get('format'), 'limit' => $config->get('limit'), 'offset' => $config->get('offset'))); return $client; }
/** * @param array $config * @return StrucrClient * @throws \Guzzle\Common\Exception\InvalidArgumentException */ public static function factory($config = array()) { $default = array('base_url' => 'https://api.strucr.com/1.0/'); $required = array('user', 'password'); 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('auth', array($config->get('user'), $config->get('password'), 'Basic')); $client->setDescription(ServiceDescription::factory(__DIR__ . '/Resources/ServiceDescriptionStrucr.json')); $client->setUserAgent('OnlineMarketingApiToolkit'); return $client; }