Example #1
0
 /**
  * Return the request data
  * 
  * @return string
  */
 public function getData()
 {
     if (is_string($this->_data)) {
         return $this->_data;
     } else {
         return $this->_internal_request->to_postdata();
     }
 }
 /**
  *
  * @param OAuthRequest $Request 
  */
 protected function _Curl($Request)
 {
     $C = curl_init();
     curl_setopt($C, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt($C, CURLOPT_SSL_VERIFYPEER, FALSE);
     switch ($Request->get_normalized_http_method()) {
         case 'POST':
             curl_setopt($C, CURLOPT_URL, $Request->get_normalized_http_url());
             curl_setopt($C, CURLOPT_POST, TRUE);
             curl_setopt($C, CURLOPT_POSTFIELDS, $Request->to_postdata());
             break;
         default:
             curl_setopt($C, CURLOPT_URL, $Request->to_url());
     }
     return $C;
 }
 /**
  *
  *
  * @param OAuthRequest $Request
  */
 protected function _curl($Request, $Post = null)
 {
     $C = curl_init();
     curl_setopt($C, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($C, CURLOPT_SSL_VERIFYPEER, false);
     switch ($Request->get_normalized_http_method()) {
         case 'POST':
             //            echo $Request->get_normalized_http_url();
             //            echo "\n\n";
             //            echo $Request->to_postdata();
             curl_setopt($C, CURLOPT_URL, $Request->get_normalized_http_url());
             //            curl_setopt($C, CURLOPT_HTTPHEADER, array('Authorization' => $Request->to_header()));
             curl_setopt($C, CURLOPT_POST, true);
             curl_setopt($C, CURLOPT_POSTFIELDS, $Request->to_postdata());
             break;
         default:
             curl_setopt($C, CURLOPT_URL, $Request->to_url());
     }
     return $C;
 }
 /**
  * Format and sign an OAuth / API request
  */
 function oAuthRequest2($url, $method, $parameters)
 {
     if (strrpos($url, 'https://') !== 0 && strrpos($url, 'http://') !== 0) {
         $url = $this->getFormat($url);
     }
     $defaults = array();
     $token = $this->token;
     $defaults['access_token'] = $token->key;
     $parameters = array_merge($defaults, $parameters);
     $request = new OAuthRequest($method, $url, $parameters);
     switch ($method) {
         case 'GET':
             return $this->http($request->to_url(), 'GET');
         default:
             return $this->http($request->get_normalized_http_url(), $method, $request->to_postdata());
     }
 }
Example #5
0
 /**
  * Make an HTTP request
  *
  * @return string API results
  */
 function http($url, $method, $postfields = NULL, $multi = false)
 {
     $this->http_info = array();
     $ci = curl_init();
     /* Curl settings */
     curl_setopt($ci, CURLOPT_USERAGENT, $this->useragent);
     curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout);
     curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout);
     curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer);
     curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
     curl_setopt($ci, CURLOPT_HEADER, FALSE);
     switch ($method) {
         case 'POST':
             curl_setopt($ci, CURLOPT_POST, TRUE);
             if (!empty($postfields)) {
                 if (is_array($postfields)) {
                     $request = new OAuthRequest($method, $url, $postfields);
                     $postfields = $request->to_postdata($multi);
                 }
                 curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
                 //	                echo "=====post data======\r\n";
                 //	                var_dump($postfields);
             }
             break;
         case 'DELETE':
             curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
             if (!empty($postfields)) {
                 $url = "{$url}?{$postfields}";
             }
             break;
         default:
             if (!empty($postfields)) {
                 $url .= '?' . http_build_query($postfields);
             }
             break;
     }
     $header_array = array();
     /*
             $header_array["FetchUrl"] = $url;
             $header_array['TimeStamp'] = date('Y-m-d H:i:s');
             $header_array['AccessKey'] = SAE_ACCESSKEY;
     
     
             $content="FetchUrl";
     
             $content.=$header_array["FetchUrl"];
     
             $content.="TimeStamp";
     
             $content.=$header_array['TimeStamp'];
     
             $content.="AccessKey";
     
             $content.=$header_array['AccessKey'];
     
             $header_array['Signature'] = base64_encode(hash_hmac('sha256',$content, SAE_SECRETKEY ,true));
     */
     //curl_setopt($ci, CURLOPT_URL, SAE_FETCHURL_SERVICE_ADDRESS );
     //print_r( $header_array );
     $header_array2 = array();
     if ($multi) {
         $header_array2 = array("Content-Type: multipart/form-data; boundary=" . OAuthUtil::$boundary, "Expect: ");
     }
     foreach ($header_array as $k => $v) {
         array_push($header_array2, $k . ': ' . $v);
     }
     curl_setopt($ci, CURLOPT_HTTPHEADER, $header_array2);
     curl_setopt($ci, CURLINFO_HEADER_OUT, TRUE);
     //        echo $url."<hr/>";
     curl_setopt($ci, CURLOPT_URL, $url);
     $response = curl_exec($ci);
     $this->response = $response;
     $this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
     $this->http_info = array_merge($this->http_info, curl_getinfo($ci));
     $this->url = $url;
     //echo '=====info====='."\r\n";
     //print_r( curl_getinfo($ci) );
     //echo '=====$response====='."\r\n";
     //print_r( $response );
     curl_close($ci);
     return $response;
 }
Example #6
0
 /**
  * do a request
  *
  * @param OAuthRequest $request
  * @return OAuthToken|null
  */
 private static function doRequest($request)
 {
     if ($request->get_normalized_http_method() == 'POST') {
         $data = self::doPost($request->get_normalized_http_url(), $request->to_postdata());
     } else {
         $data = self::doGet($request->to_url());
     }
     parse_str($data);
     if (isset($oauth_token) && isset($oauth_token_secret)) {
         return new ExtendedOAuthToken($oauth_token, $oauth_token_secret, $data);
     }
     return null;
 }
Example #7
0
 /**
  * Call Mendeley API
  *
  * You should cache frequent calls to this method in your application. At least GET calls.
  *
  * @param string $method
  * @param string $url
  * @param array $params
  * @param boolean $authenticate
  */
 private function http($method, $url, $params = array(), $authentication = true)
 {
     if (!is_array($params)) {
         throw new Exception('HTTP params need to be array in Mendeley::http');
     }
     if ($authentication) {
         $url = self::MENDELEY_OAPI_PRIVATE_URL . $url;
         $token = $this->getAccessToken($this->signatureMethod, $this->consumer);
         $request = OAuthRequest::from_consumer_and_token($this->consumer, $token, $method, $url, $params);
         $request->sign_request($this->signatureMethod, $this->consumer, $token);
     } else {
         $url = self::MENDELEY_OAPI_PUBLIC_URL . $url;
         $params['consumer_key'] = $this->consumer->key;
         $request = new OAuthRequest($method, $url, $params);
     }
     if ($method === 'GET') {
         $url = $request->to_url();
     } else {
         $url = $request->get_normalized_http_url();
         $params = $request->to_postdata();
     }
     if ($request = MendeleyUtil::runCurl($url, $method, array(), $params)) {
         $request = json_decode($request);
     }
     return $request;
 }