当前位置: 首页>>代码示例>>PHP>>正文


PHP Varien_Http_Client类代码示例

本文整理汇总了PHP中Varien_Http_Client的典型用法代码示例。如果您正苦于以下问题:PHP Varien_Http_Client类的具体用法?PHP Varien_Http_Client怎么用?PHP Varien_Http_Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Varien_Http_Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: executeApiCall

 /**
  * Only executed if sendOrderStatus validates true for orderStatuses, order data and API data is fetched
  * URL is then formed and sent as a GET request, response is then decoded with boolean values. Exception 
  * thrown if the request cannot be successfully made. Warning thrown if connection is successfully but
  * credentials are not correct
  *
  * @param $order
  * @param $orderStatus
  * @throws throwException
  */
 public function executeApiCall($order, $orderStatus)
 {
     $apiUrl = Mage::helper('orderstatus')->getApiUrl();
     $apiServiceName = Mage::helper('orderstatus')->getApiServiceName();
     $apiUsername = Mage::helper('orderstatus')->getApiUsername();
     $apiPassword = Mage::helper('orderstatus')->getApiPassword();
     $apiMethod = Mage::helper('orderstatus')->getApiMethod();
     $apiDebuggingEnabled = Mage::helper('orderstatus')->isDebuggingEnabled();
     $orderNumber = $order->getIncrementId();
     $orderDateStatusChanged = $order->getUpdatedAt();
     $orderStatus = $orderStatus;
     $apiRequest = $apiUrl . $apiMethod . "?service=" . $apiServiceName . "&username=" . $apiUsername . "&password=" . $apiPassword . "&orderno=" . $orderNumber . "&date=" . str_replace(" ", "_", $orderDateStatusChanged) . "&status=" . $orderStatus;
     try {
         $client = new Varien_Http_Client($apiRequest);
         $client->setMethod(Varien_Http_Client::GET);
         $response = $client->request();
         if ($apiDebuggingEnabled) {
             Mage::getSingleton('adminhtml/session')->addWarning("API Request : " . $apiRequest);
             Mage::getSingleton('adminhtml/session')->addWarning("API Response : " . $response->getBody());
         }
         if ($response->isSuccessful()) {
             Mage::getSingleton('adminhtml/session')->addSuccess('Touch Retail API connection was successful.');
             $responseJson = json_decode($response->getBody());
             if ($responseJson->serviceresult->success == 1) {
                 Mage::getSingleton('adminhtml/session')->addSuccess('Order status was successfully sent to Touch Retail.');
             } else {
                 Mage::getSingleton('adminhtml/session')->addWarning('Unable to send order status to Touch Retail, please check your API method System > Configuration menu.');
             }
         } else {
             Mage::getSingleton('adminhtml/session')->addWarning('Unable to connect to Touch Retail, please check your API credentials in System > Configuration menu.');
         }
     } catch (Exception $e) {
         Mage::throwException('Unable to send your API request, this maybe due to a malformed URL.');
     }
 }
开发者ID:Rafterman82,项目名称:Touch-Retail-Order-Status-API,代码行数:45,代码来源:Observer.php

示例2: indexAction

 /**
  * run synchronize customer to Magestore
  */
 public function indexAction()
 {
     // Turn Off
     die('x');
     $session = Mage::getSingleton('core/session');
     $limit = $this->getRequest()->getParam('limit', 10);
     $start = (int) $session->getLastAccountId();
     // Customer info
     $customers = Mage::getResourceModel('customer/customer_collection');
     $customers->addFieldToFilter('entity_id', array('gt' => $start))->addAttributeToSelect('email')->addAttributeToSelect('firstname')->addAttributeToSelect('lastname')->addAttributeToSelect('password_hash')->getSelect()->limit($limit)->order('entity_id ASC');
     if (!$customers->count()) {
         echo '0';
         return;
     }
     $customerData = array();
     foreach ($customers as $customer) {
         $customerData[] = array('email' => $customer->getEmail(), 'firstname' => $customer->getFirstname(), 'lastname' => $customer->getLastname(), 'password_hash' => $customer->getPasswordHash());
         $start = $customer->getId();
     }
     // Run query
     $url = Mage::getStoreConfig('subsystem/general/account') . 'add';
     $client = new Varien_Http_Client($url);
     $client->setParameterPost('pk', Magestore_Subsystem_Model_Observer::PK);
     $client->setParameterPost('data', Zend_Json::encode($customerData));
     $response = $client->request(Varien_Http_Client::POST);
     // Update start to session
     $session->setLastAccountId($start);
     echo $start;
     echo '<br>' . $response->getBody();
 }
开发者ID:Thinlt,项目名称:simicart,代码行数:33,代码来源:IndexController.php

示例3: queryMaxMind

 function queryMaxMind($params)
 {
     $servers = array("http://minfraud1.maxmind.com", "http://minfraud2.maxmind.com");
     $return = array();
     $error = false;
     foreach ($servers as $server) {
         $http = new Varien_Http_Client($server . "/app/ccv2r");
         $http->setParameterPost($params);
         try {
             $response = $http->request('POST');
         } catch (Exception $e) {
             continue;
         }
         if ($response->getStatus() != '200') {
             continue;
         }
         foreach (explode(";", $response->getBody()) as $keyval) {
             $bits = explode("=", $keyval);
             if (count($bits) > 1) {
                 list($key, $value) = $bits;
                 $return[$key] = $value;
             }
         }
         if (!empty($return)) {
             break;
         }
     }
     if (empty($return)) {
         $return['errmsg'] = "Could not contact MaxMind servers.";
         $return['err'] = "FATAL_ERROR";
     }
     return $return;
 }
开发者ID:AleksNesh,项目名称:pandora,代码行数:33,代码来源:Data.php

示例4: __construct

 /**
  * Initialise our object with the full rates retrieved from Privatbankrates as the
  * free version only allows us to get the complete set of rates. But that's ok, we are
  * caching it and then processing the individual rates
  *
  * @throws Exception
  */
 public function __construct()
 {
     $this->_httpClient = new Varien_Http_Client();
     $url = $this->_url;
     $response = $this->_httpClient->setUri($url)->setConfig(array('timeout' => Mage::getStoreConfig('currency/pm_privatbankrates/timeout')))->request('GET')->getBody();
     // response is in json format
     if (!$response) {
         $this->_messages[] = Mage::helper('pm_privatbankrates')->__('Cannot retrieve rate from %s.', $url);
     } else {
         // check response content - returns array
         $response = Zend_Json::decode($response);
         if (array_key_exists('error', $response)) {
             $this->_messages[] = Mage::helper('pm_privatbankrates')->__('API returned error %s: %s', $response['status'], $response['description']);
         } elseif (array_key_exists('base_ccy', $response[0])) {
             $rates = array();
             $rates['UAH'] = array('buy' => 1, 'sale' => 1);
             foreach ((array) $response as $currency) {
                 $rates[$currency['ccy']] = $currency;
             }
             $this->_rates = $rates;
         } else {
             Mage::log('Privatbankrates API request: %s', $url);
             Mage::log('Privatbankrates API response: ' . print_r($response, true));
             $this->_messages[] = Mage::helper('pm_privatbankrates')->__('Unknown response from API, check system.log for details.');
         }
     }
 }
开发者ID:printminion,项目名称:Printminion_Privatbankrates,代码行数:34,代码来源:Privatbankrates.php

示例5: apiCall

 /**
  * Create an api request and inject the app token.
  *
  * @param string Path to the rest method being called
  * @param string Request method: GET, POST, PUT or DELETE
  * @param mixed An array of parameters or raw post data.  Raw data isn't accepted for GET.
  * @return null
  * @throws Exception Invalid or failed requests throw exceptions.
  */
 protected function apiCall($path, $requestMethod, $params = array())
 {
     $requestMethod = strtoupper($requestMethod);
     switch ($requestMethod) {
         case 'GET':
             $setParamMethod = 'setParameterGet';
             if (!is_array($params)) {
                 throw new Exception('GET parameters can\'t be provided as raw data.');
             }
             break;
         case 'POST':
         case 'PUT':
         case 'DELETE':
             $setParamMethod = 'setParameterPost';
             break;
         default:
             throw new Exception('Invalid request method');
     }
     $client = new Varien_Http_Client($this->serverLocation . $path);
     $client->setMethod($requestMethod);
     if (is_array($params)) {
         foreach ($params as $paramKey => $paramValue) {
             call_user_func(array($client, $setParamMethod), $paramKey, $paramValue);
         }
     } else {
         $client->setRawData($params);
     }
     $response = $client->request();
     if ($response->isSuccessful()) {
         return json_decode($response->getBody());
     } else {
         throw new Exception('Request failed');
     }
 }
开发者ID:remtcs,项目名称:Implement-Module-for-prediction.io,代码行数:43,代码来源:MyrrixSDK.php

示例6: getClient

 /**
  * Client GET call
  *
  * @param $string, $string
  * @return Varien_Http_Client $response
  */
 private function getClient($apiKey, $url)
 {
     $client = new Varien_Http_Client($url);
     $client->setMethod(Varien_Http_Client::GET);
     $client->setHeaders('Authorization', 'Token token="' . $apiKey . '"');
     return $client;
 }
开发者ID:hueyl77,项目名称:fourwindsgear,代码行数:13,代码来源:Client.php

示例7: getHttpClient

 /**
  * Get the Http Client to use for the request to reCAPTCHA
  *
  * @return Varien_Http_Client
  */
 public function getHttpClient()
 {
     if (is_null($this->_client)) {
         $this->_client = new Varien_Http_Client();
     }
     $this->_client->setUri(self::REQUEST_URL);
     return $this->_client;
 }
开发者ID:crysix,项目名称:Recaptcha,代码行数:13,代码来源:Request.php

示例8: restRequest

 public function restRequest($method, $params)
 {
     $result = null;
     $url = $this->_getRestUrl($method);
     $data = $this->_restDataFormat($method, $params);
     $httpClient = new Varien_Http_Client();
     $result = $httpClient->setUri($url)->setHeaders('Content-Type: text/xml; charset=UTF-8')->setRawData($data)->request(Varien_Http_Client::POST)->getBody();
     return $result;
 }
开发者ID:amr-z,项目名称:shop-and-ship,代码行数:9,代码来源:Data.php

示例9: tunnelAction

 public function tunnelAction()
 {
     $httpClient = new Varien_Http_Client();
     if ($ga = $this->getRequest()->getParam('ga')) {
         if ($params = unserialize(base64_decode(urldecode($ga)))) {
             $response = $httpClient->setUri(Mage_Adminhtml_Block_Dashboard_Graph::API_URL)->setParameterGet($params)->setConfig(array('timeout' => 15))->request('GET');
             $headers = $response->getHeaders();
             $this->getResponse()->setHeader('Content-type', $headers['Content-type'])->setBody($response->getBody());
         }
     }
 }
开发者ID:HelioFreitas,项目名称:magento-pt_br,代码行数:11,代码来源:DashboardController.php

示例10: request

 /**
  * @param array $data Array of each installed Fontis extensions version
  * @return string
  * @throws Exception
  */
 public function request($data)
 {
     $client = new Varien_Http_Client(Mage::helper('fontis_info')->getInfoUrl(), array('keepalive' => true));
     $client->setParameterPost('data', $data);
     // If we accept gzip encoding and the response isn't actually chunked, Zend_Http_Response will throw
     // an exception. Unfortunately, this means we can't use gzip encoded responses at this time.
     $client->setHeaders('Accept-encoding', 'identity');
     $response = $client->request(Varien_Http_Client::POST);
     if ($response->isError()) {
         // if the request fails, throw an exception
         throw new Exception('Error getting info data: ' . $response->getStatus() . ' ' . $response->getMessage());
     }
     return $response->getBody();
 }
开发者ID:vstorm83,项目名称:ausport,代码行数:19,代码来源:Info.php

示例11: tunnelAction

 public function tunnelAction()
 {
     $httpClient = new Varien_Http_Client();
     $gaData = $this->getRequest()->getParam('ga');
     $gaHash = $this->getRequest()->getParam('h');
     if ($gaData && $gaHash) {
         $newHash = Mage::helper('adminhtml/dashboard_data')->getChartDataHash($gaData);
         if ($newHash == $gaHash) {
             $params = json_decode(base64_decode(urldecode($gaData)), true);
             if ($params) {
                 $response = $httpClient->setUri(Mage_Adminhtml_Block_Dashboard_Graph::API_URL)->setParameterGet($params)->setConfig(array('timeout' => 5))->request('GET');
                 $headers = $response->getHeaders();
                 $this->getResponse()->setHeader('Content-type', $headers['Content-type'])->setBody($response->getBody());
             }
         }
     }
 }
开发者ID:pminternetsolutions,项目名称:Magento-Pre-Patched-Files,代码行数:17,代码来源:DashboardController.php

示例12: tunnelAction

 public function tunnelAction()
 {
     //if(!Mage::helper('magenotification')->checkLicenseKeyAdminController($this)){ return; }
     $httpClient = new Varien_Http_Client();
     $gaData = $this->getRequest()->getParam('ga');
     $gaHash = $this->getRequest()->getParam('h');
     if ($gaData && $gaHash) {
         $newHash = Mage::helper('adminhtml/dashboard_data')->getChartDataHash($gaData);
         if ($newHash == $gaHash) {
             if ($params = unserialize(base64_decode(urldecode($gaData)))) {
                 $response = $httpClient->setUri(Mage_Adminhtml_Block_Dashboard_Graph::API_URL)->setParameterGet($params)->setConfig(array('timeout' => 5))->request('GET');
                 $headers = $response->getHeaders();
                 $this->getResponse()->setHeader('Content-type', $headers['Content-type'])->setBody($response->getBody());
             }
         }
     }
 }
开发者ID:cabrerabywaters,项目名称:magentoSunshine,代码行数:17,代码来源:StatisticController.php

示例13: getCrawlerClient

 /**
  * Get the crawler http client
  *
  * @return Varien_Http_Client
  */
 public function getCrawlerClient()
 {
     if (is_null($this->_crawlerClient)) {
         $this->_crawlerClient = new Varien_Http_Client(null, array('useragent' => sprintf('Nexcessnet_Turpentine/%s Magento/%s Varien_Http_Client', Mage::helper('turpentine/data')->getVersion(), Mage::getVersion()), 'keepalive' => true));
         $this->_crawlerClient->setCookie('frontend', 'crawler-session');
     }
     return $this->_crawlerClient;
 }
开发者ID:nexcess,项目名称:magento-turpentine,代码行数:13,代码来源:Cron.php

示例14: codesAction

 /**
  * Retrieve js scripts by parsing remote Google Optimizer page
  */
 public function codesAction()
 {
     if ($this->getRequest()->getQuery('url')) {
         $client = new Varien_Http_Client($this->getRequest()->getQuery('url'));
         $response = $client->request(Varien_Http_Client::GET);
         $result = array();
         if (preg_match_all('/<textarea[^>]*id="([_a-zA-Z0-9]+)"[^>]*>([^<]+)<\\/textarea>/', $response->getRawBody(), $matches)) {
             $c = count($matches[1]);
             for ($i = 0; $i < $c; $i++) {
                 $id = $matches[1][$i];
                 $code = $matches[2][$i];
                 $result[$id] = $code;
             }
         }
         $this->getResponse()->setBody(Zend_Json::encode($result));
     }
 }
开发者ID:ronseigel,项目名称:agent-ohm,代码行数:20,代码来源:IndexController.php

示例15: _beforeSave

 /**
  * Verify installation id in Worldpay registration system to reduce configuration failures (experimental)
  *
  * @return Phoenix_Worldpay_Model_Config_Backend_Instid
  */
 protected function _beforeSave()
 {
     try {
         if ($this->getValue()) {
             $client = new Varien_Http_Client();
             $client->setUri((string) Mage::getConfig()->getNode('phoenix/worldpay/verify_url'))->setConfig(array('timeout' => 10))->setHeaders('accept-encoding', '')->setParameterPost('inst_id', $this->getValue())->setMethod(Zend_Http_Client::POST);
             $response = $client->request();
             //                $responseBody = $response->getBody();
             //                if (empty($responseBody) || $responseBody != 'VERIFIED') {
             // verification failed. throw error message (not implemented yet).
             //                }
             // okay, inst_id verified. continue saving.
         }
     } catch (Exception $e) {
         // verification system unavailable. no further action.
     }
     return parent::_beforeSave();
 }
开发者ID:newedge-media,项目名称:iwantmymeds,代码行数:23,代码来源:Instid.php


注:本文中的Varien_Http_Client类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。