Correios CEP v0.2.0 Correios.CEP View Source

Find Brazilian addresses by zipcode, directly from Correios database. No HTML parsers.

Link to this section Summary

Functions

Find address by a given zip code

Find address by a given zip code

Link to this section Functions

Link to this function find_address!(zipcode, options \\ []) View Source

Find address by a given zip 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",
  zipcode: "54250610"
}

When zip code is not found.

iex> Correios.CEP.find_address("00000000")
** (Correios.CEP.Error) CEP NAO ENCONTRADO
Link to this function find_address(zipcode, options \\ []) View Source

Find address by a given zip code.

Zip codes with and without “-“ separator are accepted.

Options

  • connection_timeout: timeout for establishing a TCP or SSL connection, in milliseconds. Default is 5000.
  • request_timeout: timeout for receiving an HTTP response from the socket. Default is 5000.

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",
   zipcode: "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",
   zipcode: "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",
   zipcode: "54250610"
 }}

When zip code is not found.

iex> Correios.CEP.find_address("00000000")
{:error, %Correios.CEP.Error{reason: "CEP NAO ENCONTRADO"}}