protected function retrieveResponse()
 {
     if (!class_exists('ZipArchive')) {
         throw new KurogoException("class ZipArchive (php-zip) not available");
     }
     $tmpFile = Kurogo::tempFile();
     // this is the same as parent
     if (!($this->requestURL = $this->url())) {
         throw new KurogoDataException("URL could not be determined");
     }
     Kurogo::log(LOG_INFO, "Retrieving {$this->requestURL}", 'url_retriever');
     // get data from parent request and save to temp file which we will
     // unzip and return
     $response = parent::retrieveResponse();
     file_put_contents($tmpFile, $response->getResponse());
     $zip = new ZipArchive();
     if (!$zip->open($tmpFile)) {
         throw new KurogoDataException("Could not open zip file");
     }
     $targetFile = $this->targetFile();
     if ($targetFile) {
         $index = $zip->locateName($targetFile);
     } else {
         $index = 0;
     }
     if ($index === false) {
         // $zip->locateName failed
         throw new KurogoDataException("Could not locate {$this->targetFile} in zip archive");
     }
     $data = $zip->getFromIndex($index);
     unlink($tmpFile);
     $zip->close();
     $response->setResponse($data);
     Kurogo::log(LOG_DEBUG, sprintf("Returned status %d and %d bytes", $response->getCode(), strlen($data)), 'url_retriever');
     return $response;
 }
 protected function retrieveResponse()
 {
     if ($this->requiresToken && !$this->token) {
         $response = $this->initResponse();
         return $response;
     }
     $startTime = microtime(true);
     $headers = $this->headers(true);
     $response = parent::retrieveResponse();
     //if there is a location header we need to re-sign before redirecting
     if ($redirectURL = $response->getHeader("Location")) {
         Kurogo::log(LOG_WARNING, "Found Location Header", 'oauth');
         $redirectParts = parse_url($redirectURL);
         //if the redirect does not include the host or scheme, use the scheme/host from the original URL
         if (!isset($redirectParts['scheme']) || !isset($redirectParts['host'])) {
             $urlParts = parse_url($url);
             unset($urlParts['path']);
             unset($urlParts['query']);
             $redirectURL = $this->buildURL($urlParts) . $redirectURL;
         }
         $this->setBaseURL($this->canonicalURL($redirectURL));
         $parameters = $this->parameters();
         if (isset($redirectParts['query'])) {
             $parameters = array_merge($parameters, $this->parseQueryString($redirectParts['query']));
         }
         $this->setParameters($parameters);
         //reset headers
         $this->setHeaders($headers);
         Kurogo::log(LOG_DEBUG, "Redirecting to {$this->baseURL}", 'oauth');
         $response = $this->retrieveResponse();
     }
     //reset the start time to include the whole process
     $response->setStartTime($startTime);
     return $response;
 }