Esempio n. 1
0
 /**
  * Makes a request
  * @param string $url A URL in which to make a GET request
  * @param Array $params An associative array of key/value pairs to pass to said URL
  * @access private
  * @return Response
  */
 private function GetResponse($method = 'GET')
 {
     //-- since there's no option to use anything other curl, this check is kinda useless
     //-- I had high hopes with this one using sockets and whatnot, but alas, time is of
     //-- the essence... in internet time
     if ($this->useCurl) {
         $response = new Response();
         $http = WebRequest::Instance();
         $res = $http->Create($this->url, $method, $this->parameters);
         if ($res instanceof Error) {
             return $res;
         }
         $response->info = $res->Info;
         $response->json = $res->Content;
         $response = Response::Create($this, &$response);
         return $response;
     }
 }
Esempio n. 2
0
 /**
  * Makes a request
  * @param string $url A URL in which to make a GET request
  * @param Array $params An associative array of key/value pairs to pass to said URL
  * @access private
  * @return Response
  */
 private function GetResponse($method = 'GET')
 {
     //-- if there's no url, can't make a request
     if (null == $this->url) {
         trigger_error('No URL to make a request', E_USER_ERROR);
     }
     //-- since there's no option to use anything other curl, this check is kinda useless
     //-- I had high hopes with this one using sockets and whatnot, but alas, time is of
     //-- the essence... in internet time
     if ($this->useCurl) {
         //-- no curl handle? create one
         if ($this->ch === null) {
             $this->ch = curl_init();
         }
         $opts = $this->curl_opts;
         $query = '';
         switch (strtolower($method)) {
             case 'post':
                 $opts[CURLOPT_POST] = true;
                 $opts[CURLOPT_POSTFIELDS] = $this->parameters;
                 break;
             case 'delete':
                 $opts[CURLOPT_CUSTOMREQUEST] = 'DELETE';
                 foreach ($this->parameters as $key => $val) {
                     $query .= (strlen($query) == 0 ? '?' : '&') . $key . '=' . urlencode($val);
                 }
                 break;
             default:
                 foreach ($this->parameters as $key => $val) {
                     $query .= (strlen($query) == 0 ? '?' : '&') . $key . '=' . urlencode($val);
                 }
                 break;
         }
         $this->url .= $query;
         $opts[CURLOPT_URL] = $this->url;
         $response = new Response();
         if (curl_setopt_array($this->ch, $opts)) {
             if (false !== ($res = curl_exec($this->ch))) {
                 $response->info = curl_getinfo($this->ch);
                 $response->json = $res;
                 $response = Response::Create($this, &$response);
             } else {
                 $response->error = new Error('cURLError', curl_errno($this->ch), curl_error($this->ch), $opts[CURLOPT_URL]);
             }
         }
         return $response;
     }
 }