Skip to content

Instantly share code, notes, and snippets.

@dwillis
Created March 18, 2017 19:06
Show Gist options
  • Save dwillis/2b1bcfdec363709a4b8bc966b5d03625 to your computer and use it in GitHub Desktop.
Save dwillis/2b1bcfdec363709a4b8bc966b5d03625 to your computer and use it in GitHub Desktop.
def self.locate(address)
url = "https://www.googleapis.com/civicinfo/v2/representatives?address=#{address}&includeOffices=true&levels=country&roles=legislatorUpperBody&roles=legislatorLowerBody&key=APIKEY"
result = JSON.parse(open(url).read)
state = result['normalizedInput']['state']
house = result['offices'].detect{|o| o['roles'].include?('legislatorLowerBody')}
house_district = house['divisionId'].split(":").last if house
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment