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
def results(query)
return [] unless doc = fetch_data(query)
if doc = doc['ResultSet'] and doc['Error'] == 0
return doc['Found'] > 0 ? Array(doc['Result']) : []
doc = doc['ResultSet']
# 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
warn "Yahoo Geocoding API error: #{doc['Error']} (#{doc['ErrorMessage']})."
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":{
"version":"1.0",
"Error":0,
"ErrorMessage":"No error",
"Locale":"us_US",
"Quality":90,
"Found":1,
"Result":[{
"quality":90,
"latitude":"40.750381",
"longitude":"-73.993988",
"offsetlat":"40.750381",
"offsetlon":"-73.993988",
"radius":100,
"name":"Madison Square Garden",
"line1":"Madison Square Garden",
"line2":"New York, NY 10001",
"line3":"",
"line4":"United States",
"house":"",
"street":"",
"xstreet":"",
"unittype":"",
"unit":"",
"postal":"10001",
"neighborhood":"",
"city":"New York",
"county":"New York County",
"state":"New York",
"country":"United States",
"countrycode":"US",
"statecode":"NY",
"countycode":"",
"uzip":"10001",
"hash":"",
"woeid":23617041,
"woetype":20,
"cross":"",
"timezone":"America/New_York",
"neighborhood":"Garment District|Midtown|Midtown West|Manhattan",
"areacode":"212",
"boundingbox":{"north":"40.750832","south":"40.749931","east":"-73.993393","west":"-73.994591"}
}]
"@lang": "en-US",
"ResultSet": {
"@version": "2.0",
"@lang": "en-US",
"Error": "0",
"ErrorMessage": "No error",
"Locale": "en-US",
"Found": "1",
"Quality": "90",
"Result": {
"quality": "90",
"latitude": "40.750381",
"longitude": "-73.993988",
"offsetlat": "40.750381",
"offsetlon": "-73.993988",
"radius": "100",
"boundingbox": {
"north": "40.750832",
"south": "40.749931",
"east": "-73.993393",
"west": "-73.994591"
},
"name": "Madison Square Garden",
"line1": "Madison Square Garden",
"line2": "New York, NY 10001",
"line3": "",
"line4": "United States",
"cross": "",
"house": "",
"street": "",
"xstreet": "",
"unittype": "",
"unit": "",
"postal": "10001",
"neighborhood": "Garment District|Midtown|Midtown West|Manhattan",
"city": "New York",
"county": "New York County",
"state": "New York",
"country": "United States",
"countrycode": "US",
"statecode": "NY",
"countycode": "",
"timezone": "America/New_York",
"areacode": "212",
"uzip": "10001",
"hash": "",
"woeid": "23617041",
"woetype": "20"
}
}
}
{
"ResultSet":{
"version":"1.0",
"Error":0,
"ErrorMessage":"No error",
"Locale":"us_US",
"Quality":10,
"Found":0
}
"@lang": "en-US",
"ResultSet": {
"@version": "2.0",
"@lang": "en-US",
"Error": "7",
"ErrorMessage": "No result",
"Locale": "en-US",
"Found": "0",
"Quality": "0"
}
}
......@@ -76,7 +76,7 @@ class ServicesTest < Test::Unit::TestCase
def test_yahoo_address_formatting
Geocoder::Configuration.lookup = :yahoo
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
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