Created
August 21, 2014 04:34
-
-
Save drouillard/512e0ebacc734cb9b116 to your computer and use it in GitHub Desktop.
Ruby Class for using Ziptastic API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ziptastic.new.lookup "48073" | |
=> {"city"=>"Royal Oak", "country"=>"US", "county"=>"Oakland", "state"=>"Michigan", "state_short"=>"MI", "postal_code"=>"48073"} | |
Ziptastic.new.lookup "garbage" | |
=> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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