send() публичный Метод

Will automatically authenticate when receiving a 401 HTTP status code then continue retrying sending initial request.
public send ( string $method, string $path = null, array $data = [], array $options = [] ) : string
$method string
$path string
$data array the parameters for the request. For GET/DELETE this is the query string for POST/PUT this is the body
$options array passed to request and socket
Результат string
 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);
 }
Пример #2
0
 /**
  * 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;
 }
Пример #3
0
 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']);
 }
Пример #4
0
 /**
  * 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;
 }