示例#1
0
文件: Cloudyn.php 项目: mheydt/scalr
 /**
  * Makes api request
  *
  * @param   string     $qid     The id of the query.
  * @param   array      $options optional Query options for the request.
  * @param   string     $path    optional Uri path for the request (/user by default)
  * @param   string     $method  optional Http method (GET by default)
  * @return  object     Returns object that is an response data.
  * @throws  CloudynException
  */
 public function call($qid, array $options = array(), $path = '/user', $method = 'GET')
 {
     $options['qid'] = (string) $qid;
     $options['out'] = self::OUT_JSON;
     if (!isset($options['rqid'])) {
         $options['rqid'] = $this->getRequestId();
     }
     if (!isset($options['apiversion'])) {
         $options['apiversion'] = '0.4';
     }
     $this->request = $this->createNewRequest();
     $this->request->setRequestUrl($this->getUrl() . $path);
     $this->request->setRequestMethod($method);
     $this->request->setOptions(array('redirect' => 10, 'cookiesession' => true));
     $this->request->addQuery($options);
     $this->response = $this->tryCall($this->request);
     $json = $this->response->getBody()->toString();
     $json = preg_replace('#^[^\\{\\[]+|[^\\}\\]]+$#', '', trim($json));
     $obj = json_decode($json);
     if (isset($obj->status) && $obj->status != 'ok' && isset($obj->message)) {
         throw new CloudynException('Cloudyn error. ' . $obj->message);
     }
     return $obj;
 }
示例#2
0
文件: Client.php 项目: JerryCR/php-2
 /**
  * Fetches properties from the response.
  *
  * @param \http\Client\Response $response Response
  * @return array
  */
 protected function getProperties(\http\Client\Response $response)
 {
     // Process the XML with properties
     $properties = array();
     $reader = new \Jyxo\XmlReader();
     $reader->XML($response->getBody()->toString());
     // Ignore warnings
     while (@$reader->read()) {
         if (\XMLReader::ELEMENT === $reader->nodeType && 'D:prop' === $reader->name) {
             while (@$reader->read()) {
                 // Element must not be empty and has to look something like <lp1:getcontentlength>13744</lp1:getcontentlength>
                 if (\XMLReader::ELEMENT === $reader->nodeType && !$reader->isEmptyElement) {
                     if (preg_match('~^lp\\d+:(.+)$~', $reader->name, $matches)) {
                         // Apache
                         $properties[$matches[1]] = $reader->getTextValue();
                     } elseif (preg_match('~^D:(.+)$~', $reader->name, $matches)) {
                         // Lighttpd
                         $properties[$matches[1]] = $reader->getTextValue();
                     }
                 } elseif (\XMLReader::END_ELEMENT === $reader->nodeType && 'D:prop' === $reader->name) {
                     break;
                 }
             }
         }
     }
     return $properties;
 }
示例#3
0
 /**
  * {@inheritdoc}
  * @see \Scalr\Service\OpenStack\Client\ClientResponseInterface::getContent()
  */
 public function getContent()
 {
     return $this->response->getBody()->toString();
 }