= correios-cep Current available solutions to find Brazilian addresses by zipcode use an HTML form from Correios web site to perform it, instead of to use a real API. This works with an HTTP request to the form, followed by parsing the 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, getting data directly from Correios database. http://prodis.net.br/images/ruby/2011/correios_logo.png {Gem Version}[http://badge.fury.io/rb/correios-cep] {Build Status}[https://travis-ci.org/prodis/correios-cep] {Coverage Status}[https://coveralls.io/r/prodis/correios-cep] {Code Climate}[https://codeclimate.com/github/prodis/correios-cep] {Dependency Status}[https://gemnasium.com/prodis/correios-cep] == 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 === Timeout For default, the timeout for a request to Correios Web Service is 5 seconds. If Correios Web Service does not respond, a Timeout::Error exception will be raised. You can configure this timeout using Correios::CEP module. Correios::CEP.configure do |config| config.request_timeout = 3 # It configures timeout to 3 seconds end === Log For default, each request to Correios Web service is logged to STDOUT, with :info log level, using the gem {LogMe}[http://github.com/prodis/log-me]. Log example: I, [2014-02-14T00:10:12.718413 #76361] INFO -- : [Correios::CEP] Request: POST http://200.252.60.209/SigepCliente/AtendeClienteService 54250610 I, [2014-02-14T00:10:12.969937 #76361] INFO -- : [Correios::CEP] Response: HTTP/1.1 200 OK Cavaleiro 54250610 Jaboatão dos Guararapes Rua Fernando Amorim 0 PE To disable the log and configure other log output, use Correios::CEP module: Correios::CEP.configure do |config| config.log_enabled = false # It disables the log config.logger = Rails.logger # It uses Rails logger end === Configuration example Correios::CEP.configure do |config| config.logger = Rails.logger config.request_timeout = 3 end == Author - {Fernando Hamasaki de Amorim (prodis)}[http://prodis.blog.br] == Contributing to correios-cep * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet. * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it. * Fork the project. * Start a feature/bugfix branch. * Commit and push until you are happy with your contribution. * Don't forget to rebase with branch master in main project before submit the pull request. * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally. * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it. == Copyright (The MIT License) {Prodis a.k.a. Fernando Hamasaki de Amorim}[http://prodis.blog.br] http://prodis.net.br/images/prodis_150.gif Copyright (c) 2014 Prodis Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.