lib/geocoder/lookups/bing.rb in geocoder-1.1.9 vs lib/geocoder/lookups/bing.rb in geocoder-1.2.0
- old
+ new
@@ -15,17 +15,23 @@
def required_api_key_parts
["key"]
end
def query_url(query)
- "#{protocol}://dev.virtualearth.net/REST/v1/Locations" +
- (query.reverse_geocode? ? "/#{query.sanitized_text}?" : "?") +
- url_query_string(query)
+ base_url(query) + url_query_string(query)
end
private # ---------------------------------------------------------------
+ def base_url(query)
+ url = "#{protocol}://dev.virtualearth.net/REST/v1/Locations"
+ if !query.reverse_geocode? and r = query.options[:region]
+ url << "/#{r}"
+ end
+ url + "/" + URI.escape(query.sanitized_text.strip) + "?"
+ end
+
def results(query)
return [] unless doc = fetch_data(query)
if doc['statusCode'] == 200
return doc['resourceSets'].first['estimatedTotal'] > 0 ? doc['resourceSets'].first['resources'] : []
@@ -37,11 +43,10 @@
return []
end
def query_url_params(query)
{
- :key => configuration.api_key,
- :query => query.reverse_geocode? ? nil : query.sanitized_text
+ key: configuration.api_key
}.merge(super)
end
end
end