示例#1
0
 /**
  * {@inheritDoc}
  */
 public static function factory($config = array())
 {
     $defaults = array('base_url' => 'https://www.mtxserv.fr/api/{version}/', 'version' => 'v1', 'grant_type' => 'https://www.mtxserv.fr/grants/api_key', 'has_authentification' => true, 'oauth2_token' => 'https://www.mtxserv.fr/oauth/v2/token');
     $required = array('client_id', 'client_secret', 'api_key');
     $config = Collection::fromConfig($config, $defaults, $required);
     $client = new self($config->get('base_url'), $config);
     // Set services descriptions
     $client->setDescription(ServiceDescription::factory(__DIR__ . '/Resources/product.php'));
     $client->setDescription(ServiceDescription::factory(__DIR__ . '/Resources/admin.php'));
     $client->setDescription(ServiceDescription::factory(__DIR__ . '/Resources/viewer.php'));
     $client->setDescription(ServiceDescription::factory(__DIR__ . '/Resources/game.php'));
     // Add authentification
     if ($config->get('has_authentification')) {
         $client->getEventDispatcher()->addListener('request.before_send', function (\Guzzle\Common\Event $event) use($config) {
             $event['request']->getQuery()->set('access_token', Client::retrieveAccessToken($config));
         });
     }
     // Set user agent
     $client->setUserAgent('mTxServ SDK PHP');
     return $client;
 }