Recebe uma string em JSON para realizar a abertura do Ticket. * * @param string $jsonRequest string em JSON. * @return boolean */ public function openTicket($id, $subject, $body, $priority, $protocolo = null) { $this->debug = debug_backtrace(); if ($this->getArgs(func_get_args())) { $ticket = array( 'ticket' => array( 'via_id' => $id, 'subject' => $subject, 'external_id' => $protocolo, "description" => "Ticket Cetral Telefonica", 'comment' => array( 'body' => $body ), 'priority' => $priority ) ); $this->params = json_encode($ticket); $this->setMetodo('tickets'); return $this->setParams(); } else { return false; } } /** * @param string $external_id * @return boolean */ public function listTickeByExternalId($external_id) { $this->debug = debug_backtrace(); if ($this->getArgs(func_get_args())) { $this->params = null; $this->setMetodo('tickets.json?external_id=' . $external_id); return $this->setParams(); } else { return false; } } ######################################################################## ## FUNCOES DEFAULT DA CLASSE ## ######################################################################## /** * Coleta as informacoes iniciais para o inicio da integracao com a API. * * @param string $token * @param string $url * @param boolean $log */ public function __construct($token, $url, $log = false) { $this->token = base64_encode($token); $this->url = "https://{$url}.zendesk.com/api/v2/"; $this->setLog($log); $this->log->info("Iniciando integracao", debug_backtrace()); } /** * Parametriza o metodo utilizado para a consulta. * * @param type $metodo */ private function setMetodo($metodo) { $this->metodo = $metodo; } /** * Escreve a query para ser passada para o curl * * @param string $query */ private function setQuery($query) { return $this->query .= $query; } /** * retorna a string pronta da query do curl e limpa a variavel. * * @return string $query */ private function getQuery() { $query = $this->query; unset($this->query); return $query; } /** * Constroi de forma dinamica a string para ser passada para a execucao do Curl * * @void */ private function curl() { $this->curl = curl_init(); $this->log->debug("URL: {$this->url}{$this->metodo}", debug_backtrace()); curl_setopt($this->curl, CURLOPT_URL, $this->url . $this->metodo); curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, true); if($this->params){ curl_setopt($this->curl, CURLOPT_POSTFIELDS, $this->params); } curl_setopt($this->curl, CURLOPT_TIMEOUT, 10); curl_setopt($this->curl, CURLOPT_HTTPHEADER, array( 'Content-Type:application/json', 'Authorization: Basic ' . $this->token )); $this->log->debug("Curl: {$this->curl}", debug_backtrace()); } /** * Recebe array de forma de indice e valor * * @example array("qtype" => 'test_api', "query" => '123', "oper" => '=') * * @obs sempre chamar a função debug_backtrace() para ser disponível em log * * @param type $params * @debug_track function debug_backtrace() */ private function setParams() { $this->curl(); unset($this->params); return $this->exec(); } /** * Recebe as informações e realiza a execucao da API * * @void */ private function exec() { /** * Caso tenha problema de requisição */ $content = curl_exec($this->curl); if (curl_errno($this->curl)) { $this->log->error(curl_error($this->curl), debug_backtrace()); curl_close($this->curl); //$this->audioError(); return false; } curl_close($this->curl); return $this->response($content); } /** * Prepara dos dados para ser transmitidos para o metodo a ser retornado a * integracao. * * @return array */ private function response($data) { $this->log->debug("Reponse API: " . print_r(json_decode($data, true), true), $this->debug); if ($data) { return json_decode($data, true); } else { return false; } } }