public function test_getLastErrorMessage() { $this->curl->setOption(CURLOPT_URL, 'foo://bar'); $this->curl->setOption(CURLOPT_RETURNTRANSFER, TRUE); $this->curl->execute(); $this->assertEquals($this->curl->getLastErrorMessage(), 'cURL failed with error #1: Protocol foo not supported or disabled in libcurl'); }
/** * Fetches data from the Blizzard Diablo 3 API * * @param string $url * @return mixed */ protected function getData($url) { // set curl options $this->request = new CurlRequest($url); $this->request->setOption(CURLOPT_URL, $url); $this->request->setOption(CURLOPT_RETURNTRANSFER, true); $this->request->setOption(CURLOPT_CONNECTTIMEOUT, 5); $this->request->setOption(CURLOPT_TIMEOUT, 30); $this->request->setOption(CURLOPT_MAXREDIRS, 7); $this->request->setOption(CURLOPT_HEADER, false); return $this->request->execute(); }
public function execute($response = null) { // note: $response is not used here, only needed to keep PHP strict mode // happy. $this->prepare(); $response = parent::execute(new TransloaditResponse()); $response->parseJson(); return $response; }
public static function lookup($location_string) { $api = 'http://maps.googleapis.com/maps/api/geocode/json'; $api_call = new CurlRequest($api); $api_call->setParams(array('sensor' => 'false', 'address' => $location_string)); try { $result = $api_call->execute(); $geocode = json_decode($result['body']); if ($geocode->status != 'OK') { return false; } return $geocode->results[0]->geometry->location; } catch (Exception $e) { return false; } }
function __request (&$object_or_class, $method, $path, $data = null, $headers = null) { if (is_null($headers)) { $headers = array( 'Accept: application/xml', 'Content-Type: application/xml' ); } $request = new CurlRequest(); $request->headers = $headers; $request->url = $this->url . $object_or_class->interpolated_uri() . $path; $request->username = $this->username; $request->password = $this->password; $request->set(CURLOPT_CUSTOMREQUEST, $method); $request->set(CURLOPT_SSL_VERIFYPEER, false); if (!empty($data)) $request->set(CURLOPT_POSTFIELDS, $data); $response = $request->execute(); return $response; }