コード例 #1
0
ファイル: FactoryTest.php プロジェクト: stefandoorn/Api
 public function testFactoryFrontend()
 {
     $result = \Voradius\ClientFrontendFactory::newInstance('http://test', 'api-key');
     $this->assertInstanceOf('\\GuzzleHttp\\Client', $result);
     $this->assertEquals($result->getBaseUrl(), 'http://test');
     $this->assertEquals($result->getDefaultOption('headers')['X-API-KEY'], 'api-key');
 }
コード例 #2
0
ファイル: Client.php プロジェクト: stefandoorn/Api
 /**
  * Client to use in several entities
  *
  * @param null $api_key
  * @param int $env
  */
 public function __construct($api_key = null, $env = self::LIVE, $part = self::PART_API)
 {
     if ($api_key === null) {
         throw new InvalidParameterException('API Key cannot be null');
     }
     if (!in_array($env, [self::LOCAL, self::LIVE, self::SANDBOX, self::STAGING])) {
         throw new ParameterNotAllowedException('Unknown environment');
     }
     if (!in_array($part, [self::PART_API, self::PART_FRONTEND])) {
         throw new ParameterNotAllowedException('Unknown part');
     }
     $this->setApiKey($api_key);
     $this->setEnv($env);
     switch ($part) {
         case 1:
             $this->_connection = ClientApiFactory::newInstance($this->getApiUrl(), $this->getApiKey());
             break;
         case 2:
             $this->_connection = ClientFrontendFactory::newInstance($this->getFrontendUrl(), $this->getApiKey());
             break;
     }
 }