public function view() { if (empty($this->request->query['link'])) { throw new NotFoundException('Missing link parameter'); } $link = rawurldecode($this->request->query['link']); if (!Validation::url($link)) { throw new NotFoundException('Invalid link'); } $request = new Nodes\Curl($link); $request->exec(); $responseCode = $request->getResponseCode(); if ($responseCode != 200) { throw new NotFoundException('Response code was not 200 OK'); } $this->response->disableCache(); $this->response->type($request->getResponseHeader('content-type')); $this->response->body($request->getResponseBody()); $this->response->send(); $this->_stop(); }
/** * _curl * * @param mixed $url * @return mixed */ protected function _curl($url) { $curl = new \Nodes\Curl($url, array(CURLOPT_CONNECTTIMEOUT => 4)); return $curl->get()->getResponseBody(); }
/** * Extend a current access token for up to 60 days * * Return data has two keys * - access_token Is the new access token * - expires Is how long the new access token will be valid for (up to 60 days) * * Can throw Curl and Facebook exceptions * * @param string $access_token An old access token that belongs to this application * @return array */ public static function extendAccessToken($access_token) { $curl = new \Nodes\Curl(); $params = http_build_query(array('client_id' => Configure::read('Facebook.appId'), 'client_secret' => Configure::read('Facebook.secret'), 'grant_type' => 'fb_exchange_token', 'fb_exchange_token' => $access_token)); $response = $curl->setOption(CURLOPT_URL, sprintf('https://graph.facebook.com/oauth/access_token?%s', $params))->get()->getResponseBody(); parse_str($response, $res); return $res; }
protected function _delete($params) { if (static::$_embedded) { return false; } $request = new \Nodes\Curl(); $request->setOption(CURLOPT_URL, $url = $this->_buildRequestURI($params)); $request->delete(); $responseBody = $request->getResponseBody(); if (isset($responseBody['error'])) { throw new Exception($responseBody['error']['message'], $responseBody['error']['code']); } return $request; }