Instagram\API\Framework\Request::execute PHP Method

execute() public method

Execute the Request
public execute ( ) : Response
return Response The Response
    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();
        }
    }

Usage Example

 /**
  *
  * Execute the Request
  *
  * @return object Response Data
  * @throws InstagramException
  */
 public function execute()
 {
     $response = parent::execute();
     $this->response = $response;
     if ($this->interceptResponse($response)) {
         return null;
     }
     if ($this->throwExceptionIfResponseNotOk() && !$response->isOK() && !$response->isJson()) {
         return $response->getCode();
     }
     $this->instagram->setCookies(array_merge($this->instagram->getCookies(), $response->getCookies()));
     if ($this->parseResponse()) {
         return $this->mapper->map($response->getData(), $this->getResponseObject());
     }
     return $response->getData();
 }