/** * Perform the HTTP query for a list of objects and de-serialize the * results. */ protected function objectQuery($params = [], $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; $headers = ['X-Auth-Token' => $this->token]; $response = $this->client->get($url, ['headers' => $headers]); // The only codes that should be returned are 200 and the ones // already thrown by GET. if ($response->getStatusCode() != 200) { throw new Exception('An unknown exception occurred while processing the request.'); } $json = $response->json(); // Turn the array into a list of RemoteObject instances. $list = []; foreach ($json as $item) { if (!empty($item['subdir'])) { $list[] = new Subdir($item['subdir'], $params['delimiter']); } elseif (empty($item['name'])) { throw new 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, $this->client); } } return $list; }