public function execute()
{
$data = null;
$curl = new Curl();
try {
$curl->setOpt(CURLOPT_SSL_VERIFYPEER, $this->verifyPeer);
if ($this->proxy != null) {
$curl->setOpt(CURLOPT_PROXY, $this->proxy);
if ($this->proxyCredentials != null) {
$curl->setOpt(CURLOPT_PROXYUSERPWD, $this->proxyCredentials);
}
}
foreach ($this->getHeaders() as $key => $value) {
$curl->setHeader($key, $value);
}
foreach ($this->getCookies() as $key => $value) {
$curl->setCookie($key, $value);
}
$error_format = "Instagram Request failed: [%s] [%s] %s";
switch ($this->getMethod()) {
case self::GET:
$data = $curl->get($this->getUrl(), $this->getParams());
if ($curl->curlError) {
throw new InstagramException(sprintf($error_format, "GET", $this->getUrl(), $curl->errorMessage));
}
break;
case self::POST:
$data = $curl->post($this->getUrl(), $this->getParams());
if ($curl->curlError) {
throw new InstagramException(sprintf($error_format, "POST", $this->getUrl(), $curl->errorMessage));
}
break;
default:
throw new InstagramException(sprintf($error_format, "UNKNOWN", $this->getUrl(), "Unsupported Request Method"));
}
return new Response($curl, $data);
} finally {
//Release cURL resources after return or exception
$curl->close();
}
}