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; }
/** * Parses a template file and declares view variables in this scope for the * template to have access to them. Loads localized templates based on the current * active locale. * @param string The name of the template to load * @param array an associative array of values to assign in the template * @param string The file extension of the template to be loaded * @return string The parsed html. */ public static function parse($path, $variables = array(), $extension = '.php', $allowDebug = true) { $tpl = new self(); $tpl->injectVariables($variables); $tpl->setViewName($path); $tpl->setConfig("file_extention", $extension); if (!(bool) $tpl->getConfig("allow_debug")) { $tpl->setConfig("allow_debug", false); } else { $tpl->setConfig("allow_debug", $allowDebug); } return $tpl->compile(); }
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://auspost.com.au', 'https://test.npe.auspost.com.au'); // Ignore unnecessary user-specified configuration values if ($developerMode) { unset($config['auth_key']); } unset($config['base_url']); $default = array('developer_mode' => $developerMode, 'base_url' => $baseUrl[$developerMode], 'auth_key' => '28744ed5982391881611cca6cf5c2409'); $required = array('developer_mode', 'base_url', 'auth_key'); $config = Collection::fromConfig($config, $default, $required); $client = new self($config->get('base_url'), $config); $client->getConfig()->setPath('request.options/headers/Accept', 'application/json'); $client->getConfig()->setPath('request.options/headers/Auth-Key', $config->get('auth_key')); $client->setDescription(ServiceDescription::factory(__DIR__ . '/service.json')); $client->setSslVerification(false); 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; }
/** * 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; }