From c278f94cb096215283bb35e52901159cb1e311ac Mon Sep 17 00:00:00 2001 From: Eric Hayes <eric@inflection.com> Date: Wed, 26 Jun 2013 13:56:51 -0700 Subject: [PATCH] This commit adds the Data Science Toolkit as a lookup type. The DSTK behaves identically to the Google Maps API with the exception that it can be run behind your own firewall. More information about this tool can be found here: http://www.datasciencetoolkit.org/ --- .gitignore | 1 + lib/geocoder/lookup.rb | 1 + lib/geocoder/lookups/dstk.rb | 20 ++++++++++++++++++++ lib/geocoder/results/dstk.rb | 6 ++++++ test/services_test.rb | 20 ++++++++++++++++++++ test/test_helper.rb | 7 +++++++ 6 files changed, 55 insertions(+) create mode 100644 lib/geocoder/lookups/dstk.rb create mode 100644 lib/geocoder/results/dstk.rb diff --git a/.gitignore b/.gitignore index c94bfb4e..96a66d35 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ rdoc/* *.gem .bundle Gemfile.lock +.DS_Store diff --git a/lib/geocoder/lookup.rb b/lib/geocoder/lookup.rb index 054d55cc..6a6ee407 100644 --- a/lib/geocoder/lookup.rb +++ b/lib/geocoder/lookup.rb @@ -21,6 +21,7 @@ module Geocoder # def street_services [ + :dstk, :esri, :google, :google_premier, diff --git a/lib/geocoder/lookups/dstk.rb b/lib/geocoder/lookups/dstk.rb new file mode 100644 index 00000000..68186053 --- /dev/null +++ b/lib/geocoder/lookups/dstk.rb @@ -0,0 +1,20 @@ +# More information about the Data Science Toolkit can be found at: +# http://www.datasciencetoolkit.org/. The provided APIs mimic the +# Google geocoding api. + +require 'geocoder/lookups/google' +require 'geocoder/results/dstk' + +module Geocoder::Lookup + class Dstk < Google + + def name + "Data Science Toolkit" + end + + def query_url(query) + host = configuration[:host] || "www.datasciencetoolkit.org" + "#{protocol}://#{host}/maps/api/geocode/json?" + url_query_string(query) + end + end +end diff --git a/lib/geocoder/results/dstk.rb b/lib/geocoder/results/dstk.rb new file mode 100644 index 00000000..ce98fe6a --- /dev/null +++ b/lib/geocoder/results/dstk.rb @@ -0,0 +1,6 @@ +require 'geocoder/results/google' + +module Geocoder::Result + class Dstk < Google + end +end \ No newline at end of file diff --git a/test/services_test.rb b/test/services_test.rb index 906f4fd3..022b4233 100644 --- a/test/services_test.rb +++ b/test/services_test.rb @@ -98,6 +98,26 @@ class ServicesTest < Test::Unit::TestCase Geocoder::Lookup::GooglePremier.new.query_url(Geocoder::Query.new("Madison Square Garden, New York, NY")) end + # --- DSTK (Data Science Toolkit) --- + + def test_dstk_result_components + Geocoder.configure(:lookup => :dstk, :dstk => { :host => 'NOT_AN_ACTUAL_HOST' }) + result = Geocoder.search("Madison Square Garden, New York, NY").first + assert_equal "Manhattan", + result.address_components_of_type(:sublocality).first['long_name'] + end + + def test_dstk_query_url + Geocoder.configure(:lookup => :dstk, :dstk => { :host => 'NOT_AN_ACTUAL_HOST' }) + assert_equal "http://NOT_AN_ACTUAL_HOST/maps/api/geocode/json?address=Madison+Square+Garden%2C+New+York%2C+NY&language=en&sensor=false", + Geocoder::Lookup::Dstk.new.query_url(Geocoder::Query.new("Madison Square Garden, New York, NY")) + end + + def test_dstk_default_query_url + Geocoder.configure(:lookup => :dstk) + assert_equal "http://www.datasciencetoolkit.org/maps/api/geocode/json?address=Madison+Square+Garden%2C+New+York%2C+NY&language=en&sensor=false", + Geocoder::Lookup::Dstk.new.query_url(Geocoder::Query.new("Madison Square Garden, New York, NY")) + end # --- Yahoo --- diff --git a/test/test_helper.rb b/test/test_helper.rb index b74017d4..24ca32c7 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -119,6 +119,13 @@ module Geocoder end end + class Dstk + private + def fixture_prefix + "google" + end + end + class Yandex private def default_fixture_filename -- GitLab