class Geocoder::Lookup::Base
Public Class Methods
# File lib/geocoder/lookups/base.rb, line 17 def initialize @cache = nil end
Public Instance Methods
The working Cache
object.
# File lib/geocoder/lookups/base.rb, line 85 def cache if @cache.nil? and store = configuration.cache cache_options = configuration.cache_options @cache = Cache.new(store, cache_options) end @cache end
Symbol which is used in configuration to refer to this Lookup
.
# File lib/geocoder/lookups/base.rb, line 31 def handle str = self.class.to_s str[str.rindex(':')+1..-1].gsub(/([a-z\d]+)([A-Z])/,'\1_\2').downcase.to_sym end
Return the URL for a map of the given coordinates.
Not necessarily implemented by all subclasses as only some lookups also provide maps.
# File lib/geocoder/lookups/base.rb, line 59 def map_link_url(coordinates) nil end
Human-readable name of the geocoding API.
# File lib/geocoder/lookups/base.rb, line 24 def name fail 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.
# File lib/geocoder/lookups/base.rb, line 78 def query_url(query) base_query_url(query) + url_query_string(query) end
Array containing string descriptions of keys required by the API. Empty array if keys are optional or not required.
# File lib/geocoder/lookups/base.rb, line 67 def required_api_key_parts [] end
Query
the geocoding API and return a Geocoder::Result
object. Returns nil
on timeout or error.
Takes a search string (eg: “Mississippi Coast Coliseumf, Biloxi, MS”, “205.128.54.202”) for geocoding, or coordinates (latitude, longitude) for reverse geocoding. Returns an array of Geocoder::Result
s.
# File lib/geocoder/lookups/base.rb, line 44 def search(query, options = {}) query = Geocoder::Query.new(query, options) unless query.is_a?(Geocoder::Query) results(query).map{ |r| result = result_class.new(r) result.cache_hit = @cache_hit if cache result } end
Array containing the protocols supported by the api. Should be set to [:http] if only HTTP is supported or [:https] if only HTTPS is supported.
# File lib/geocoder/lookups/base.rb, line 98 def supported_protocols [:http, :https] end