Skip to content

Commit

Permalink
Merge pull request #3 from prhost/master
Browse files Browse the repository at this point in the history
novo provider ApiCep que era o antigo Widenet, e outros fix.
  • Loading branch information
prhost authored May 6, 2020
2 parents 4dcf620 + d0d7433 commit aae0f75
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Para evitar problemas com indisponibilidade de serviços, a consulta é realizad
* [Correios](http://www.buscacep.correios.com.br/sistemas/buscacep/)
* [Viacep](https://viacep.com.br/)
* [CEP Aberto](http://cepaberto.com/)
* [Widenet](https://apps.widenet.com.br/busca-cep/api-de-consulta)
* [Api CEP (Antigo Widenet)](https://apicep.com/)
* [Republica Virtual](https://www.republicavirtual.com.br/cep/)

A library irá retornar para você a resposta mais rápida, aumentando assim a performance da consulta.
Expand Down
4 changes: 2 additions & 2 deletions src/CepGratis.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
use Prhost\CepGratis\Contracts\ProviderContract;
use Prhost\CepGratis\Exceptions\CepGratisInvalidParameterException;
use Prhost\CepGratis\Exceptions\CepGratisTimeoutException;
use Prhost\CepGratis\Providers\ApiCepProvider;
use Prhost\CepGratis\Providers\CepAbertoProvider;
use Prhost\CepGratis\Providers\CorreiosProvider;
use Prhost\CepGratis\Providers\RepublicaVirtualProvider;
use Prhost\CepGratis\Providers\ViaCepProvider;
use Prhost\CepGratis\Providers\WidenetProvider;

/**
* Class to query CEP.
Expand Down Expand Up @@ -64,7 +64,7 @@ public static function search(string $cep, array $options = [], int $timeout = n

$cepGratis->addProvider(new ViaCepProvider());
$cepGratis->addProvider(new CorreiosProvider());
$cepGratis->addProvider(new WidenetProvider());
$cepGratis->addProvider(new ApiCepProvider());
$cepGratis->addProvider(new CepAbertoProvider());
$cepGratis->addProvider(new RepublicaVirtualProvider());

Expand Down
1 change: 1 addition & 0 deletions src/Clients/CurlHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ private function createCurl($uri, array $data = [])
curl_setopt_array($curl, [
CURLOPT_URL => $uri,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false
]);

if ($this->headers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,27 @@
use Prhost\CepGratis\Contracts\HttpClientContract;
use Prhost\CepGratis\Contracts\ProviderContract;

class WidenetProvider implements ProviderContract
class ApiCepProvider implements ProviderContract
{
/**
* @return Address|null
*/
public function getAddress($cep, HttpClientContract $client, array $option = [])
{
$response = $client->get('http://apps.widenet.com.br/busca-cep/api/cep/' . $cep . '.json');
$response = $client->get('https://ws.apicep.com/busca-cep/api/cep/' . $cep . '.json');

if (!is_null($response)) {
$content = json_decode($response);
if (is_object($content) && !isset($content->erro)) {
if (isset($content->status) && $content->status == 0) {
if (isset($content->status) && ($content->status == 0 || $content->status == 404)) {
return null;
}

$address = trim(explode('- até', $content->address)[0]);
$address = trim(explode('- de', $address)[0]);
$address = '';
if ($content->address) {
$address = trim(explode('- até', $content->address)[0] ?? '');
$address = trim(explode('- de', $address)[0] ?? '');
}

return Address::create([
'zipcode' => $cep,
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/RepublicaVirtualProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function getAddress($cep, HttpClientContract $client, array $option = [])

return Address::create([
'zipcode' => $cep,
'street' => $content->tipo_logradouro . ' ' . $content->logradouro,
'street' => trim($content->tipo_logradouro . ' ' . $content->logradouro),
'neighborhood' => $content->bairro,
'city' => $content->cidade,
'state' => $content->uf,
Expand Down

0 comments on commit aae0f75

Please sign in to comment.