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

Merge pull request #498 from arnoldclark/master

Allow bing to search restricted by region
parents a25e3d7b 3a390fba
No related branches found
No related tags found
No related merge requests found
......@@ -17,13 +17,21 @@ module Geocoder::Lookup
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)
["#{protocol}://dev.virtualearth.net/REST/v1/Locations",
query.options[:region],
sanitized_text(query)].compact.join("/") + "?"
end
def sanitized_text(query)
URI.escape(query.sanitized_text.strip) if !query.reverse_geocode?
end
def results(query)
return [] unless doc = fetch_data(query)
......@@ -40,7 +48,7 @@ module Geocoder::Lookup
def query_url_params(query)
{
:key => configuration.api_key,
:query => query.reverse_geocode? ? nil : query.sanitized_text
:query => query.reverse_geocode? ? query.sanitized_text : nil
}.merge(super)
end
end
......
......@@ -264,6 +264,45 @@ class ServicesTest < Test::Unit::TestCase
assert_equal 0, results.length
end
def test_bing_query_url_contains_region
lookup = Geocoder::Lookup::Bing.new
url = lookup.query_url(Geocoder::Query.new(
"manchester",
:region => "uk"
))
assert_match /Locations\/uk\/manchester/, url
assert_no_match /query/, url
end
def test_bing_query_url_without_region
lookup = Geocoder::Lookup::Bing.new
url = lookup.query_url(Geocoder::Query.new(
"manchester"
))
assert_match /Locations\/manchester/, url
assert_no_match /query/, url
end
def test_bing_query_url_contains_address_with_spaces
lookup = Geocoder::Lookup::Bing.new
url = lookup.query_url(Geocoder::Query.new(
"manchester, lancashire",
:region => "uk"
))
assert_match /Locations\/uk\/manchester,%20lancashire/, url
assert_no_match /query/, url
end
def test_bing_query_url_contains_address_with_trailing_and_leading_spaces
lookup = Geocoder::Lookup::Bing.new
url = lookup.query_url(Geocoder::Query.new(
" manchester, lancashire ",
:region => "uk"
))
assert_match /Locations\/uk\/manchester,%20lancashire/, url
assert_no_match /query/, url
end
# --- Nominatim ---
def test_nominatim_result_components
......
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