lib/geocoder/lookups/base.rb in geocoder-1.4.9 vs lib/geocoder/lookups/base.rb in geocoder-1.5.0

- old
+ new

@@ -2,11 +2,10 @@ require 'net/https' require 'uri' unless defined?(ActiveSupport::JSON) begin - require 'rubygems' # for Ruby 1.8 require 'json' rescue LoadError raise LoadError, "Please install the 'json' or 'json_pure' gem to parse geocoder results." end end @@ -70,12 +69,16 @@ end ## # URL to use for querying the geocoding engine. # + # Subclasses should not modify this method. Instead they should define + # base_query_url and url_query_string. If absolutely necessary to + # subclss this method, they must also subclass #cache_key. + # def query_url(query) - fail + base_query_url(query) + url_query_string(query) end ## # The working Cache object. # @@ -96,10 +99,18 @@ end private # ------------------------------------------------------------- ## + # String which, when concatenated with url_query_string(query) + # produces the full query URL. Should include the "?" a the end. + # + def base_query_url(query) + fail + end + + ## # An object with configuration data for this particular lookup. # def configuration Geocoder.config_for_lookup(handle) end @@ -145,10 +156,17 @@ # request URL, but in cases where OAuth is used and the nonce, # timestamp, etc varies from one request to another, we need to use # something else (like the URL before OAuth encoding). # def cache_key(query) - query_url(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| + key.to_s.match /(key|token)/ + end end ## # Class of the result objects #