diff --git a/README.md b/README.md index 9a3804a6..cffa9a25 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,3 @@ Premissas: ● Tratar o erro. Dar um retorno amigável para usuário leigo. -## PS: Valorizamos a criatividade no layout. - -# Entrega: - * Disponibilizar um link do repositório no GitHub e encaminhar para developer@cd2.com.br diff --git a/arquivo.xml b/arquivo.xml new file mode 100644 index 00000000..f228cacf --- /dev/null +++ b/arquivo.xml @@ -0,0 +1,13 @@ + + + 88060-000 + Rodovia João Gualberto Soares + de 4001/4002 a 16999/17000 + São João do Rio Vermelho + Florianópolis + SC + 4205407 + + 48 + 8105 + diff --git a/index.css b/index.css new file mode 100644 index 00000000..55ab7a11 --- /dev/null +++ b/index.css @@ -0,0 +1,6 @@ +/* Show it is fixed to the top */ +body { + min-height: 75rem; + padding-top: 4.5rem; + } + \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 00000000..e1cc2951 --- /dev/null +++ b/index.html @@ -0,0 +1,103 @@ + + + + + + + + + + + + + PHP Test + + + + + + + + + + + + + + + + + + + +
+
+
+ + +
+
+
+ + +
+
+
+
+ +
+
+
+ + +
+
+
+ + + + + + + + \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 00000000..770173e1 --- /dev/null +++ b/index.php @@ -0,0 +1,235 @@ +connect_errno) { + echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; + } + + $validacao = "SELECT * FROM enderecos_pesquisados WHERE cep = '$cep'"; + + $teste = $mysqli->query($validacao); + $temRegistros = mysqli_fetch_array($teste); + + if(empty($temRegistros)){ + + $url = "viacep.com.br/ws/$cep/xml/"; + + $curl = curl_init(); + + curl_setopt_array($curl, array( + CURLOPT_URL => $url, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'GET', + )); + + $response = curl_exec($curl); + + curl_close($curl); + + if(!empty($response)){ + $xml = simplexml_load_string($response); + $json = json_encode($xml); + $response = json_decode($json,TRUE); + } + + // $teste = file_put_contents('arquivo.xml', $response); + + // $response = json_decode($response); + $response = (object)$response; + if(isset($response->erro)){ + + $linha = " + CEP inválido, por favor digite um CEP válido + "; + }else{ + if(empty($response->complemento)){ + $complemento = ''; + }else{ + $complemento = $response->complemento; + } + if(empty($response->gia)){ + $gia = ''; + }else{ + $gia = $response->gia; + } + $linha = " + + $response->cep + $response->logradouro + $complemento + $response->bairro + $response->localidade + $response->uf + $response->ibge + $gia + $response->ddd + $response->siafi + + "; + + $query = "INSERT INTO enderecos_pesquisados (cep,logradouro,complemento,bairro,localidade,uf,ibge,gia,ddd,siafi) VALUES ('$response->cep','$response->logradouro','$complemento','$response->bairro','$response->localidade','$response->uf','$response->ibge','$gia','$response->ddd','$response->siafi')"; + + $mysqli->query($query); + } + + + + }else{ + $temRegistros = (object)$temRegistros; + $linha = " + + $temRegistros->cep + $temRegistros->logradouro + $temRegistros->complemento + $temRegistros->bairro + $temRegistros->localidade + $temRegistros->uf + $temRegistros->ibge + $temRegistros->gia + $temRegistros->ddd + $temRegistros->siafi + + "; + } +?> + + + + + + + + + + + + + + PHP Test + + + + + + + + + + + + + + + + + +
+ +
+
+
+ + +
+
+
+ + +
+
+
+
+ +
+
+
+ + +
+
+ + + + + + + + + + + + + + + + + +
ceplogradourocomplementobairrolocalidadeufibgegiadddsiafi
+
+ + + + + \ No newline at end of file diff --git a/viaCep.sql b/viaCep.sql new file mode 100644 index 00000000..981e4d8f --- /dev/null +++ b/viaCep.sql @@ -0,0 +1,13 @@ +CREATE TABLE `enderecos_pesquisados` ( + `id` int(11) PRIMARY KEY AUTO_INCREMENT not null, + `cep` int(11) not null, + `logradouro` varchar(250) not null, + `complemento` varchar(250) not null, + `bairro` varchar(100) not null, + `localidade` varchar(100) not null, + `uf` varchar(2) not null, + `ibge` int(11) not null, + `gia` varchar(100) not null, + `ddd` int(2) not null, + `siafi` int(10) not null +); \ No newline at end of file