public function Send(HttpContext $context) { if (in_array($context->getMethod(), array('post', 'put'))) { $context->setHeaders('Content-Length: ' . strlen($context->getBody())); } curl_setopt($this->_cUrl, CURLOPT_URL, $context->getRequestURL()); curl_setopt($this->_cUrl, CURLOPT_CUSTOMREQUEST, $context->getMethod()); curl_setopt($this->_cUrl, CURLOPT_POSTFIELDS, $context->getBody()); curl_setopt($this->_cUrl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($this->_cUrl, CURLOPT_HEADER, 1); if (substr($context->getHost(), 0, 5) == 'https') { curl_setopt($this->_cUrl, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($this->_cUrl, CURLOPT_SSL_VERIFYPEER, 0); } curl_setopt($this->_cUrl, CURLOPT_HTTPHEADER, $context->getHeaders()); $raw = curl_exec($this->_cUrl); $result = new HttpResult(); $pos = strpos($raw, "\r\n\r\n"); $result->protocol = substr($raw, 0, 8); $result->headers = explode("\r\n", substr($raw, 0, $pos)); $result->body = substr($raw, $pos + 4); $info = curl_getinfo($this->_cUrl); $result->statusCode = $info['http_code']; curl_close($this->_cUrl); return $result; }
public function Delete() { $id = $this->dto->Id; if (empty($id)) { throw new \Exception('Argumento \\"Id\\" é necessario', 1); } $context = new HttpContext(); $context->setHeaders($this->_header); $context->setAuthorization($this->auth); $context->setMethod('DELETE'); $context->setHost($this->_host); $context->setRequestURI($this->_requestURI . '/' . $this->dto->Id); return $this->_machine->Send($context); }
public function Post() { if (!$this->isValid($this->dto)) { throw new \Exception('Campos obrigatórios não foram informados: ' . implode(', ', $this->getError()), 1); } $context = new HttpContext(); $context->setHeaders($this->_header); $context->setAuthorization($this->auth); $context->setMethod('POST'); $context->setHost($this->_host); $context->setRequestURI($this->_requestURI); $this->_requestJson = $this->dto->fields(); $context->setBody($this->_requestJson); return $this->_machine->Send($context); }
public function Get() { $context = new HttpContext(); $context->setHeaders($this->_header); $context->setAuthorization($this->auth); $context->setMethod('GET'); $context->setHost($this->_host); $context->setRequestURI($this->_requestURI); return $this->_machine->Send($context); }
public function GetByPagamento() { $context = new HttpContext(); $context->setHeaders($this->_header); $context->setAuthorization($this->auth); $context->setMethod('GET'); $context->setHost($this->_host); $context->setRequestURI($this->_requestURI . '?data=' . $this->dto->DataPagamento); return $this->_machine->Send($context); }
public function GetByPeriodo() { $context = new HttpContext(); $context->setHeaders($this->_header); $context->setAuthorization($this->auth); $context->setMethod('GET'); $context->setHost($this->_host); $context->setRequestURI(sprintf('%s/%s/%s', $this->_requestURI, $this->dto->DataInicio, $this->dto->DataFim)); return $this->_machine->Send($context); }
public function Delete($id) { $this->dto->Id = $id; $context = new HttpContext(); $context->setHeaders($this->_header); $context->setAuthorization($this->auth); $context->setMethod('DELETE'); $context->setHost($this->_host); $context->setRequestURI($this->_requestURI . '/' . $this->dto->Id); return $this->_machine->Send($context); }
public function GetByTipo($tipo) { $this->dto->Tipo = $tipo; $context = new HttpContext(); $context->setHeaders($this->_header); $context->setAuthorization($this->auth); $context->setMethod('GET'); $context->setHost($this->_host); $context->setRequestURI($this->_requestURI . '/' . $this->dto->Tipo); return $this->_machine->Send($context); }
public function GetByCep() { $context = new HttpContext(); $context->setHeaders($this->_header); $context->setMethod('GET'); $context->setHost($this->_host); $context->setRequestURI($this->_requestURI . '/' . $this->dto->CEP); return $this->_machine->Send($context); }