public function getJSONByURI($uri) { $request = new Request('http://' . self::DOMAIN . '/sc2/' . $uri . '.json'); $request->setOption(CURLOPT_HTTPHEADER, ['X-Requested-With: XMLHttpRequest']); $request->execute(); $raw = substr($request->getRawResponse(), $request->getInfo(CURLINFO_HEADER_SIZE)); $json = json_decode($raw, true); if (!$json or !$json['json']['success']) { throw new JSONUnvalidException(); } return $json; }
/** * @param string $url The URL of the gzip * @return string the uncompressed downloaded content * @throws Curl\Exception\ProtectedOptionException * @throws GoogleSitemapParserException */ protected function downloadAndExtractGZIP($url) { try { $request = new Request($url); $request->setOption(CURLOPT_ENCODING, ''); $request->execute(); /** @var \Symfony\Component\HttpFoundation\Response $response */ $response = $request->getResponse(); return $response->headers->get('Content-Type') === 'application/xml' ? $response->getContent() : gzdecode($response->getContent()); } catch (Curl\Exception\CurlErrorException $e) { throw new GoogleSitemapParserException($e->getMessage()); } }