Skip to content

Commit

Permalink
updated yahoo geocoder (was using a deprecated version)
Browse files Browse the repository at this point in the history
  • Loading branch information
opencongress committed Oct 11, 2011
1 parent 7acfbac commit ac5baf5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
7 changes: 2 additions & 5 deletions app/models/zipcode_district.rb
@@ -1,12 +1,9 @@
class ZipcodeDistrict < ActiveRecord::Base
def ZipcodeDistrict.zip_lookup(zip5, zip4 = nil)
if zip4.blank?
find(:all, :select => "DISTINCT state, district",
:conditions => ["zip5 = ?", zip5])
self.select("DISTINCT state, district").where(["zip5 = ?", zip5]).all
else
find(:all, :select => "DISTINCT state, district",
:conditions => ["zip5 = ? AND (zip4 = ? OR zip4 = 'xxxx')", zip5, zip4])

self.select("DISTINCT state, district").where(["zip5 = ? AND (zip4 = ? OR zip4 = 'xxxx')", zip5, zip4]).all
end
end

Expand Down
9 changes: 6 additions & 3 deletions lib/yahoo_geocoder.rb
Expand Up @@ -17,17 +17,20 @@ def geocode
require 'hpricot'
require 'open-uri'
begin
doc = Hpricot.XML(open("http://local.yahooapis.com/MapsService/V1/geocode?appid=#{@key}&location=#{CGI::escape(@address)}"))
doc = Hpricot.XML(open("http://where.yahooapis.com/geocode?q=#{CGI::escape(@address)}&appid=#{@key}"))


#puts "\n\n\nHERE's the DOC: #{doc}\n\n\n"
if doc
zip = (doc/:Result/:Zip).inner_html
zip = (doc/:Result/:postal).inner_html
@zip5,@zip4 = zip.split('-')
@city = (doc/:Result/:City).inner_html
@city = (doc/:Result/:city).inner_html
return true
else
return false
end
rescue
logger.warn "Error with Yahoo API: #{$!}"
return false
end
end
Expand Down

0 comments on commit ac5baf5

Please sign in to comment.