Find Brazilian addresses by postal code, directly from Correios API. No HTML parsers.
Correios.CEP.Address.zipcode
was removed in the version 0.6.0
. Use Correios.CEP.Address.postal_code
instead.
The package can be installed by adding correios_cep
to your list of dependencies in mix.exs
:
def deps do
[
{:correios_cep, "~> 0.7.0"}
]
end
iex> Correios.CEP.find_address("54250610")
{:ok,
%Correios.CEP.Address{
street: "Rua Fernando Amorim",
neighborhood: "Cavaleiro",
complement: "",
city: "Jaboatão dos Guararapes",
state: "PE",
postal_code: "54250610"
}}
iex> Correios.CEP.find_address("00000-000")
{:error,
%Correios.CEP.Error{
type: :postal_code_not_found,
message: "Postal code not found",
reason: "CEP NAO ENCONTRADO"
}}
iex> Correios.CEP.find_address!("54250-610")
%Correios.CEP.Address{
street: "Rua Fernando Amorim",
neighborhood: "Cavaleiro",
complement: "",
city: "Jaboatão dos Guararapes",
state: "PE",
postal_code: "54250610"
}
iex> Correios.CEP.find_address!("00000-000")
** (Correios.CEP.Error) Postal code not found
There are some supported options that can be added to the request, as timeouts, proxy and URL configuration.
The example below shows the use of request_timeout
and proxy
options:
iex> Correios.CEP.find_address("54250610", request_timeout: 3000, proxy: {"localhost", 8888})
{:ok,
%Correios.CEP.Address{
street: "Rua Fernando Amorim",
neighborhood: "Cavaleiro",
complement: "",
city: "Jaboatão dos Guararapes",
state: "PE",
postal_code: "54250610"
}}
See Correios.CEP.find_address/2
documentation to check the details of the available options.
The full documentation is available at https://hexdocs.pm/correios_cep.
See the contributing guide.
Correios CEP is released under the Apache 2.0 License. See the LICENSE file.
Copyright © 2018-2020 Fernando Hamasaki de Amorim