Ejemplo n.º 1
0
 /**
  * Perform the HTTP query for a list of objects and de-serialize the
  * results.
  */
 protected function objectQuery($params = array(), $limit = NULL, $marker = NULL)
 {
     if (isset($limit)) {
         $params['limit'] = (int) $limit;
         if (!empty($marker)) {
             $params['marker'] = (string) $marker;
         }
     }
     // We always want JSON.
     $params['format'] = 'json';
     $query = http_build_query($params);
     $query = str_replace('%2F', '/', $query);
     $url = $this->url . '?' . $query;
     $client = \HPCloud\Transport::instance();
     $headers = array('X-Auth-Token' => $this->token);
     $response = $client->doRequest($url, 'GET', $headers);
     // The only codes that should be returned are 200 and the ones
     // already thrown by doRequest.
     if ($response->status() != 200) {
         throw new \HPCloud\Exception('An unknown exception occurred while processing the request.');
     }
     $responseContent = $response->content();
     $json = json_decode($responseContent, TRUE);
     // Turn the array into a list of RemoteObject instances.
     $list = array();
     foreach ($json as $item) {
         if (!empty($item['subdir'])) {
             $list[] = new Subdir($item['subdir'], $params['delimiter']);
         } elseif (empty($item['name'])) {
             throw new \HPCloud\Exception('Unexpected entity returned.');
         } else {
             //$url = $this->url . '/' . rawurlencode($item['name']);
             $url = self::objectUrl($this->url, $item['name']);
             $list[] = RemoteObject::newFromJSON($item, $this->token, $url);
         }
     }
     return $list;
 }