Skip to content
Snippets Groups Projects
Commit f52f655c authored by Alex Reisner's avatar Alex Reisner
Browse files

Update Yahoo lookup to reflect API changes.

"Results" key is now "Result" and is not an array when only one result.
Update code and response fixtures to reflect this.
parent e3d2afef
No related branches found
No related tags found
No related merge requests found
...@@ -12,8 +12,15 @@ module Geocoder::Lookup ...@@ -12,8 +12,15 @@ module Geocoder::Lookup
def results(query) def results(query)
return [] unless doc = fetch_data(query) return [] unless doc = fetch_data(query)
if doc = doc['ResultSet'] and doc['Error'] == 0 doc = doc['ResultSet']
return doc['Found'] > 0 ? Array(doc['Result']) : [] # seems to have Error == 7 when no results, though this is not documented
if [0, 7].include?(doc['Error'].to_i)
if doc['Found'].to_i > 0
r = doc['Result']
return r.is_a?(Array) ? r : [r]
else
return []
end
else else
warn "Yahoo Geocoding API error: #{doc['Error']} (#{doc['ErrorMessage']})." warn "Yahoo Geocoding API error: #{doc['Error']} (#{doc['ErrorMessage']})."
return [] return []
......
{
"ResultSet":{
"version":"1.0",
"Error":0,
"ErrorMessage":"No error",
"Locale":"us_US",
"Quality":87,
"Found":1,
"Result":[{
"quality":9,
"latitude":"55.008390",
"longitude":"-5.822485",
"offsetlat":"54.314072",
"offsetlon":"-2.230010",
"radius":1145100,
"boundingbox":{
"north":"60.854691",
"south":"49.162090",
"east":"1.768960",
"west":"-13.413930"
},
"name":"",
"line1":"",
"line2":"",
"line3":"",
"line4":"United Kingdom",
"cross":"",
"house":"",
"street":"",
"xstreet":"",
"unittype":"",
"unit":"",
"postal":"",
"neighborhood":"",
"city":"",
"county":"",
"state":"",
"country":"United Kingdom",
"countrycode":"GB",
"statecode":"",
"countycode":"",
"timezone":"Europe/London",
"areacode":"",
"uzip":"",
"hash":"",
"woeid":23424975,
"woetype":12
}]
}
}
{ {
"ResultSet":{ "@lang": "en-US",
"version":"1.0", "ResultSet": {
"Error":0, "@version": "2.0",
"ErrorMessage":"No error", "@lang": "en-US",
"Locale":"us_US", "Error": "0",
"Quality":90, "ErrorMessage": "No error",
"Found":1, "Locale": "en-US",
"Result":[{ "Found": "1",
"quality":90, "Quality": "90",
"latitude":"40.750381", "Result": {
"longitude":"-73.993988", "quality": "90",
"offsetlat":"40.750381", "latitude": "40.750381",
"offsetlon":"-73.993988", "longitude": "-73.993988",
"radius":100, "offsetlat": "40.750381",
"name":"Madison Square Garden", "offsetlon": "-73.993988",
"line1":"Madison Square Garden", "radius": "100",
"line2":"New York, NY 10001", "boundingbox": {
"line3":"", "north": "40.750832",
"line4":"United States", "south": "40.749931",
"house":"", "east": "-73.993393",
"street":"", "west": "-73.994591"
"xstreet":"", },
"unittype":"", "name": "Madison Square Garden",
"unit":"", "line1": "Madison Square Garden",
"postal":"10001", "line2": "New York, NY 10001",
"neighborhood":"", "line3": "",
"city":"New York", "line4": "United States",
"county":"New York County", "cross": "",
"state":"New York", "house": "",
"country":"United States", "street": "",
"countrycode":"US", "xstreet": "",
"statecode":"NY", "unittype": "",
"countycode":"", "unit": "",
"uzip":"10001", "postal": "10001",
"hash":"", "neighborhood": "Garment District|Midtown|Midtown West|Manhattan",
"woeid":23617041, "city": "New York",
"woetype":20, "county": "New York County",
"cross":"", "state": "New York",
"timezone":"America/New_York", "country": "United States",
"neighborhood":"Garment District|Midtown|Midtown West|Manhattan", "countrycode": "US",
"areacode":"212", "statecode": "NY",
"boundingbox":{"north":"40.750832","south":"40.749931","east":"-73.993393","west":"-73.994591"} "countycode": "",
}] "timezone": "America/New_York",
"areacode": "212",
"uzip": "10001",
"hash": "",
"woeid": "23617041",
"woetype": "20"
}
} }
} }
{ {
"ResultSet":{ "@lang": "en-US",
"version":"1.0", "ResultSet": {
"Error":0, "@version": "2.0",
"ErrorMessage":"No error", "@lang": "en-US",
"Locale":"us_US", "Error": "7",
"Quality":10, "ErrorMessage": "No result",
"Found":0 "Locale": "en-US",
} "Found": "0",
"Quality": "0"
}
} }
...@@ -76,7 +76,7 @@ class ServicesTest < Test::Unit::TestCase ...@@ -76,7 +76,7 @@ class ServicesTest < Test::Unit::TestCase
def test_yahoo_address_formatting def test_yahoo_address_formatting
Geocoder::Configuration.lookup = :yahoo Geocoder::Configuration.lookup = :yahoo
result = Geocoder.search("Madison Square Garden, New York, NY").first result = Geocoder.search("Madison Square Garden, New York, NY").first
assert_equal "Madison Square Garden, New York, NY 10001, United States", assert_equal "Madison Square Garden, New York, NY 10001, United States",
result.address result.address
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment