Skip to content
This repository has been archived by the owner on Jun 12, 2019. It is now read-only.
/ postjoy Public archive

Postal codes made easy

License

Notifications You must be signed in to change notification settings

ankane/postjoy

Repository files navigation

Postjoy

Postal codes made easy

Get Started

Add this line to your application’s Gemfile:

gem 'postjoy'

Lookup postal code

Postjoy.find(94109)
# =>
{
  city: "San Francisco",
  state: "California",
  state_code: "CA",
  latitude: 37.7917,
  longitude: -122.4186
}

Returns nil if the postal code does not exist

Validations

Also adds validations for Rails

class Address < ActiveRecord::Base
  validates :postal_code, postal_code: true
end

Credit

Data from GeoNames

TODO

  • international postal codes

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

To update postal codes, download the updated list from GeoNames to US.txt and run:

rake create