darrell-geokit 1.2.4.1 → 1.4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,88 @@
1
+ # encoding: utf-8
2
+ require File.join(File.dirname(__FILE__), 'test_base_geocoder')
3
+
4
+ class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
5
+
6
+ IP_FAILURE=<<-EOF
7
+ Country: (Private Address) (XX)
8
+ City: (Private Address)
9
+ Latitude:
10
+ Longitude:
11
+ EOF
12
+
13
+ IP_SUCCESS=<<-EOF
14
+ Country: UNITED STATES (US)
15
+ City: Sugar Grove, IL
16
+ Latitude: 41.7696
17
+ Longitude: -88.4588
18
+ EOF
19
+
20
+ IP_UNICODED=<<-EOF
21
+ Country: SWEDEN (SE)
22
+ City: Borås
23
+ Latitude: 57.7167
24
+ Longitude: 12.9167
25
+ EOF
26
+
27
+ def setup
28
+ super
29
+ @success.provider = "hostip"
30
+ end
31
+
32
+ def test_successful_lookup
33
+ success = MockSuccess.new
34
+ success.expects(:body).returns(IP_SUCCESS)
35
+ url = 'http://api.hostip.info/get_html.php?ip=12.215.42.19&position=true'
36
+ GeoKit::Geocoders::IpGeocoder.expects(:call_geocoder_service).with(url).returns(success)
37
+ location = GeoKit::Geocoders::IpGeocoder.geocode('12.215.42.19')
38
+ assert_not_nil location
39
+ assert_equal 41.7696, location.lat
40
+ assert_equal(-88.4588, location.lng)
41
+ assert_equal "Sugar Grove", location.city
42
+ assert_equal "IL", location.state
43
+ assert_equal "US", location.country_code
44
+ assert_equal "hostip", location.provider
45
+ assert location.success?
46
+ end
47
+
48
+ def test_unicoded_lookup
49
+ success = MockSuccess.new
50
+ success.expects(:body).returns(IP_UNICODED)
51
+ url = 'http://api.hostip.info/get_html.php?ip=12.215.42.19&position=true'
52
+ GeoKit::Geocoders::IpGeocoder.expects(:call_geocoder_service).with(url).returns(success)
53
+ location = GeoKit::Geocoders::IpGeocoder.geocode('12.215.42.19')
54
+ assert_not_nil location
55
+ assert_equal 57.7167, location.lat
56
+ assert_equal 12.9167, location.lng
57
+ assert_equal "Bor\303\245s", location.city
58
+ assert_nil location.state
59
+ assert_equal "SE", location.country_code
60
+ assert_equal "hostip", location.provider
61
+ assert location.success?
62
+ end
63
+
64
+ def test_failed_lookup
65
+ failure = MockSuccess.new
66
+ failure.expects(:body).returns(IP_FAILURE)
67
+ url = 'http://api.hostip.info/get_html.php?ip=10.10.10.10&position=true'
68
+ GeoKit::Geocoders::IpGeocoder.expects(:call_geocoder_service).with(url).returns(failure)
69
+ location = GeoKit::Geocoders::IpGeocoder.geocode("10.10.10.10")
70
+ assert_not_nil location
71
+ assert !location.success?
72
+ end
73
+
74
+ def test_invalid_ip
75
+ location = GeoKit::Geocoders::IpGeocoder.geocode("blah")
76
+ assert_not_nil location
77
+ assert !location.success?
78
+ end
79
+
80
+ def test_service_unavailable
81
+ failure = MockFailure.new
82
+ url = 'http://api.hostip.info/get_html.php?ip=10.10.10.10&position=true'
83
+ GeoKit::Geocoders::IpGeocoder.expects(:call_geocoder_service).with(url).returns(failure)
84
+ location = GeoKit::Geocoders::IpGeocoder.geocode("10.10.10.10")
85
+ assert_not_nil location
86
+ assert !location.success?
87
+ end
88
+ end
data/test/test_latlng.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'test/unit'
2
2
  require 'lib/geokit'
3
+ require 'mocha'
3
4
 
4
5
  class LatLngTest < Test::Unit::TestCase #:nodoc: all
5
6
 
@@ -9,6 +10,25 @@ class LatLngTest < Test::Unit::TestCase #:nodoc: all
9
10
  @point = Geokit::LatLng.new(@loc_a.lat, @loc_a.lng)
10
11
  end
11
12
 
13
+ def valid_reverse_geocoding_result
14
+ location = Geokit::GeoLoc.new({
15
+ :city => "Essen",
16
+ :country_code => "DE",
17
+ :lat => 51.4578329,
18
+ :lng => 7.0166848,
19
+ :provider => "google",
20
+ :state => "Nordrhein-Westfalen",
21
+ :street_address => "Porscheplatz 1",
22
+ :zip => "45127"
23
+ })
24
+
25
+ location.full_address = "Porscheplatz 1, 45127 Essen, Deutschland"
26
+ location.precision = 'address'
27
+ location.provider = 'google'
28
+ location.success = true
29
+ location
30
+ end
31
+
12
32
  def test_distance_between_same_using_defaults
13
33
  assert_equal 0, Geokit::LatLng.distance_between(@loc_a, @loc_a)
14
34
  assert_equal 0, @loc_a.distance_to(@loc_a)
@@ -128,5 +148,62 @@ class LatLngTest < Test::Unit::TestCase #:nodoc: all
128
148
  res=Geokit::LatLng.normalize([lat,lng])
129
149
  assert_equal res,Geokit::LatLng.new(lat,lng)
130
150
  end
151
+
152
+ def test_hash
153
+ lat=37.7690
154
+ lng=-122.443
155
+ first = Geokit::LatLng.new(lat,lng)
156
+ second = Geokit::LatLng.new(lat,lng)
157
+ assert_equal first.hash, second.hash
158
+ end
159
+
160
+ def test_eql?
161
+ lat=37.7690
162
+ lng=-122.443
163
+ first = Geokit::LatLng.new(lat,lng)
164
+ second = Geokit::LatLng.new(lat,lng)
165
+ assert first.eql?(second)
166
+ assert second.eql?(first)
167
+ end
168
+
169
+ def test_reverse_geocode
170
+ point = Geokit::LatLng.new(51.4578329, 7.0166848)
171
+ Geokit::Geocoders::MultiGeocoder.expects(:reverse_geocode).with(point).returns(valid_reverse_geocoding_result)
172
+ res = point.reverse_geocode
131
173
 
174
+ assert_equal "Nordrhein-Westfalen", res.state
175
+ assert_equal "Essen", res.city
176
+ assert_equal "45127", res.zip
177
+ assert_equal "51.4578329,7.0166848", res.ll # slightly dif from yahoo
178
+ assert res.is_us? == false
179
+ assert_equal "Porscheplatz 1, 45127 Essen, Deutschland", res.full_address #slightly different from yahoo
180
+ end
181
+
182
+ def test_reverse_geocoding_using_specific_geocoder
183
+ point = Geokit::LatLng.new(51.4578329, 7.0166848)
184
+ Geokit::Geocoders::GoogleGeocoder.expects(:reverse_geocode).with(point).returns(valid_reverse_geocoding_result)
185
+ res = point.reverse_geocode(:using => Geokit::Geocoders::GoogleGeocoder)
186
+
187
+ assert_equal "Nordrhein-Westfalen", res.state
188
+ assert_equal "Essen", res.city
189
+ assert_equal "45127", res.zip
190
+ assert_equal "51.4578329,7.0166848", res.ll # slightly dif from yahoo
191
+ assert res.is_us? == false
192
+ assert_equal "Porscheplatz 1, 45127 Essen, Deutschland", res.full_address #slightly different from yahoo
193
+ assert_equal "google", res.provider
194
+ end
195
+
196
+ def test_reverse_geocoding_using_specific_geocoder_short_syntax
197
+ point = Geokit::LatLng.new(51.4578329, 7.0166848)
198
+ Geokit::Geocoders::GoogleGeocoder.expects(:reverse_geocode).with(point).returns(valid_reverse_geocoding_result)
199
+ res = point.reverse_geocode(:using => :google)
200
+
201
+ assert_equal "Nordrhein-Westfalen", res.state
202
+ assert_equal "Essen", res.city
203
+ assert_equal "45127", res.zip
204
+ assert_equal "51.4578329,7.0166848", res.ll # slightly dif from yahoo
205
+ assert res.is_us? == false
206
+ assert_equal "Porscheplatz 1, 45127 Essen, Deutschland", res.full_address #slightly different from yahoo
207
+ assert_equal "google", res.provider
208
+ end
132
209
  end
@@ -10,27 +10,27 @@ class MultiGeocoderTest < BaseGeocoderTest #:nodoc: all
10
10
  end
11
11
 
12
12
  def test_successful_first
13
- Geokit::Geocoders::GoogleGeocoder.expects(:geocode).with(@address).returns(@success)
13
+ Geokit::Geocoders::GoogleGeocoder.expects(:geocode).with(@address, {}).returns(@success)
14
14
  assert_equal @success, Geokit::Geocoders::MultiGeocoder.geocode(@address)
15
15
  end
16
16
 
17
17
  def test_failover
18
- Geokit::Geocoders::GoogleGeocoder.expects(:geocode).with(@address).returns(@failure)
19
- Geokit::Geocoders::YahooGeocoder.expects(:geocode).with(@address).returns(@success)
18
+ Geokit::Geocoders::GoogleGeocoder.expects(:geocode).with(@address, {}).returns(@failure)
19
+ Geokit::Geocoders::YahooGeocoder.expects(:geocode).with(@address, {}).returns(@success)
20
20
  assert_equal @success, Geokit::Geocoders::MultiGeocoder.geocode(@address)
21
21
  end
22
22
 
23
23
  def test_double_failover
24
- Geokit::Geocoders::GoogleGeocoder.expects(:geocode).with(@address).returns(@failure)
25
- Geokit::Geocoders::YahooGeocoder.expects(:geocode).with(@address).returns(@failure)
26
- Geokit::Geocoders::UsGeocoder.expects(:geocode).with(@address).returns(@success)
24
+ Geokit::Geocoders::GoogleGeocoder.expects(:geocode).with(@address, {}).returns(@failure)
25
+ Geokit::Geocoders::YahooGeocoder.expects(:geocode).with(@address, {}).returns(@failure)
26
+ Geokit::Geocoders::UsGeocoder.expects(:geocode).with(@address, {}).returns(@success)
27
27
  assert_equal @success, Geokit::Geocoders::MultiGeocoder.geocode(@address)
28
28
  end
29
29
 
30
30
  def test_failure
31
- Geokit::Geocoders::GoogleGeocoder.expects(:geocode).with(@address).returns(@failure)
32
- Geokit::Geocoders::YahooGeocoder.expects(:geocode).with(@address).returns(@failure)
33
- Geokit::Geocoders::UsGeocoder.expects(:geocode).with(@address).returns(@failure)
31
+ Geokit::Geocoders::GoogleGeocoder.expects(:geocode).with(@address, {}).returns(@failure)
32
+ Geokit::Geocoders::YahooGeocoder.expects(:geocode).with(@address, {}).returns(@failure)
33
+ Geokit::Geocoders::UsGeocoder.expects(:geocode).with(@address, {}).returns(@failure)
34
34
  assert_equal @failure, Geokit::Geocoders::MultiGeocoder.geocode(@address)
35
35
  end
36
36
 
@@ -41,4 +41,53 @@ class MultiGeocoderTest < BaseGeocoderTest #:nodoc: all
41
41
  Geokit::Geocoders.provider_order = temp
42
42
  end
43
43
 
44
+ def test_blank_address
45
+ t1, t2 = Geokit::Geocoders.provider_order, Geokit::Geocoders.ip_provider_order # will need to reset after
46
+ Geokit::Geocoders.provider_order = [:google]
47
+ Geokit::Geocoders.ip_provider_order = [:geo_plugin]
48
+ Geokit::Geocoders::GoogleGeocoder.expects(:geocode).with("", {}).returns(@failure)
49
+ Geokit::Geocoders::GeoPluginGeocoder.expects(:geocode).never
50
+ assert_equal @failure, Geokit::Geocoders::MultiGeocoder.geocode("")
51
+ Geokit::Geocoders.provider_order, Geokit::Geocoders.ip_provider_order = t1, t2 # reset to orig values
52
+ end
53
+
54
+ def test_reverse_geocode_successful_first
55
+ Geokit::Geocoders::GoogleGeocoder.expects(:reverse_geocode).with(@latlng).returns(@success)
56
+ assert_equal @success, Geokit::Geocoders::MultiGeocoder.reverse_geocode(@latlng)
57
+ end
58
+
59
+ def test_reverse_geocode_failover
60
+ Geokit::Geocoders::GoogleGeocoder.expects(:reverse_geocode).with(@latlng).returns(@failure)
61
+ Geokit::Geocoders::YahooGeocoder.expects(:reverse_geocode).with(@latlng).returns(@success)
62
+ assert_equal @success, Geokit::Geocoders::MultiGeocoder.reverse_geocode(@latlng)
63
+ end
64
+
65
+ def test_reverse_geocode_double_failover
66
+ Geokit::Geocoders::GoogleGeocoder.expects(:reverse_geocode).with(@latlng).returns(@failure)
67
+ Geokit::Geocoders::YahooGeocoder.expects(:reverse_geocode).with(@latlng).returns(@failure)
68
+ Geokit::Geocoders::UsGeocoder.expects(:reverse_geocode).with(@latlng).returns(@success)
69
+ assert_equal @success, Geokit::Geocoders::MultiGeocoder.reverse_geocode(@latlng)
70
+ end
71
+
72
+ def test_reverse_geocode_failure
73
+ Geokit::Geocoders::GoogleGeocoder.expects(:reverse_geocode).with(@latlng).returns(@failure)
74
+ Geokit::Geocoders::YahooGeocoder.expects(:reverse_geocode).with(@latlng).returns(@failure)
75
+ Geokit::Geocoders::UsGeocoder.expects(:reverse_geocode).with(@latlng).returns(@failure)
76
+ assert_equal @failure, Geokit::Geocoders::MultiGeocoder.reverse_geocode(@latlng)
77
+ end
78
+
79
+ def test_reverse_geocode_with_invalid_provider
80
+ temp = Geokit::Geocoders::provider_order
81
+ Geokit::Geocoders.provider_order = [:bogus]
82
+ assert_equal @failure, Geokit::Geocoders::MultiGeocoder.reverse_geocode(@latlng)
83
+ Geokit::Geocoders.provider_order = temp
84
+ end
85
+
86
+ def test_reverse_geocode_with_blank_latlng
87
+ t1 = Geokit::Geocoders.provider_order # will need to reset after
88
+ Geokit::Geocoders.provider_order = [:google]
89
+ Geokit::Geocoders::GoogleGeocoder.expects(:reverse_geocode).with("").returns(@failure)
90
+ assert_equal @failure, Geokit::Geocoders::MultiGeocoder.reverse_geocode("")
91
+ Geokit::Geocoders.provider_order = t1 # reset to orig values
92
+ end
44
93
  end
@@ -0,0 +1,38 @@
1
+ require File.join(File.dirname(__FILE__), 'test_base_geocoder')
2
+
3
+ Geokit::Geocoders::ip_provider_order=[:geo_plugin,:ip]
4
+
5
+ class MultiIpGeocoderTest < BaseGeocoderTest #:nodoc: all
6
+
7
+ def setup
8
+ @ip_address = '10.10.10.10'
9
+ @success = Geokit::GeoLoc.new({:city=>"SAN FRANCISCO", :state=>"CA", :country_code=>"US", :lat=>37.7742, :lng=>-122.417068})
10
+ @success.success = true
11
+ @failure = Geokit::GeoLoc.new
12
+ end
13
+
14
+ def test_successful_first
15
+ Geokit::Geocoders::GeoPluginGeocoder.expects(:geocode).with(@ip_address, {}).returns(@success)
16
+ assert_equal @success, Geokit::Geocoders::MultiGeocoder.geocode(@ip_address)
17
+ end
18
+
19
+ def test_failover
20
+ Geokit::Geocoders::GeoPluginGeocoder.expects(:geocode).with(@ip_address, {}).returns(@failure)
21
+ Geokit::Geocoders::IpGeocoder.expects(:geocode).with(@ip_address, {}).returns(@success)
22
+ assert_equal @success, Geokit::Geocoders::MultiGeocoder.geocode(@ip_address)
23
+ end
24
+
25
+ def test_failure
26
+ Geokit::Geocoders::GeoPluginGeocoder.expects(:geocode).with(@ip_address, {}).returns(@failure)
27
+ Geokit::Geocoders::IpGeocoder.expects(:geocode).with(@ip_address, {}).returns(@failure)
28
+ assert_equal @failure, Geokit::Geocoders::MultiGeocoder.geocode(@ip_address)
29
+ end
30
+
31
+ def test_invalid_provider
32
+ temp = Geokit::Geocoders::ip_provider_order
33
+ Geokit::Geocoders.ip_provider_order = [:bogus]
34
+ assert_equal @failure, Geokit::Geocoders::MultiGeocoder.geocode(@ip_address)
35
+ Geokit::Geocoders.ip_provider_order = temp
36
+ end
37
+
38
+ end
@@ -32,6 +32,15 @@ class YahooGeocoderTest < BaseGeocoderTest #:nodoc: all
32
32
  do_full_address_assertions(Geokit::Geocoders::YahooGeocoder.geocode(@address))
33
33
  end
34
34
 
35
+ def test_yahoo_full_address_accuracy
36
+ response = MockSuccess.new
37
+ response.expects(:body).returns(YAHOO_FULL)
38
+ url = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=Yahoo&location=#{Geokit::Inflector.url_escape(@address)}"
39
+ Geokit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
40
+ res = Geokit::Geocoders::YahooGeocoder.geocode(@address)
41
+ assert_equal 8, res.accuracy
42
+ end
43
+
35
44
  def test_yahoo_full_address_with_geo_loc
36
45
  response = MockSuccess.new
37
46
  response.expects(:body).returns(YAHOO_FULL)
@@ -48,6 +57,15 @@ class YahooGeocoderTest < BaseGeocoderTest #:nodoc: all
48
57
  do_city_assertions(Geokit::Geocoders::YahooGeocoder.geocode(@address))
49
58
  end
50
59
 
60
+ def test_yahoo_city_accuracy
61
+ response = MockSuccess.new
62
+ response.expects(:body).returns(YAHOO_CITY)
63
+ url = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=Yahoo&location=#{Geokit::Inflector.url_escape(@address)}"
64
+ Geokit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
65
+ res = Geokit::Geocoders::YahooGeocoder.geocode(@address)
66
+ assert_equal 4, res.accuracy
67
+ end
68
+
51
69
  def test_yahoo_city_with_geo_loc
52
70
  response = MockSuccess.new
53
71
  response.expects(:body).returns(YAHOO_CITY)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: darrell-geokit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4.1
4
+ version: 1.4.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andre Lewis and Bill Eisenhauer
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-09 00:00:00 -08:00
12
+ date: 2009-06-15 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -41,6 +41,7 @@ files:
41
41
  - test/test_yahoo_geocoder.rb
42
42
  has_rdoc: true
43
43
  homepage: http://geokit.rubyforge.org
44
+ licenses:
44
45
  post_install_message:
45
46
  rdoc_options:
46
47
  - --main
@@ -62,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
63
  requirements: []
63
64
 
64
65
  rubyforge_project: geokit
65
- rubygems_version: 1.2.0
66
+ rubygems_version: 1.3.5
66
67
  signing_key:
67
68
  specification_version: 2
68
69
  summary: none
@@ -71,8 +72,13 @@ test_files:
71
72
  - test/test_bounds.rb
72
73
  - test/test_ca_geocoder.rb
73
74
  - test/test_geoloc.rb
75
+ - test/test_geoplugin_geocoder.rb
74
76
  - test/test_google_geocoder.rb
77
+ - test/test_google_reverse_geocoder.rb
78
+ - test/test_inflector.rb
79
+ - test/test_ipgeocoder.rb
75
80
  - test/test_latlng.rb
76
81
  - test/test_multi_geocoder.rb
82
+ - test/test_multi_ip_geocoder.rb
77
83
  - test/test_us_geocoder.rb
78
84
  - test/test_yahoo_geocoder.rb