Example #1
0
 public function testFactory()
 {
     $result = \Voradius\ClientFactory::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');
 }
Example #2
0
 /**
  * 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);
     $this->_connection = ClientFactory::newInstance($this->getUrl($this->getEnv(), $part), $this->getApiKey());
 }