public function send($method, $path = null, $data = array(), array $options = array())
{
$defaults = array('return' => 'body');
$options += $defaults;
$request = $this->_request($method, $path, $data, $options);
$options += array('message' => $request);
if (!$this->connection || !$this->connection->open($options)) {
return;
}
$response = $this->connection->send($request, $options);
$this->connection->close();
if ($response->status['code'] == 401 && ($auth = $response->digest())) {
$request->auth = $auth;
$this->connection->open(array('message' => $request) + $options);
$response = $this->connection->send($request, $options);
$this->connection->close();
}
$this->last = (object) compact('request', 'response');
$handlers = $this->_responseTypes;
$handler = isset($handlers[$options['return']]) ? $handlers[$options['return']] : null;
return $handler ? $handler($response) : $response;
}