public function send($method, $path = null, $data = array(), array $options = array()) { $defaults = array('headers' => array('User-Agent' => 'Lava Surfboard')); $xml = new \SimpleXmlElement('<request method="' . $path . '"></request>'); foreach ($data as $key => $val) { if ($val != null) { $xml->{$key} = $val; } } $xmlString = $xml->asXML(); $data = str_replace("<?xml version=\"1.0\"?>\n", '<!--?xml version="1.0" encoding="utf-8"?-->', $xmlString); $path = '/api/2.1/xml-in'; $response = parent::send($method, $path, $data, $options + $defaults); return new \SimpleXmlElement($response); }
/** * Send request with the given options and data. The token should be part of the options. * * @param string $method * @param string $path * @param array $data encoded for the request * @param array $options oauth parameters * - headers : send parameters in the header. (default: true) * - realm : the realm to authenticate. (default: app directory name) * @return mixed the response from api call */ public function send($method, $path = null, $data = array(), array $options = array()) { $defaults = array('headers' => true, 'realm' => basename(LITHIUM_APP_PATH)); $options += $defaults + $this->_config; $url = $this->config($path); $oauth = $this->sign($options + compact('data', 'url', 'method')); if ($options['headers']) { $header = 'OAuth realm="' . $options['realm'] . '",'; foreach ($oauth as $key => $val) { $header .= $key . '="' . rawurlencode($val) . '",'; unset($oauth[$key]); } $options['headers'] = array('Authorization' => $header); } $options['host'] = $options['proxy'] ? $options['proxy'] : $options['host']; $response = parent::send($method, $url, $data + $oauth, $options); if (strpos($response, 'oauth_token=') !== false) { return $this->_decode($response); } return $response; }
public function testSendConfiguringConnection() { $http = new Service($this->_testConfig); $result = $http->send('get', 'some-path/stuff', array(), array('someKey' => 'someValue')); $config = array_pop($http->connection->configs); $this->assertEqual('someValue', $config['someKey']); }
/** * Send request with the given options and data. The token should be part of the options. * * @param string $method * @param string $path * @param array $data encoded for the request * @param array $options oauth parameters * - headers : send parameters in the header. (default: true) * - realm : the realm to authenticate. (default: app directory name) * @return mixed the response from api call */ public function send($method, $path = null, $data = array(), array $options = array()) { self::_parseParams($options); $data += $options['params']; $defaults = array('headers' => true, 'realm' => basename(LITHIUM_APP_PATH)); $url = $this->config($path); $options['host'] = $this->_config['proxy'] ?: $this->_config['host']; $response = parent::send($method, $url, $data); $hasToken = strpos($response, 'access_token=') !== false; $isJson = strpos($response, '"data":') !== false; if ($hasToken && !$isJson) { return $this->_decode($response); } return $response; }