/** * Factory method to create a new S3 client * * @param array|Collection $config Configuration data. Array keys: * base_url - Base URL of web service. Default: {{scheme}}://{{region}}/ * scheme - Set to http or https. Defaults to http * region - AWS region. Defaults to s3.amazonaws.com * access_key - AWS access key ID. Set to sign requests. * secret_key - AWS secret access key. Set to sign requests. * * @return S3Client */ public static function factory($config) { $defaults = array('base_url' => '{{scheme}}://{{region}}/', 'region' => self::REGION_DEFAULT, 'scheme' => 'http'); $required = array('region', 'scheme'); $config = Inspector::prepareConfig($config, $defaults, $required); // Filter our the Timestamp and Signature query string values from cache $config->set('cache.key_filter', 'header=Date, Authorization; query=Timestamp, Signature'); // If an access key and secret access key were provided, then the client // requests will be authenticated if ($config->get('access_key') && $config->get('secret_key')) { $signature = new S3Signature($config->get('access_key'), $config->get('secret_key')); } $client = new self($config->get('base_url'), $config->get('access_key'), $config->get('secret_key'), null, $signature); $client->setConfig($config); // If signing requests, add the request signing plugin if ($signature) { $client->getEventManager()->attach(new SignS3RequestPlugin($signature), -99999); } // Retry 500 and 503 failures using exponential backoff $client->getEventManager()->attach(new ExponentialBackoffPlugin()); // If Amazon DevPay tokens were provided, then add a DevPay filter if ($config->get('devpay_user_token') && $config->get('devpay_product_token')) { // Add the devpay plugin pretty soon in the event emissions $client->getEventManager()->attach(new DevPayPlugin($config->get('devpay_user_token'), $config->get('devpay_product_token')), 9999); } return $client; }
/** * Get client instance * * @param array $config * * @return ProductAdvertisingClient */ public static function factory($config) { $defaults = array('base_url' => 'http://webservices.amazon.com/onca/xml?Service=AWSECommerceService', 'version' => self::VERSION); $required = array('access_key', 'secret_key'); $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('version'), $signature); $client->setConfig($config); // Sign the request last $client->getEventManager()->attach(new QueryStringAuthPlugin($signature, $config->get('version')), -9999); return $client; }
/** * Factory method to create a new SimpleDB client * * @param array|Collection $config Configuration data. Array keys: * base_url - Base URL of web service. Default: {{scheme}}://{{region}}/ * scheme - Set to http or https. Defaults to http * version - API version. Defaults to 2009-04-15 * region - AWS region. Defaults to sdb.amazonaws.com * * access_key - AWS access key ID * * secret_key - AWS secret access key * * @return CentinelClient */ public static function factory($config) { // Passed config, default config, and required configs $config = Inspector::prepareConfig($config, array('base_url' => '{{scheme}}://{{region}}/', 'version' => '2009-04-15', 'region' => self::REGION_DEFAULT, 'scheme' => 'http'), array('access_key', 'secret_key', 'region', 'version', 'scheme')); // Filter our the Timestamp and Signature query string values from cache $config->set('cache.key_filter', 'query=Timestamp, Signature'); $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('version'), $signature); $client->setConfig($config); // Sign the request last $client->getEventManager()->attach(new QueryStringAuthPlugin($signature, $config->get('version')), -9999); // Retry 500 and 503 failures using exponential backoff $client->getEventManager()->attach(new ExponentialBackoffPlugin()); return $client; }
/** * Factory method to create a new MWS client * * @param array|Collection $config Configuration data. Array keys: * base_url - Base URL of web service. Default: https://mws.amazonservices.com/ * version - API version. Defaults to 2009-02-01 * * access_key - AWS access key ID * * secret_key - AWS secret access key * * merchant_id - AWS merchant ID * * marketplace_id - AWS marketplace ID * application_name - Application name * application_version - Application version * * @return MwsClient */ public static function factory($config) { $defaults = array('base_url' => 'https://mws.amazonservices.fr/', 'version' => self::VERSION); $required = array('access_key', 'secret_key', 'merchant_id', 'marketplace_id', 'application_name', 'application_version'); $config = Inspector::prepareConfig($config, $defaults, $required); // Filter our the Timestamp and Signature query string values from cache $config->set('cache.key_filter', 'query=Timestamp, Signature'); $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('version'), $signature); $client->setConfig($config); // Sign the request last $client->getEventManager()->attach(new QueryStringAuthPlugin($signature, $config->get('version')), -9999); // Retry 500 and 503 failures, up to 3 times $client->getEventManager()->attach(new ExponentialBackoffPlugin(3, null, function ($try) { // @codeCoverageIgnoreStart return 60; // @codeCoverageIgnoreEnd })); // Throttle requests, no more than one per second $client->getEventManager()->attach(new ThrottlePlugin(1000)); return $client; }
/** * generates a Guzzle client **/ protected function init_client($config) { $default = array('base_url' => '{{scheme}}://api.{{domain}}/{{version}}/?appid={{appid}}&appkey={{appkey}}', 'scheme' => 'https', 'version' => '0.1', 'domain' => \PSU::isDev() ? 'dev.plymouth.edu' : 'plymouth.edu'); $required = array('appid', 'appkey', 'base_url'); $config = \Guzzle\Common\Inspector::prepareConfig($config, $default, $required); $client = new \Guzzle\Service\Client($config->get('base_url'), $config); $client->setConfig($config); return $client; }