Permalink
Browse files

Make params passed to Query override config values.

If you do this:

  Geocoder::Query.new("Kremlin, Moscow", :params => {:language => "ru"})

you should get a response in Russian ("ru") regardless of the value set
in Geocoder.configure(...).
  • Loading branch information...
1 parent bf657d0 commit 08286a12e5a38bcac394f71e9f33662519e4d4d7 @alexreisner committed Dec 23, 2012
@@ -38,10 +38,10 @@ def results(query)
end
def query_url_params(query)
- super.merge(
+ {
:key => configuration.api_key,
:query => query.reverse_geocode? ? nil : query.sanitized_text
- )
+ }.merge(super)
end
end
end
@@ -27,12 +27,12 @@ def results(query)
end
def query_url_params(query)
- params = super.merge(
+ params = {
:geoit => "xml",
:jsonp => 1,
:callback => "test",
:auth => configuration.api_key
- )
+ }.merge(super)
if query.reverse_geocode?
lat,lon = query.coordinates
params[:latt] = lat
@@ -54,9 +54,9 @@ def query_url_google_params(query)
end
def query_url_params(query)
- super.merge(query_url_google_params(query)).merge(
+ query_url_google_params(query).merge(
:key => configuration.api_key
- )
+ ).merge(super)
end
end
end
@@ -22,7 +22,7 @@ def query_url(query)
private # ---------------------------------------------------------------
def query_url_params(query)
- super.merge(query_url_google_params(query)).merge(
+ query_url_google_params(query).merge(super).merge(
:key => nil, # don't use param inherited from Google lookup
:client => configuration.api_key[1],
:channel => configuration.api_key[2]
@@ -27,12 +27,11 @@ def search_type(query)
end
def query_url_params(query)
- key = configuration.api_key
params = { :location => query.sanitized_text }
- if key
+ if key = configuration.api_key
params[:key] = CGI.unescape(key)
end
- super.merge(params)
+ params.merge(super)
end
def results(query)
@@ -39,10 +39,10 @@ def reserved_result
end
def query_url_params(query)
- super.merge(
+ {
:l => configuration.api_key,
:i => query.sanitized_text
- )
+ }.merge(super)
end
end
end
@@ -26,12 +26,12 @@ def results(query)
end
def query_url_params(query)
- params = super.merge(
+ params = {
:format => "json",
:polygon => "1",
:addressdetails => "1",
:"accept-language" => configuration.language
- )
+ }.merge(super)
if query.reverse_geocode?
lat,lon = query.coordinates
params[:lat] = lat
@@ -60,13 +60,13 @@ def parse_raw_data(raw_data)
end
def query_url_params(query)
- super.merge(
+ {
:location => query.sanitized_text,
:flags => "JXTSR",
:gflags => "AC#{'R' if query.reverse_geocode?}",
:locale => "#{configuration.language}_US",
:appid => configuration.api_key
- )
+ }.merge(super)
end
def cache_key(query)
@@ -43,12 +43,12 @@ def query_url_params(query)
else
q = query.sanitized_text
end
- super.merge(
+ {
:geocode => q,
:format => "json",
:plng => "#{configuration.language}", # supports ru, uk, be
:key => configuration.api_key
- )
+ }.merge(super)
end
end
end
View
@@ -33,6 +33,27 @@ def test_query_url_contains_values_in_params_hash
end
end
+ {
+ :bing => :key,
+ :geocoder_ca => :auth,
+ :google => :language,
+ :google_premier => :language,
+ :mapquest => :key,
+ :maxmind => :l,
+ :nominatim => :"accept-language",
+ :yahoo => :locale,
+ :yandex => :plng
+ }.each do |l,p|
+ define_method "test_passing_param_to_#{l}_query_overrides_configuration_value" do
+ set_api_key!(l)
+ url = Geocoder::Lookup.get(l).query_url(Geocoder::Query.new(
+ "test", :params => {p => "xxxx"}
+ ))
+ assert_match /#{p}=xxxx/, url,
+ "Param passed to #{l} lookup does not override configuration value"
+ end
+ end
+
def test_raises_exception_on_invalid_key
Geocoder.configure(:always_raise => [Geocoder::InvalidApiKey])
#Geocoder::Lookup.all_services_except_test.each do |l|

0 comments on commit 08286a1

Please sign in to comment.