Esempio n. 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;
 }
Esempio n. 2
0
 public function testFactoryInitializesUserAgent()
 {
     $client = Client::factory(array('client_id' => 'CLIENT_ID', 'client_secret' => 'CLIENT_SECRET', 'api_key' => 'API_KEY', 'version' => 'v1337'));
     $request = $client->get();
     $this->assertEquals('mTxServ SDK PHP', (string) $request->getHeader('User-Agent'));
 }