예제 #1
0
파일: base.php 프로젝트: brynner/postr
 protected function _getResponse($method, array $query = array())
 {
     //Argument 1 must be a string
     Eden_Zappos_Error::i()->argument(1, 'string');
     //Our request parameters
     $default = array(self::KEY => $this->_apiKey);
     //generate URL-encoded query string to build our NVP string
     $query = http_build_query($query + $default);
     $curl = Eden_Curl::i()->setUrl($method . '?' . $query)->setReturnTransfer(TRUE)->setHeader(false);
     $results = $curl->getQueryResponse();
     foreach ($results as $key => $value) {
         if (!is_array($value)) {
             return $value;
         }
         if (!empty($value) && isset($value)) {
             foreach ($value as $k => $v) {
                 $response = json_decode($k . ']}', false);
                 if (empty($response)) {
                     $response = json_decode($k, false);
                 }
                 break;
             }
         } else {
             return $key;
         }
     }
     return $response;
 }
 /**
  * sends the post to facebook
  *
  * @return int
  */
 public function create()
 {
     //get the facebook graph url
     $url = Eden_Facebook_Graph::GRAPH_URL . $this->_id . '/links';
     $query = array('access_token' => $this->_token);
     $url .= '?' . http_build_query($query);
     //send it into curl
     $response = Eden_Curl::i()->setUrl($url)->setConnectTimeout(10)->setFollowLocation(true)->setTimeout(60)->verifyPeer(false)->setUserAgent(Eden_Facebook_Auth::USER_AGENT)->setHeaders('Expect')->setPost(true)->setPostFields(http_build_query($this->_post))->getJsonResponse();
     //get the json response
     return $response['id'];
     //return the id
 }
예제 #3
0
파일: fql.php 프로젝트: brynner/postr
 /**
  * Queries the database
  * 
  * @param string query
  * @return array|object
  */
 public function query($query)
 {
     //Argument 1 must be a string or null
     Eden_Facebook_Error::i()->argument(1, 'string', 'array', self::SELECT);
     if (!is_array($query)) {
         $query = array('q' => (string) $query);
     } else {
         foreach ($query as $key => $select) {
             $query[$key] = (string) $select;
         }
         $query = array('q' => json_encode($query));
     }
     $query['access_token'] = $this->_token;
     $url = self::FQL_URL . '?' . http_build_query($query);
     $results = Eden_Curl::i()->setUrl($url)->setConnectTimeout(10)->setFollowLocation(true)->setTimeout(60)->verifyPeer(false)->setUserAgent(Eden_Facebook_Auth::USER_AGENT)->setHeaders('Expect')->getJsonResponse();
     $this->_queries[] = array('query' => $query['q'], 'results' => $results);
     if (isset($results['error']['message'])) {
         Eden_Facebook_Error::i($query['q'] . $results['error']['message'])->trigger();
     }
     return $results['data'];
 }
예제 #4
0
파일: base.php 프로젝트: annaqin/eden
 protected function _postRequest($query, $headers = array())
 {
     //set url
     $url = 'https://' . $this->_host . '/';
     //set curl
     $curl = Eden_Curl::i()->verifyHost(false)->verifyPeer(false)->setUrl($url)->setPost(true)->setHeaders($headers)->setPostFields($query);
     $response = $curl->getResponse();
     //get curl infomation
     $this->_meta['url'] = $url;
     $this->_meta['query'] = $query;
     $this->_meta['curl'] = $curl->getMeta();
     $this->_meta['response'] = $response;
     return $response;
 }
예제 #5
0
파일: s3.php 프로젝트: brynner/postr
 protected function _setResponse($action, $bucket = NULL, $path = '/', array $query = array(), $data = NULL, array $headers = array(), array $amazon = array())
 {
     //get host - bucket1.s3.amazonaws.com
     $host = $this->_getHost($bucket);
     //get url - http://bucket1.s3.amazonaws.com/some/path
     $url = $this->_getUrl($host, $path, $query);
     //get path - /bucket1/some/path
     $path = $this->_getPath($bucket, $path);
     //get headers
     ksort($amazon);
     $curlHeaders = $amazonHeaders = array();
     $headers['Host'] = $host;
     $headers['Date'] = gmdate('D, d M Y H:i:s T');
     foreach ($amazon as $header => $value) {
         $curlHeaders[] = $header . ': ' . $value;
         $amazonHeaders[] = strtolower($header) . ':' . $value;
     }
     foreach ($headers as $header => $value) {
         $curlHeaders[] = $header . ': ' . $value;
     }
     $amazonHeaders = "\n" . implode("\n", $amazonHeaders);
     if (!trim($amazonHeaders)) {
         $amazonHeaders = NULL;
     }
     if (!isset($headers['Content-MD5'])) {
         $headers['Content-MD5'] = NULL;
     }
     if (!isset($headers['Content-Type'])) {
         $headers['Content-Type'] = NULL;
     }
     //get signature
     $signature = array($action, $headers['Content-MD5'], $headers['Content-Type'], $headers['Date'] . $amazonHeaders, $path);
     $signature = implode("\n", $signature);
     if ($headers['Host'] == 'cloudfront.amazonaws.com') {
         $signature = $headers['Date'];
     }
     $curlHeaders[] = 'Authorization: ' . $this->_getSignature($signature);
     //setup curl
     $curl = Eden_Curl::i()->setUserAgent('S3/php')->setUrl($url)->setHeaders($curlHeaders)->setHeader(false)->setWriteFunction(array(&$this, '_responseWriteCallback'))->verifyHost(true)->verifyPeer(true);
     //->endWhen();
     // Request types
     switch ($action) {
         case 'GET':
             break;
         case 'PUT':
         case 'POST':
             // POST only used for CloudFront
             //Open a file resource using the php://memory stream
             $fh = fopen('php://memory', 'rw');
             // Write the data to the file
             fwrite($fh, $data);
             // Move back to the beginning of the file
             rewind($fh);
             $curl->setPut(true)->setInFile($fh)->setInFileSize(strlen($data));
             break;
         case 'HEAD':
             $curl->setCustomRequest('HEAD')->setNobody(true);
             break;
         case 'DELETE':
             $curl->setCustomRequest('DELETE');
             break;
     }
     //get curl response
     $response = $curl->getResponse();
     //if there is no errot in curl
     if (!empty($response)) {
         //check if response format is in xml
         if ($this->_isXml($response)) {
             //if it is xml, well format in to object
             $this->_response = simplexml_load_string($response);
         }
         //else, there must be a curl error
     } else {
         //return curl error
         $this->_response = $curl->getMeta();
     }
     //save curl response to meta
     $this->_meta = $curl->getMeta();
     $this->_meta['url'] = $url;
     $this->_meta['headers'] = $curlHeaders;
     $this->_meta['query'] = $data;
     $this->_meta['path'] = $path;
     $this->_meta['bucket'] = $bucket;
     $this->_meta['response'] = $this->_response;
     //print_r($this->_meta);
     return $this->_response;
 }
예제 #6
0
파일: base.php 프로젝트: annaqin/eden
 protected function _put($url, $query, $etag = false)
 {
     //if query is an array
     if (is_array($query)) {
         //prevent sending fields with no value
         $query = $this->_accessKey($query);
         //covent query to json format
         $query = json_encode($query);
         //add access token to the url
         $url = $url . '?' . self::ACCESS_TOKEN . '=' . $this->_token;
     }
     //if query is an xml
     if ($this->isXml($query)) {
         //set different headers for xml
         $this->_headers = $this->setXmlHeaders($this->_developerId, $etag);
         //well format the xml
         $query = $this->formatToXml($query);
         //add access token to the url
         $url = $url . '?' . self::ACCESS_TOKEN . '=' . $this->_token;
     }
     //if query is in string
     if (is_string($query)) {
         //get the raw data using file get content
         $query = file_get_contents($query);
         //use different headers
         $headers = array();
         $headers[] = 'Content-Length: ' . strlen($query);
         $headers[] = 'Content-Transfer-Encoding: base64';
         $this->_headers = $headers;
         //add access token to the url
         $url = $url . '&' . self::ACCESS_TOKEN . '=' . $this->_token;
     }
     //Open a file resource using the php://memory stream
     $fh = fopen('php://memory', 'rw');
     // Write the data to the file
     fwrite($fh, $query);
     // Move back to the beginning of the file
     rewind($fh);
     //start curl
     $curl = Eden_Curl::i()->verifyHost(false)->verifyPeer(false)->setHeaders($this->_headers)->setPut(true)->setUrl($url)->setInFile($fh)->setInFileSize(strlen($query));
     //get the response
     $response = $curl->getResponse();
     $this->_meta = $curl->getMeta();
     $this->_meta['url'] = $url;
     $this->_meta['headers'] = $this->_headers;
     $this->_meta['query'] = $query;
     //reset protected variables
     unset($this->_query);
     //check if response is in json format
     if ($this->isJson($response)) {
         //else it is in json format, covert it to array
         return $response = json_decode($response, true);
     }
     //check if response is in xml format
     if ($this->isXml($response)) {
         //if it is xml, convert it to array
         return $response = simplexml_load_string($response);
     }
     return $response;
 }
예제 #7
0
 protected function _getAccess($query, $code = NULL)
 {
     //if there is a code
     if (!is_null($code)) {
         //put codein the query
         $query[self::CODE] = $code;
     }
     //set curl
     $result = Eden_Curl::i()->setUrl($this->_accessUrl)->verifyHost()->verifyPeer()->setHeaders(self::TYPE, self::REQUEST)->setPostFields(http_build_query($query))->getResponse();
     //check if results is in JSON format
     if ($this->isJson($result)) {
         //if it is in json, lets json decode it
         $response = json_decode($result, true);
         //else its not in json format
     } else {
         //parse it to make it an array
         parse_str($result, $response);
     }
     return $response;
 }
예제 #8
0
파일: consumer.php 프로젝트: brynner/postr
 /**
  * Returns the token from the server
  *
  * @param array
  * @return array
  */
 public function getResponse(array $query = array())
 {
     $headers = $this->_headers;
     $json = NULL;
     if ($this->_json) {
         $json = json_encode($query);
         $query = array();
     }
     //get the authorization parameters as an array
     $signature = $this->getSignature($query);
     $authorization = $this->getAuthorization($signature, false);
     //if we should use the authrization
     if ($this->_useAuthorization) {
         //add the string to headers
         $headers[] = sprintf(self::AUTH_HEADER, $this->_buildQuery($authorization, ',', false));
     } else {
         //merge authorization and query
         $query = array_merge($authorization, $query);
     }
     $query = $this->_buildQuery($query);
     $url = $this->_url;
     //set curl
     $curl = Eden_Curl::i()->verifyHost(false)->verifyPeer(false);
     //if post
     if ($this->_method == self::POST) {
         $headers[] = self::POST_HEADER;
         if (!is_null($json)) {
             $query = $json;
         }
         //get the response
         $response = $curl->setUrl($url)->setPost(true)->setPostFields($query)->setHeaders($headers)->getResponse();
     } else {
         if (trim($query)) {
             //determine the conector
             $connector = NULL;
             //if there is no question mark
             if (strpos($url, '?') === false) {
                 $connector = '?';
                 //if the redirect doesn't end with a question mark
             } else {
                 if (substr($url, -1) != '?') {
                     $connector = '&';
                 }
             }
             //now add the secret to the redirect
             $url .= $connector . $query;
         }
         //get the response
         $response = $curl->setUrl($url)->setHeaders($headers)->getResponse();
     }
     $this->_meta = $curl->getMeta();
     $this->_meta['url'] = $url;
     $this->_meta['authorization'] = $authorization;
     $this->_meta['headers'] = $headers;
     $this->_meta['query'] = $query;
     $this->_meta['response'] = $response;
     return $response;
 }
예제 #9
0
파일: oauth.php 프로젝트: annaqin/eden
 public function getConsumerKey()
 {
     $this->_params['scopes'] = implode(', ', $this->_scopes);
     $url = $this->_debug ? self::CONSUMER_KEY_URL . '?debug=true' : self::CONSUMER_KEY_URL;
     unset($this->_params['oauth_consumer_key']);
     front()->output($this->_params);
     exit;
     $params = http_build_query($this->_params);
     $headers = array();
     $headers[] = 'Content-Type: application/x-www-form-urlencoded';
     $curl = Eden_Curl::i()->verifyHost(false)->verifyPeer(false)->setUrl($url)->setPost(true)->setPostFields($params)->setHeaders($headers);
     //get the response
     $response = $curl->getResponse();
     return $response;
 }
예제 #10
0
파일: ecs.php 프로젝트: annaqin/eden
 protected function _sendRequest()
 {
     return Eden_Curl::i()->setUrl($this->_requestUrl)->verifyHost(false)->verifyPeer(false)->setTimeout(60)->getResponse();
 }
예제 #11
0
파일: base.php 프로젝트: brynner/postr
 protected function _sendRequest($post)
 {
     //Argument 1 must be a string
     Eden_Authorizenet_Error::i()->argument(1, 'string');
     //if it is in live mode
     if ($this->_isLive) {
         $this->_url = self::LIVE_URL;
     }
     //Execute curl
     $curl = Eden_Curl::i()->setUrl($this->_url)->setPostFields($post)->setHeader(false)->setTimeout(45)->verifyHost(true)->setCaInfo($this->_certificate)->setPost(true);
     return $curl->getResponse();
 }
예제 #12
0
 /**
  * Returns an RSS feed to a public id
  *
  * @param int
  * @return SimpleXml
  */
 public function rss($id)
 {
     Eden_Facebook_Error::i()->argument(1, 'int');
     return Eden_Curl::i()->setUrl(sprintf(self::RSS, $id))->setUserAgent(self::RSS_AGENT)->setConnectTimeout(10)->setFollowLocation(true)->setTimeout(60)->verifyPeer(false)->getSimpleXmlResponse();
 }
예제 #13
0
if(!class_exists('Eden_Paypal_Base')){class Eden_Paypal_Base extends Eden_Class{const VERSION='84.0';const TEST_URL='https://api-3t.sandbox.paypal.com/nvp';const LIVE_URL='https://api-3t.paypal.com/nvp';const SANDBOX_URL='https://test.authorize.net/gateway/transact.dll';protected $_meta=array();protected $_url=NULL;protected $_user=NULL;protected $_password=NULL;protected $_signature=NULL;protected $_certificate=NULL;public function __construct($user,$password,$signature,$certificate,$live=false){$this->_user=$user;$this->_password=$password;$this->_signature=$signature;$this->_certificate=$certificate;$this->_url=self::TEST_URL;$this->_baseUrl=self::TEST_URL;if($live){$this->_url=self::LIVE_URL;$this->_baseUrl=self::LIVE_URL;}}public function getMeta(){return $this->_meta;}protected function _accessKey($array){foreach($array as $key=>$val){if(is_array($val)){$array[$key]=$this->_accessKey($val);}if($val==false || $val==NULL || empty($val) || !$val){unset($array[$key]);}}return $array;}protected function _request($method,array $query=array(),$post=true){Eden_Paypal_Error::i()->argument(1,'string');$default=array( 'USER'=>$this->_user,'PWD'=>$this->_password,'SIGNATURE'=>$this->_signature,'VERSION'=>self::VERSION,'METHOD'=>$method);$query=http_build_query($query + $default);$curl=Eden_Curl::i()->setUrl($this->_baseUrl)->setVerbose(true)->setCaInfo($this->_certificate)->setPost(true)->setPostFields($query);$response=$curl->getQueryResponse();$this->_meta['url']=$this->_baseUrl;$this->_meta['query']=$query;$this->_meta['curl']=$curl->getMeta();$this->_meta['response']=$response;return $response;}}}
예제 #14
0
파일: graph.php 프로젝트: brynner/postr
 protected function _call($url, array $post = array())
 {
     return Eden_Curl::i()->setUrl($url)->setConnectTimeout(10)->setFollowLocation(true)->setTimeout(60)->verifyPeer(false)->setUserAgent(Eden_Facebook_Auth::USER_AGENT)->setHeaders('Expect')->when(!empty($post), 2)->setPost(true)->setPostFields(http_build_query($post))->getResponse();
 }
 protected function _upload($url, $query, $etag = false)
 {
     //well format the xml
     $query = $this->formatToXml($query);
     //set different headers for xml
     $this->_headers = $this->setXmlHeaders($this->_developerId, $etag);
     $this->_headers[] = 'Content-Length:' . strlen($query);
     $this->_headers[] = 'Host: gdata.youtube.com';
     //add access token to query
     $url = $url . '?' . self::ACCESS_TOKEN . '=' . $this->_token;
     //set curl
     $curl = Eden_Curl::i()->verifyHost(false)->verifyPeer(false)->setUrl($url)->setPost(true)->setPostFields($query)->setHeaders($this->_headers);
     //get response form curl
     $response = $curl->getResponse();
     $this->_meta = $curl->getMeta();
     $this->_meta['url'] = $url;
     $this->_meta['headers'] = $this->_headers;
     $this->_meta['query'] = $query;
     //reset protected variables
     $this->_reset();
     //check if response is in xml format
     if ($this->isXml($response)) {
         //if it is xml, convert it to array
         return $response = simplexml_load_string($response);
     }
     //if it is a normal response
     return $response;
 }
예제 #16
0
파일: base.php 프로젝트: annaqin/eden
 protected function _put($url, array $query = array())
 {
     //prevent sending fields with no value
     $query = $this->_accessKey($query);
     //covent query to json format
     $query = json_encode($query);
     //add access token to the url
     //Open a file resource using the php://memory stream
     $fh = fopen('php://memory', 'rw');
     // Write the data to the file
     fwrite($fh, $query);
     // Move back to the beginning of the file
     rewind($fh);
     //start curl
     $curl = Eden_Curl::i()->verifyHost(false)->verifyPeer(false)->setHeaders($this->_headers)->setPut(true)->setUrl($url)->setUserPwd($this->_email . '/token:' . $this->_token)->setInFile($fh)->setInFileSize(strlen($query));
     //get the response
     $response = $curl->getJsonResponse();
     $this->_meta = $curl->getMeta();
     $this->_meta['url'] = $url;
     $this->_meta['headers'] = $this->_headers;
     $this->_meta['query'] = $query;
     print_r($this->_meta);
     //reset protected variables
     unset($this->_query);
     return $response;
 }
예제 #17
0
파일: base.php 프로젝트: annaqin/eden
 protected function _getResponse($host, $rawQuery)
 {
     //prevent sending null values
     $rawQuery = $this->_accessKey($rawQuery);
     //sort the raw query
     ksort($rawQuery);
     //format array query
     $query = $this->_formatQuery($rawQuery);
     // Build out the variables
     $domain = "https://{$host}/";
     //set parameters for generating request
     $query[self::ACCESS_KEY] = $this->_accessKey;
     $query[self::TIMESTAMP] = date('c');
     $query[self::VERSION] = $this->_versionDate;
     $query[self::SIGNATURE_METHOD] = 'HmacSHA256';
     $query[self::SIGNATURE_VERSION] = 2;
     //create a request signature for security access
     $query[self::SIGNATURE] = $this->_generateSignature($host, $query);
     //build a http query
     $url = $domain . '?' . http_build_query($query);
     //set curl
     $curl = Eden_Curl::i()->setUrl($url)->verifyHost(false)->verifyPeer(false)->setTimeout(60);
     //get response from curl
     $response = $curl->getResponse();
     //if result is in xml format
     if ($this->isXml($response)) {
         //convert it to string
         $response = simplexml_load_string($response);
     }
     //get curl infomation
     $this->_meta['url'] = $url;
     $this->_meta['query'] = $query;
     $this->_meta['curl'] = $curl->getMeta();
     $this->_meta['response'] = $response;
     return $response;
 }
예제 #18
0
 protected function _getResponse($url, array $query = array())
 {
     //if needed, add access token to query
     $query['access_token'] = $this->_token;
     //build url query
     $url = $url . '?' . http_build_query($query);
     //set curl
     $curl = Eden_Curl::i()->setUrl($url)->verifyHost(false)->verifyPeer(false)->setTimeout(60);
     //get response from curl
     $response = $curl->getJsonResponse();
     //get curl infomation
     $this->_meta['url'] = $url;
     $this->_meta['query'] = $query;
     $this->_meta['curl'] = $curl->getMeta();
     $this->_meta['response'] = $response;
     return $response;
 }
예제 #19
0
파일: webcharge.php 프로젝트: brynner/postr
 /**
  * Validates required transaction parameters and sends 
  * the transaction to Innovative Gateway Solutions.
  *
  * @return string the cURL result
  */
 public function send()
 {
     //test for valid amount
     if (!$this->_transaction['fulltotal'] || !is_numeric($this->_transaction['fulltotal'])) {
         //throw exception
         Eden_Webcharge_Error::i()->setMessage(Eden_Webcharge_Error::INVALID_AMOUNT)->addVariable((string) $this->_transaction['fulltotal']);
     }
     //test for valid transaction type
     if (!$this->_transaction['trantype'] || !in_array($this->_transaction['trantype'], $this->_transactionTypes)) {
         //throw exception
         Eden_Webcharge_Error::i()->setMessage(Eden_Webcharge_Error::INVALID_TRANSACTION_TYPE)->addVariable((string) $this->_transaction['trantype'])->trigger();
     }
     //test for valid card type
     if (!$this->_transaction['cardtype'] || !in_array($this->_transaction['cardtype'], $this->creditCards)) {
         //throw exception
         Eden_Webcharge_Error::i()->setMessage(Eden_Webcharge_Error::INVALID_CARD_TYPE)->addVariable((string) $this->_transaction['cardtype'])->trigger();
     }
     //test for valid month
     if (!$this->_transaction['month'] || !is_numeric($this->_transaction['month']) || strlen((string) $this->_transaction['month']) != 2) {
         //throw exception
         Eden_Webcharge_Error::i()->setMessage(Eden_Webcharge_Error::INVALID_CREDIT_CARD_MONTH)->addVariable((string) $this->_transaction['month'])->trigger();
     }
     //test for valid year
     if (!$this->_transaction['year'] || !is_numeric($this->_transaction['year']) || !in_array(strlen((string) $this->_transaction['year']), array(2, 4))) {
         //throw exception
         Eden_Webcharge_Error::i()->setMessage(Eden_Webcharge_Error::INVALID_CREDIT_CARD_YEAR)->addVariable((string) $this->_transaction['year'])->trigger();
     }
     //test for valid creditcard name
     if (!$this->_transaction['ccname']) {
         //throw exception
         Eden_Webcharge_Error::i(Eden_Webcharge_Error::INVALID_CREDIT_CARD_NAME)->trigger();
     }
     // Create the connection through the cURL extension
     return Eden_Curl::i()->setUrl(self::PAYMENT_URL)->when($this->_proxy != NULL)->setProxy($this->_proxy)->endWhen()->setUserAgent($this->_agent)->setPost(true)->setPostFields($this->_transaction)->setFollowLocation(true)->setTimeout($this->_timeout)->getResponse();
 }
예제 #20
0
파일: base.php 프로젝트: annaqin/eden
 protected function _post($url, array $query = array())
 {
     //add access token to query
     $url = $url . '?' . self::ACCESS_TOKEN . '=' . $this->_token;
     //prevent sending fields with no value
     $query = $this->_accessKey($query);
     //add current date for verification
     $query[self::VERIFY] = date('Ymd', time());
     //build a to string query
     $query = http_build_query($query);
     //reset variables
     unset($this->_query);
     //set curl
     $curl = Eden_Curl::i()->verifyHost(false)->verifyPeer(false)->setUrl($url)->setPostFields($query);
     //get the response
     $response = $curl->getJsonResponse();
     $this->_meta = $curl->getMeta();
     $this->_meta['url'] = $url;
     $this->_meta['query'] = $query;
     return $response;
 }
예제 #21
0
파일: instagram.php 프로젝트: annaqin/eden
 protected function _delete($url)
 {
     $response = Eden_Curl::i()->setUrl($url)->setConnectTimeout(10)->setFollowLocation(true)->setTimeout(60)->verifyPeer(false)->setCustomDelete()->getJsonResponse();
     return $response;
 }
예제 #22
0
파일: base.php 프로젝트: annaqin/eden
 protected function _post($url, array $query = array())
 {
     //prevent sending fields with no value
     $query = $this->_accessKey($query);
     //set headers
     $headers = array();
     $headers[] = Eden_Oauth_Consumer::POST_HEADER;
     //make oauth signature
     $rest = Eden_Oauth::i()->consumer($url, $this->_consumerKey, $this->_consumerSecret)->setMethodToPost()->setToken($this->_accessToken, $this->_accessSecret)->setSignatureToHmacSha1();
     //get the authorization parameters as an array
     $signature = $rest->getSignature($query);
     $authorization = $rest->getAuthorization($signature, false);
     $authorization = $this->_buildQuery($authorization);
     //if query is in array
     if (is_array($query)) {
         //build a http query
         $query = $this->_buildQuery($query);
     }
     //determine the conector
     $connector = NULL;
     //if there is no question mark
     if (strpos($url, '?') === false) {
         $connector = '?';
         //if the redirect doesn't end with a question mark
     } else {
         if (substr($url, -1) != '?') {
             $connector = '&';
         }
     }
     //now add the authorization to the url
     $url .= $connector . $authorization;
     //set curl
     $curl = Eden_Curl::i()->verifyHost(false)->verifyPeer(false)->setUrl($url)->setPost(true)->setPostFields($query)->setHeaders($headers);
     //get the response
     $response = $curl->getJsonResponse();
     $this->_meta = $curl->getMeta();
     $this->_meta['url'] = $url;
     $this->_meta['authorization'] = $authorization;
     $this->_meta['headers'] = $headers;
     $this->_meta['query'] = $query;
     //reset variables
     unset($this->_query);
     return $response;
 }
예제 #23
0
파일: base.php 프로젝트: taqmaninw/apipack
 protected function _upload($url, array $query = array())
 {
     //prevent sending fields with no value
     $query = $this->_accessKey($query);
     //set url
     $this->_url = $url;
     //make authorization for twitter
     $this->_getAuthentication();
     //set headers
     $this->_headers['Expect'] = '';
     //at this point, the authentication header si already set
     foreach ($this->_headers as $k => $v) {
         //trim header
         $headers[] = trim($k . ': ' . $v);
     }
     //set curl
     $curl = Eden_Curl::i()->verifyHost(false)->verifyPeer(false)->setUrl($url)->setPost(true)->setPostFields($query)->setHeaders($headers);
     //json decode the response
     $response = $curl->getJsonResponse();
     //reset variables
     unset($this->_query);
     $this->_meta = $curl->getMeta();
     $this->_meta['url'] = $url;
     $this->_meta['headers'] = $headers;
     $this->_meta['query'] = $query;
     return $response;
 }
 protected function _post($url, $query = array())
 {
     $headers = array();
     $headers[] = 'Content-Type: application/json';
     $query = json_encode($query);
     //determine the conector
     $connector = NULL;
     //if there is no question mark
     if (strpos($url, '?') === false) {
         $connector = '?';
         //if the redirect doesn't end with a question mark
     } else {
         if (substr($url, -1) != '?') {
             $connector = '&';
         }
     }
     //now add the authorization to the url
     $url .= $connector . 'key=' . $this->_key;
     //set curl
     $curl = Eden_Curl::i()->verifyHost(false)->verifyPeer(false)->setUrl($url)->setPost(true)->setPostFields($query)->setHeaders($headers);
     //get the response
     $response = $curl->getResponse();
     $this->_meta = $curl->getMeta();
     $this->_meta['url'] = $url;
     $this->_meta['headers'] = $headers;
     $this->_meta['query'] = $query;
     return $response;
 }
예제 #25
0
파일: base.php 프로젝트: brynner/postr
 protected function _getResponse($url, array $query = array())
 {
     $headers = array();
     $headers[] = 'Content-Type: application/json';
     //if api key is null
     if (is_null($this->_api)) {
         //we must have an oauth token
         $headers[] = sprintf(self::ACCESS_HEADER, $this->_user);
     } else {
         $query['app_key'] = $this->_api;
         $query['user_key'] = $this->_user;
     }
     $query = http_build_query($query);
     //determine the conector
     $connector = NULL;
     //if there is no question mark
     if (strpos($url, '?') === false) {
         $connector = '?';
         //if the redirect doesn't end with a question mark
     } else {
         if (substr($url, -1) != '?') {
             $connector = '&';
         }
     }
     //now add the authorization to the url
     $url .= $connector . $query;
     //set curl
     $curl = Eden_Curl::i()->verifyHost(false)->verifyPeer(false)->setUrl($url)->setHeaders($headers);
     //get the response
     $response = $curl->getResponse();
     $this->_meta = $curl->getMeta();
     $this->_meta['url'] = $url;
     $this->_meta['headers'] = $headers;
     $this->_meta['query'] = $query;
     return $response;
 }
예제 #26
0
파일: base.php 프로젝트: taqmaninw/apipack
 protected function _request($method, array $query = array(), $post = true)
 {
     //Argument 1 must be a string
     Eden_Paypal_Error::i()->argument(1, 'string');
     //Our request parameters
     $default = array('USER' => $this->_user, 'PWD' => $this->_password, 'SIGNATURE' => $this->_signature, 'VERSION' => self::VERSION, 'METHOD' => $method);
     //generate URL-encoded query string to build our NVP string
     $query = http_build_query($query + $default);
     $curl = Eden_Curl::i()->setUrl($this->_baseUrl)->setVerbose(true)->setCaInfo($this->_certificate)->setPost(true)->setPostFields($query);
     $response = $curl->getQueryResponse();
     $this->_meta['url'] = $this->_baseUrl;
     $this->_meta['query'] = $query;
     $this->_meta['curl'] = $curl->getMeta();
     $this->_meta['response'] = $response;
     return $response;
 }
 protected function _setResponse($action, $bucket = NULL, $path = '/', array $query = array(), $data = NULL, array $headers = array(), array $amazon = array())
 {
     //reset meta and response
     $this->_meta = array();
     $this->_response = NULL;
     //get host - bucket1.s3.amazonaws.com
     $host = $this->_getHost($bucket);
     //get url - http://bucket1.s3.amazonaws.com/some/path
     $url = $this->_getUrl($host, $path, $query);
     //get path - /bucket1/some/path
     $path = $this->_getPath($bucket, $path);
     //get headers
     ksort($amazon);
     $curlHeaders = $amazonHeaders = array();
     $headers['Host'] = $host;
     $headers['Date'] = gmdate('D, d M Y H:i:s T');
     foreach ($amazon as $header => $value) {
         $curlHeaders[] = $header . ': ' . $value;
         $amazonHeaders[] = strtolower($header) . ':' . $value;
     }
     foreach ($headers as $header => $value) {
         $curlHeaders[] = $header . ': ' . $value;
     }
     $amazonHeaders = "\n" . implode("\n", $amazonHeaders);
     if (!trim($amazonHeaders)) {
         $amazonHeaders = NULL;
     }
     if (!isset($headers['Content-MD5'])) {
         $headers['Content-MD5'] = NULL;
     }
     if (!isset($headers['Content-Type'])) {
         $headers['Content-Type'] = NULL;
     }
     //get signature
     $signature = array($action, $headers['Content-MD5'], $headers['Content-Type'], $headers['Date'] . $amazonHeaders, $path);
     $signature = implode("\n", $signature);
     if ($headers['Host'] == 'cloudfront.amazonaws.com') {
         $signature = $headers['Date'];
     }
     $curlHeaders[] = 'Authorization: ' . $this->_getSignature($signature);
     //setup curl
     $curl = Eden_Curl::i()->setUserAgent('S3/php')->setUrl($url)->setHeaders($curlHeaders)->setHeader(false)->setWriteFunction(array(&$this, '_responseWriteCallback'))->setHeaderFunction(array(&$this, '_responseHeaderCallback'))->when($this->_ssl)->verifyHost(true)->verifyPeer(true)->endWhen();
     // Request types
     switch ($action) {
         case 'GET':
             break;
         case 'PUT':
         case 'POST':
             // POST only used for CloudFront
             $curl->setPut(true)->setInFile($data[0])->setInFileSize($data[1]);
             break;
         case 'HEAD':
             $curl->setCustomRequest('HEAD')->setNobody(true);
             break;
         case 'DELETE':
             $curl->setCustomRequest('DELETE');
             break;
     }
     $response = $curl->getResponse();
     $meta = $curl->getMeta();
     // Execute, grab errors
     if ($response) {
         $this->_meta['code'] = $meta['info'];
         $this->_meta['error'] = array();
     } else {
         $this->_meta['error'] = array('code' => $meta['error_code'], 'message' => $meta['error_message'], 'path' => $path);
     }
     // Parse body into XML
     if (empty($this->_meta['error']) && isset($this->_meta['headers']['type']) && $this->_meta['headers']['type'] == 'application/xml' && strlen($this->_response) > 0) {
         $this->_response = simplexml_load_string($this->_response);
         if (!in_array($this->_meta['code'], array(200, 204)) && isset($this->_response->Code, $this->_response->Message)) {
             $this->_meta['error'] = array('code' => $this->_response->Code, 'message' => $this->_response->Message, 'path' => $path);
             if (isset($this->_response->Resource)) {
                 $this->_meta['error']['path'] = $this->_response->Resource;
             }
             $this->_response = NULL;
         }
     }
     return $this;
 }