public function purge() { do { $response = $this->connection->reserve(0); if ($response->id) { $this->connection->delete($response->id); } } while ($response->status == 'RESERVED'); return true; }
/** * Send request and return response data. * * @param string $method * @param string $path * @param array $data the parameters for the request. For GET/DELETE this is the query string * for POST/PUT this is the body * @param array $options passed to request and socket * @return string */ 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(); $this->last = (object) compact('request', 'response'); return $options['return'] == 'body' && $response ? $response->body() : $response; }
/** * Send request and return response data. Will open the connection if * needed and always close it after sending the request. * * Will automatically authenticate when receiving a `401` HTTP status code * then continue retrying sending initial request. * * @param string $method * @param string $path * @param array $data the parameters for the request. For GET/DELETE this is the query string * for POST/PUT this is the body * @param array $options passed to request and socket * @return string */ 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; }
public function disconnect() { return $this->connection->close(); }