From d1f036f1479ca5ed514ea6bd411c65e5ad4b73ef Mon Sep 17 00:00:00 2001
From: Chris Myers <chris@cbmyers.com>
Date: Mon, 3 Oct 2011 13:59:31 -0400
Subject: [PATCH] added nominatim

---
 lib/geocoder.rb       |  2 +-
 test/services_test.rb | 18 ++++++++++++++++++
 test/test_helper.rb   | 13 +++++++++++++
 3 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/lib/geocoder.rb b/lib/geocoder.rb
index 5bce2283..b73e6e9c 100644
--- a/lib/geocoder.rb
+++ b/lib/geocoder.rb
@@ -56,7 +56,7 @@ module Geocoder
   # All street address lookups, default first.
   #
   def street_lookups
-    [:google, :google_premier, :yahoo, :bing, :geocoder_ca, :yandex]
+    [:google, :google_premier, :yahoo, :bing, :geocoder_ca, :yandex, :nominatim]
   end
 
   ##
diff --git a/test/services_test.rb b/test/services_test.rb
index b01b84ab..479ce2e7 100644
--- a/test/services_test.rb
+++ b/test/services_test.rb
@@ -110,4 +110,22 @@ class ServicesTest < Test::Unit::TestCase
     results = Geocoder.search("no results")
     assert_equal 0, results.length
   end
+  
+  # --- Nominatim ---
+  
+   def test_nominatim_result_components
+    Geocoder::Configuration.lookup = :nominatim
+    result = Geocoder.search("Madison Square Garden, New York, NY").first
+    assert_equal "10001", result.postal_code
+  end
+
+  def test_nominatim_address_formatting
+    Geocoder::Configuration.lookup = :nominatim
+    result = Geocoder.search("Madison Square Garden, New York, NY").first
+    assert_equal "Madison Square Garden, West 31st Street, Long Island City, New York City, New York, 10001, United States of America",
+      result.address
+  end
+ 
+  
+  
 end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 137f756f..94d3ebf0 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -150,6 +150,19 @@ module Geocoder
       end
     end
 
+	class Nominatim < Base
+      private #-----------------------------------------------------------------
+      def fetch_raw_data(query, reverse = false)
+        raise TimeoutError if query == "timeout"
+        raise SocketError if query == "socket_error"
+        file = case query
+          when "no results";  :no_results
+          else                :madison_square_garden
+        end
+        read_fixture "nominatim_#{file}.json"
+      end
+    end
+
   end
 end
 
-- 
GitLab