BrZipCode
This gem helps you to find an address based on a brazilian zip code. For that, 3 webservices are used:
The webservices are searched in order. If one is not available, the next is tested until one is available or none.
Installation
Add this line to your application's Gemfile:
gem 'br_zip_code'
And then execute:
$ bundle
Or install it yourself as:
$ gem install br_zip_code
Usage
BrZipCode.get("22451090")   #=> {:street=>"Rua Duque Estrada", :state=>"RJ", :city=>"Rio de Janeiro", :district=>"Gávea"}
BrZipCode.get("22.451-090") #=> {:street=>"Rua Duque Estrada", :state=>"RJ", :city=>"Rio de Janeiro", :district=>"Gávea"}
BrZipCode.get("22451-090")  #=> {:street=>"Rua Duque Estrada", :state=>"RJ", :city=>"Rio de Janeiro", :district=>"Gávea"}
BrZipCode.get("12345678")   #=> nil
BrZipCode.get("1234567")    #=> nil
Basic JSON API
The route /zip_code/:zip_code.json (/zip_code/22441090.json, for example) is accessible. Pass the zip_code and get the response, so you can create AJAX function to autocomplete addresses.
So, http://localhost:3000/zip_code/22441090.json will return:
{
  "success":true,
  "zip_code_info":
  {
    "street_type":"Rua",
    "street":"Rua General Venâncio Flores",
    "state":"RJ",
    "city":"Rio de Janeiro",
    "neighborhood":"Leblon"
  }
}
Development
After checking out the repo, run bin/setup to install dependencies. Then, run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release to create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.
Contributing
- Fork it ( https://github.com/[my-github-username]/br_zip_code/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request