Coder Social home page Coder Social logo

correios-cep's Introduction

Correios CEP

Gem Version Build Status Coverage Status Code Climate GitHub license

Correios Logo

Current available solutions to find Brazilian addresses by zipcode use an HTML form from Correios web site website to perform it, instead of to use a real API.

The old solution works with an HTTP request to the form, followed by parsing HTML result page. The huge problem here is when the Correios web site development team decides to modify some HTML element in the result page, even a layout update, it will break the parser logic for result.

Correios CEP gem solves this problem, retrieving data directly from Correios database.

Installing

Gemfile

gem 'correios-cep'

Direct installation

$ gem install correios-cep

Using

require 'correios-cep'

# With "get" instance method
finder = Correios::CEP::AddressFinder.new
address = finder.get('54250610')

# With "get" class method
address = Correios::CEP::AddressFinder.get('54250610')

address # =>
{
  :address => 'Rua Fernando Amorim',
  :neighborhood => 'Cavaleiro',
  :city => 'Jaboatão dos Guararapes',
  :state => 'PE',
  :zipcode => '54250610',
  :complement => ''
}

Configurations

All the configurations are set using Correios::CEP module.

Timeout

For default, the timeout for a request to Correios Web Service is 5 seconds. If Correios Web Service does not respond, a HTTP::TimeoutError exception will be raised.

Correios::CEP.configure do |config|
  config.request_timeout = 3 # It configures timeout to 3 seconds
end

HTTP Proxy

If you need to use an HTTP proxy to HTTP requests, configure HTTP proxy URL.

Correios::CEP.configure do |config|
  config.proxy_url = 'http://10.20.30.40:8888'
end

Log

From 0.7.0 version, there is no more default logger, and the log level will be the same of the given logger.

Correios::CEP.configure do |config|
  config.logger = Rails.logger
end

Configuration example

Correios::CEP.configure do |config|
  config.logger = Rails.logger
  config.request_timeout = 3 # seconds
end

Credits

Author

Fernando Hamasaki de Amorim (prodis)

Prodis Logo

Contributors

https://github.com/prodis/correios-cep/graphs/contributors

Contributing

See the contributing guide.

License

Correios CEP gem is released under the Apache 2.0 License. See the LICENSE file.

correios-cep's People

Contributors

prodis avatar maurymmarques avatar esasse avatar givigier avatar qw3 avatar schweigert avatar rafbgarcia avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.