Skip to content

Instantly share code, notes, and snippets.

@drouillard
Created August 21, 2014 04:34
Show Gist options
  • Save drouillard/512e0ebacc734cb9b116 to your computer and use it in GitHub Desktop.
Save drouillard/512e0ebacc734cb9b116 to your computer and use it in GitHub Desktop.
Ruby Class for using Ziptastic API
Ziptastic.new.lookup "48073"
=> {"city"=>"Royal Oak", "country"=>"US", "county"=>"Oakland", "state"=>"Michigan", "state_short"=>"MI", "postal_code"=>"48073"}
Ziptastic.new.lookup "garbage"
=> {}
require "net/http"
require "uri"
require "json"
class Ziptastic
BASE_URL = 'http://zip.getziptastic.com/v2/US/'
def initialize
end
def lookup(zip)
raise "No Zip code provided" unless zip
uri = URI.parse(BASE_URL + zip)
response = Net::HTTP.get_response(uri)
JSON.parse response.body
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment