Class: Geocoder::Lookup::Base
- Inherits:
-
Object
- Object
- Geocoder::Lookup::Base
- Defined in:
- lib/geocoder/lookups/base.rb
Direct Known Subclasses
Baidu, BaiduIp, Bing, Esri, Freegeoip, GeocoderCa, GeocoderUs, Geocodio, Geoip2, GeoportailLu, Google, Here, Mapbox, Mapquest, Maxmind, MaxmindGeoip2, MaxmindLocal, Nominatim, Okf, Opencagedata, Ovi, Pointpin, PostcodeAnywhereUk, SmartyStreets, Telize, Test, Yahoo, Yandex
Instance Method Summary collapse
-
#cache ⇒ Object
The working Cache object.
-
#handle ⇒ Object
Symbol which is used in configuration to refer to this Lookup.
-
#initialize ⇒ Base
constructor
A new instance of Base.
-
#map_link_url(coordinates) ⇒ Object
Return the URL for a map of the given coordinates.
-
#name ⇒ Object
Human-readable name of the geocoding API.
-
#query_url(query) ⇒ Object
URL to use for querying the geocoding engine.
-
#required_api_key_parts ⇒ Object
Array containing string descriptions of keys required by the API.
-
#search(query, options = {}) ⇒ Object
Query the geocoding API and return a Geocoder::Result object.
-
#supported_protocols ⇒ Object
Array containing the protocols supported by the api.
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
18 19 20 |
# File 'lib/geocoder/lookups/base.rb', line 18 def initialize @cache = nil end |
Instance Method Details
#cache ⇒ Object
The working Cache object.
82 83 84 85 86 87 |
# File 'lib/geocoder/lookups/base.rb', line 82 def cache if @cache.nil? and store = configuration.cache @cache = Cache.new(store, configuration.cache_prefix) end @cache end |
#handle ⇒ Object
Symbol which is used in configuration to refer to this Lookup.
32 33 34 35 |
# File 'lib/geocoder/lookups/base.rb', line 32 def handle str = self.class.to_s str[str.rindex(':')+1..-1].gsub(/([a-z\d]+)([A-Z])/,'\1_\2').downcase.to_sym end |
#map_link_url(coordinates) ⇒ Object
Return the URL for a map of the given coordinates.
Not necessarily implemented by all subclasses as only some lookups also provide maps.
60 61 62 |
# File 'lib/geocoder/lookups/base.rb', line 60 def map_link_url(coordinates) nil end |
#name ⇒ Object
Human-readable name of the geocoding API.
25 26 27 |
# File 'lib/geocoder/lookups/base.rb', line 25 def name fail end |
#query_url(query) ⇒ Object
URL to use for querying the geocoding engine.
75 76 77 |
# File 'lib/geocoder/lookups/base.rb', line 75 def query_url(query) fail end |
#required_api_key_parts ⇒ Object
Array containing string descriptions of keys required by the API. Empty array if keys are optional or not required.
68 69 70 |
# File 'lib/geocoder/lookups/base.rb', line 68 def required_api_key_parts [] end |
#search(query, options = {}) ⇒ Object
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.
45 46 47 48 49 50 51 52 |
# File 'lib/geocoder/lookups/base.rb', line 45 def search(query, = {}) query = Geocoder::Query.new(query, ) unless query.is_a?(Geocoder::Query) results(query).map{ |r| result = result_class.new(r) result.cache_hit = @cache_hit if cache result } end |
#supported_protocols ⇒ Object
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.
94 95 96 |
# File 'lib/geocoder/lookups/base.rb', line 94 def supported_protocols [:http, :https] end |