class Geokit::Geocoders::Geocoder
The Geocoder
base class which defines the interface to be used by all other geocoders.
Public Class Methods
normalize_address(addr)
click to toggle source
# File lib/geocoder.rb, line 14 def self.normalize_address(addr) addr.gsub(/\s*,\s*/, ',').strip end
Private Class Methods
do_get(url)
click to toggle source
Wraps the geocoder call around a proxy if necessary. Use typhoeus and memcache if defined
# File lib/geocoder.rb, line 22 def self.do_get(url) if (defined?(APICache) && Geokit::Geocoders::api_cache) body = APICache.get(url, { :cache => Geokit::Geocoders::api_cache, :valid => Geokit::Geocoders::api_cache_valid, :timeout => Geokit::Geocoders::api_cache_timeout}) # fake Net::HTTPOK so that caching will work for all geocoders res = Net::HTTPOK.new(1.0, 200, 'OK') res.instance_variable_set(:@body, body) res.instance_variable_set(:@read, true) else uri = URI.parse(url) req = Net::HTTP::Get.new(url) req.basic_auth(uri.user, uri.password) if uri.userinfo res = Net::HTTP::Proxy(GeoKit::Geocoders::proxy_addr, GeoKit::Geocoders::proxy_port, GeoKit::Geocoders::proxy_user, GeoKit::Geocoders::proxy_pass).start(uri.host, uri.port) { |http| http.get(uri.path + "?" + uri.query) } end return res end