/** * Talk to new relic * * @param string $restPoint * @return string */ public function talkToNewRelic($restPoint) { $headers = array('x-api-key:' . $this->_api_key); $http = new Varien_Http_Adapter_Curl(); $http->write('GET', 'https://api.newrelic.com/api/v1/accounts/' . $this->_account_Id . '/' . $restPoint . '.xml', '1.1', $headers); $response = $http->read(); $response = Zend_Http_Response::extractBody($response); return $response; }
public function sendRequest($request, $parameters = array()) { if (!$this->code || !$this->username || !$this->password) { return false; } if ($request != 'verifyUser' && !$this->session) { return false; } $parameters['sessionKey'] = $this->session; $parameters['request'] = $request; $parameters['version'] = '1.0'; $parameters['clientCode'] = $this->code; $url = $this->getUrl(); $http = new Varien_Http_Adapter_Curl(); $http->setConfig(array('timeout' => 100)); // $http->write(Zend_Http_Client::POST, $parameters); $http->write(Zend_Http_Client::POST, $url, CURL_HTTP_VERSION_1_0, array(), $parameters); $responseBody = Zend_Http_Response::extractBody($http->read()); $http->close(); if (Mage::getStoreConfig('eepohs_erply/general/log_requests')) { Mage::log("REQUEST URL: " . $url . "\nREQUEST PARAMETERS:\n" . print_r($parameters, true) . "\nRESPONSE:\n" . $responseBody, null, self::REQUEST_LOG); } // $http = new Varien_Http_Adapter_Curl(); // $config = array('timeout' => 30); // // $http->setConfig($config); // $http->write(Zend_Http_Client::POST, $url, '1.0', array(), http_build_query($parameters)); // $content = Zend_Http_Response::extractBody($http->read()); // print_r(Zend_Http_Response::extractHeaders($http->read())); //return $content; // $ch = curl_init(); // curl_setopt($ch, CURLOPT_URL, $url); // curl_setopt($ch, CURLOPT_HEADER, 1); // curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // curl_setopt($ch, CURLOPT_POST, true); // curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters); // // if (curl_exec($ch) === false) // return false; // // $content = curl_multi_getcontent($ch); // curl_close($ch); // list($header1, $header2, $body) = explode("\r\n\r\n", $content, 3); return $responseBody; }
/** * Talk to pin gateway * * @param array $data * @param string $endPoint * @return object */ protected function talkToGateway($data, $endPoint, $proto = Zend_Http_Client::POST) { $url = mage::helper('pinpayments')->getGatewayUrl() . '1/' . $endPoint; $secretKey = mage::getStoreConfig('payment/pinpayments/secret_api_key'); if ($proto == Zend_Http_Client::PUT) { $result = exec("curl {$url} -u {$secretKey}: -X PUT -d email={$data['email']} -d card_token={$data['card_token']}", $output, $return_var); } else { $curl = new ProxiBlue_PinPayments_Varien_Http_Adapter_Curl(); $curl->setConfig(array('timeout' => 15)); $curl->setConfig(array('userpwd' => mage::getStoreConfig('payment/pinpayments/secret_api_key') . ":")); $curl->write($proto, $url, '1.1', null, $data); $curlData = $curl->read(); $result = Zend_Http_Response::extractBody($curlData); $curl->close(); $result = json_decode($result); } return $result; }
/** * Make sure a response with some leading whitespace in the response body * does not get modified (see ZF-1924) * */ public function testLeadingWhitespaceBody() { $body = Zend_Http_Response::extractBody($this->readResponse('response_leadingws')); $this->assertEquals($body, "\r\n\t \n\r\tx", 'Extracted body is not identical to expected body'); }
public function testExtractorsOnInvalidString() { // Try with an empty string $response_str = ''; $this->assertTrue(Zend_Http_Response::extractCode($response_str) === false); $this->assertTrue(Zend_Http_Response::extractMessage($response_str) === false); $this->assertTrue(Zend_Http_Response::extractVersion($response_str) === false); $this->assertTrue(Zend_Http_Response::extractBody($response_str) === ''); $this->assertTrue(Zend_Http_Response::extractHeaders($response_str) === array()); }
public function sendMessage(Xcom_Xfabric_Model_Message $message, array $options = array()) { $url = $this->prepareUri($message->getTopic()); Mage::getSingleton('xcom_xfabric/debug')->start('Send Request to ' . $url->getUri(), $message->getTopic(), serialize($message->getHeaders()), isset($options['message_data']) ? $options['message_data'] : ''); $adapter = $this->_getAdapter(); $adapter->setConfig($this->_config); $adapter->write(Zend_Http_Client::POST, $url, '1.1', $this->_prepareHeaders($message->getHeaders()), $message->getBody()); $result = $adapter->read(); $error = ''; $httpCode = $adapter->getInfo(CURLINFO_HTTP_CODE); if ($adapter->getErrno()) { $error = $adapter->getError(); } if (!$result || $error) { Mage::getSingleton('xcom_xfabric/debug')->stop('Unable to complete the request.', $message->getTopic(), $result, 'Unable to complete the request. ' . $error); switch ($httpCode) { case '400': $errorText = 'Bad request. '; break; case '401': $errorText = 'Request is unauthorized. '; break; case '403': $errorText = 'Request is forbidden. '; break; case '404': $errorText = 'Not Found. '; break; case '413': $errorText = 'Message is too large'; break; default: $errorText = ''; break; } throw Mage::exception('Xcom_Xfabric', Mage::helper('xcom_xfabric')->__('Unable to complete the request. ') . $errorText . $error); } $zendHttpCode = Zend_Http_Response::extractCode($result); $zendHttpMessage = Zend_Http_Response::extractMessage($result); $zendHttpBody = Zend_Http_Response::extractBody($result); if ($zendHttpCode != '200') { Mage::getSingleton('xcom_xfabric/debug')->stop('Unable to complete the request.', $message->getTopic(), $result, $zendHttpMessage . ' ' . $zendHttpBody); throw Mage::exception('Xcom_Xfabric', $zendHttpMessage . ' ' . $zendHttpBody, $zendHttpCode); } if (!empty($options['synchronous']) && !$error) { $response = $this->_getResponseMessage($message->getCorrelationId()); if (!$response) { Mage::getSingleton('xcom_xfabric/debug')->stop('Response is not received', $message->getTopic(), $result, 'No Errors'); throw Mage::exception('Xcom_Xfabric', Mage::helper('xcom_xfabric')->__('Unable to complete the request. Please refer to the User Guide ' . 'to verify your settings and try again. If the error persists, contact your administrator.')); } return $response; } Mage::getSingleton('xcom_xfabric/debug')->stop('No Response is been waiting', $message->getTopic(), $result, $error); return true; }
/** * Talk to NewRelic API * * @param array $data * @return string */ public function talkToNewRelic($data) { $headers = array('x-api-key:' . $this->_api_key); $http = new Varien_Http_Adapter_Curl(); $http->write('POST', 'https://rpm.newrelic.com/deployments.xml', '1.1', $headers, $data); $response = $http->read(); $response = Zend_Http_Response::extractBody($response); return $response; }
/** * Make sure a response with some leading whitespace in the response body * does not get modified (see ZF-1924) * */ public function testLeadingWhitespaceBody() { $message = file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'response_leadingws'); $body = Zend_Http_Response::extractBody($message); $this->assertEquals($body, "\r\n\t \n\r\tx", 'Extracted body is not identical to expected body'); }
public function createApiGet($path, $timeout = self::DEFAULT_TIMEOUT) { try { $config = array('timeout' => $timeout); $http = new Varien_Http_Adapter_Curl(); $feed_url = self::YOTPO_UNSECURED_API_URL . "/" . $path; $http->setConfig($config); $http->write(Zend_Http_Client::GET, $feed_url, '1.1', array('Content-Type: application/json')); $resData = $http->read(); return array("code" => Zend_Http_Response::extractCode($resData), "body" => json_decode(Zend_Http_Response::extractBody($resData))); } catch (Exception $e) { Mage::log('error: ' . $e); } }