コード例 #1
0
 /**
  * Constructor
  *
  * You must pass the OpenStack's options for the authentication
  *
  * @param  array $options
  * @param  HttpClient $httpClient
  * @throws Exception\InvalidArgumentException
  */
 public function __construct(array $options, HttpClient $httpClient = null)
 {
     $this->setOptions($options);
     $this->api = new Api($httpClient);
     $this->api->setApiPath(__DIR__ . '/api/identity');
     $this->api->setQueryParams(array('format' => 'json'));
     $this->api->setUrl($this->options['url']);
     $username = isset($options['user']) ? $options['user'] : $options['username'];
     if (isset($options['password'])) {
         if (!$this->auth($username, $options['password'])) {
             throw new Exception\RuntimeException('Authentication failed, please check the username and password provided');
         }
     } else {
         if (!$this->auth($username, null, $options['key'])) {
             throw new Exception\RuntimeException('Authentication failed, please check the username and the API\'s key provided');
         }
     }
     $this->api->resetLastResponse();
 }
コード例 #2
0
 /**
  * Constructor
  *
  * @param null|string $accessKey
  *            Access Key
  * @param null|string $secretKey
  *            Secret Key
  * @param null|HttpClient $httpClient
  */
 public function __construct($accessKey = null, $secretKey = null, ZendServiceApi $api = null, HttpClient $httpClient = null)
 {
     $this->setKeys($accessKey, $secretKey);
     if (null === $httpClient) {
         $httpClient = new HttpClient();
         $adapter = new HttpClient\Adapter\Curl();
         $adapter->setCurlOption(CURLOPT_USERPWD, $accessKey . ':' . $secretKey);
         $httpClient->setAdapter($adapter);
     }
     if (null === $api) {
         $api = new ZendServiceApi($httpClient);
     }
     if (!$this->resultSetPrototype instanceof ResultSetInterface) {
         $this->resultSetPrototype = new ResultSet(new ClassMethods(false), new ArrayObject());
     }
     $defaultApiQueryParams = array('format' => 'json');
     $api->setQueryParams($defaultApiQueryParams);
     $this->api = $api;
     $this->setUrl(static::API_BASE_URI);
     /*$this->setUrl(static::API_BASE_URI . '/' . $this->name);
     
             if ('apikey' !== $this->name ) {
                 $this->api->setQueryParams(array_merge(
                     $defaultApiQueryParams,
                     array(
                         'akid' => $this->getAkid() //TODO TO REMOVE AFTER TEST
                     )
                 ));
             }*/
     $this->init();
 }