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

Use more consistent cache keys for ESRI lookup.

Intended to fix #1048.
parent 4f0be135
No related branches found
No related tags found
No related merge requests found
...@@ -10,14 +10,16 @@ module Geocoder::Lookup ...@@ -10,14 +10,16 @@ module Geocoder::Lookup
end end
def query_url(query) def query_url(query)
search_keyword = query.reverse_geocode? ? "reverseGeocode" : "find" base_query_url(query) + url_query_string(query)
"#{protocol}://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/#{search_keyword}?" +
url_query_string(query)
end end
private # --------------------------------------------------------------- private # ---------------------------------------------------------------
def base_query_url(query)
action = query.reverse_geocode? ? "reverseGeocode" : "find"
"#{protocol}://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/#{action}?"
end
def results(query) def results(query)
return [] unless doc = fetch_data(query) return [] unless doc = fetch_data(query)
...@@ -32,6 +34,17 @@ module Geocoder::Lookup ...@@ -32,6 +34,17 @@ module Geocoder::Lookup
end end
end end
def cache_key(query)
base_query_url(query) + hash_to_query(cache_key_params(query))
end
def cache_key_params(query)
# omit api_key and token because they may vary among requests
query_url_params(query).reject do |key,value|
[:api_key, :token].include?(key)
end
end
def query_url_params(query) def query_url_params(query)
params = { params = {
:f => "pjson", :f => "pjson",
......
...@@ -110,6 +110,17 @@ class EsriTest < GeocoderTestCase ...@@ -110,6 +110,17 @@ class EsriTest < GeocoderTestCase
result.viewport result.viewport
end end
def test_cache_key_doesnt_include_api_key_or_token
token = Geocoder::EsriToken.new('xxxxx', Time.now + 60)
Geocoder.configure(esri: {token: token, api_key: "xxxxx", for_storage: true})
query = Geocoder::Query.new("Bluffton, SC")
lookup = Geocoder::Lookup.get(:esri)
key = lookup.send(:cache_key, query)
assert_match /forStorage/, key
assert_no_match /token/, key
assert_no_match /api_key/, key
end
def teardown def teardown
Geocoder.configure(esri: {token: nil, for_storage: nil}) Geocoder.configure(esri: {token: nil, for_storage: nil})
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