Correios CEP v0.7.0 Correios.CEP View Source
Find Brazilian addresses by postal code, directly from Correios API. No HTML parsers.
Link to this section Summary
Link to this section Types
Specs
t() :: {:ok, Correios.CEP.Address.t()} | {:error, Correios.CEP.Error.t()}
Link to this section Functions
Specs
Finds address by the given postal_code
.
Postal codes with and without "-" separator are accepted.
Options
connection_timeout
: timeout for establishing a connection, in milliseconds. Default is 5000.request_timeout
: timeout for receiving the HTTP response, in milliseconds. Default is 5000.proxy
: proxy to be used for the request:{host, port}
tuple, whereport
is an integer.proxy_auth
: proxy authentication:{user, password}
tuple.url
: Correios API full URL. Default ishttps://apps.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente
.
Examples
iex> Correios.CEP.find_address("54250610")
{:ok,
%Correios.CEP.Address{
city: "Jaboatão dos Guararapes",
complement: "",
neighborhood: "Cavaleiro",
state: "PE",
street: "Rua Fernando Amorim",
postal_code: "54250610"
}}
iex> Correios.CEP.find_address("54250-610")
{:ok,
%Correios.CEP.Address{
city: "Jaboatão dos Guararapes",
complement: "",
neighborhood: "Cavaleiro",
state: "PE",
street: "Rua Fernando Amorim",
postal_code: "54250610"
}}
iex> Correios.CEP.find_address("54250-610", connection_timeout: 1000, request_timeout: 1000)
{:ok,
%Correios.CEP.Address{
city: "Jaboatão dos Guararapes",
complement: "",
neighborhood: "Cavaleiro",
state: "PE",
street: "Rua Fernando Amorim",
postal_code: "54250610"
}}
iex> Correios.CEP.find_address("54250-610", proxy: {"localhost", 8888})
{:ok,
%Correios.CEP.Address{
city: "Jaboatão dos Guararapes",
complement: "",
neighborhood: "Cavaleiro",
state: "PE",
street: "Rua Fernando Amorim",
postal_code: "54250610"
}}
iex> Correios.CEP.find_address(
...> "54250-610",
...> proxy: {"localhost", 8888},
...> proxy_auth: {"myuser", "mypass"}
...> )
{:ok,
%Correios.CEP.Address{
city: "Jaboatão dos Guararapes",
complement: "",
neighborhood: "Cavaleiro",
state: "PE",
street: "Rua Fernando Amorim",
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("1234567")
{:error,
%Correios.CEP.Error{
type: :postal_code_invalid,
message: "Postal code in invalid format"
}}
iex> Correios.CEP.find_address("")
{:error,
%Correios.CEP.Error{
type: :postal_code_required,
message: "Postal code is required"
}}
Specs
find_address!(String.t(), keyword()) :: Correios.CEP.Address.t()
Finds address by a given postal code.
Similar to find_address/2
except it will unwrap the error tuple and raise in case of errors.
Examples
iex> Correios.CEP.find_address!("54250610")
%Correios.CEP.Address{
city: "Jaboatão dos Guararapes",
complement: "",
neighborhood: "Cavaleiro",
state: "PE",
street: "Rua Fernando Amorim",
postal_code: "54250610"
}
iex> Correios.CEP.find_address!("00000-000")
** (Correios.CEP.Error) Postal code not found