geokit 1.6.5 → 1.6.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +9 -0
  3. data/.travis.yml +13 -0
  4. data/CHANGELOG.md +92 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE +25 -0
  7. data/Manifest.txt +21 -0
  8. data/README.markdown +179 -176
  9. data/Rakefile +8 -1
  10. data/ext/mkrf_conf.rb +15 -0
  11. data/geokit.gemspec +33 -0
  12. data/lib/geokit/geocoders.rb +7 -774
  13. data/lib/geokit/inflectors.rb +38 -0
  14. data/lib/geokit/mappable.rb +61 -3
  15. data/lib/geokit/multi_geocoder.rb +61 -0
  16. data/lib/geokit/services/ca_geocoder.rb +55 -0
  17. data/lib/geokit/services/fcc.rb +57 -0
  18. data/lib/geokit/services/geo_plugin.rb +31 -0
  19. data/lib/geokit/services/geonames.rb +53 -0
  20. data/lib/geokit/services/google.rb +158 -0
  21. data/lib/geokit/services/google3.rb +202 -0
  22. data/lib/geokit/services/ip.rb +103 -0
  23. data/lib/geokit/services/openstreetmap.rb +119 -0
  24. data/lib/geokit/services/us_geocoder.rb +50 -0
  25. data/lib/geokit/services/yahoo.rb +75 -0
  26. data/lib/geokit/version.rb +3 -0
  27. data/test/helper.rb +92 -0
  28. data/test/test_base_geocoder.rb +1 -15
  29. data/test/test_bounds.rb +1 -2
  30. data/test/test_ca_geocoder.rb +1 -1
  31. data/test/test_geoloc.rb +35 -5
  32. data/test/test_geoplugin_geocoder.rb +1 -2
  33. data/test/test_google_geocoder.rb +39 -2
  34. data/test/test_google_geocoder3.rb +55 -3
  35. data/test/test_google_reverse_geocoder.rb +1 -1
  36. data/test/test_inflector.rb +5 -3
  37. data/test/test_ipgeocoder.rb +25 -1
  38. data/test/test_latlng.rb +1 -3
  39. data/test/test_multi_geocoder.rb +1 -1
  40. data/test/test_multi_ip_geocoder.rb +1 -1
  41. data/test/test_openstreetmap_geocoder.rb +161 -0
  42. data/test/test_polygon_contains.rb +101 -0
  43. data/test/test_us_geocoder.rb +1 -1
  44. data/test/test_yahoo_geocoder.rb +18 -1
  45. metadata +164 -83
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- require File.join(File.dirname(__FILE__), 'test_base_geocoder')
2
+ require File.join(File.dirname(__FILE__), 'helper')
3
3
 
4
4
  class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
5
5
 
@@ -17,6 +17,13 @@ class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
17
17
  Longitude: -88.4588
18
18
  EOF
19
19
 
20
+ IP_LATIN=<<-EOF
21
+ Country: BRAZIL (BR)
22
+ City: S\xE3o Jos\xE9 do Rio Pr\xEAto\n
23
+ Latitude: -20.8
24
+ Longitude: -49.3833
25
+ EOF
26
+
20
27
  IP_UNICODED=<<-EOF
21
28
  Country: SWEDEN (SE)
22
29
  City: Borås
@@ -73,6 +80,23 @@ class IpGeocoderTest < BaseGeocoderTest #:nodoc: all
73
80
  assert location.success?
74
81
  end
75
82
 
83
+ def test_non_unicoded_lookup
84
+ success = MockSuccess.new
85
+ success.stubs(:body).returns(IP_LATIN)
86
+ success.stubs(:[]).with('content-type').returns('text/plain; charset=iso-8859-1')
87
+ url = 'http://api.hostip.info/get_html.php?ip=201.23.177.144&position=true'
88
+ GeoKit::Geocoders::IpGeocoder.expects(:call_geocoder_service).with(url).returns(success)
89
+ location = GeoKit::Geocoders::IpGeocoder.geocode('201.23.177.144')
90
+ assert_not_nil location
91
+ assert_equal -20.8, location.lat
92
+ assert_equal -49.3833, location.lng
93
+ assert_equal "São José Do Rio Prêto", location.city
94
+ assert_nil location.state
95
+ assert_equal "BR", location.country_code
96
+ assert_equal "hostip", location.provider
97
+ assert location.success?
98
+ end
99
+
76
100
  def test_failed_lookup
77
101
  failure = MockSuccess.new
78
102
  failure.expects(:body).returns(IP_FAILURE)
@@ -1,6 +1,4 @@
1
- require 'test/unit'
2
- require 'lib/geokit'
3
- require 'mocha'
1
+ require File.join(File.dirname(__FILE__), 'helper')
4
2
 
5
3
  class LatLngTest < Test::Unit::TestCase #:nodoc: all
6
4
 
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), 'test_base_geocoder')
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
2
 
3
3
  Geokit::Geocoders::provider_order=[:google,:yahoo,:us]
4
4
 
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), 'test_base_geocoder')
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
2
 
3
3
  Geokit::Geocoders::ip_provider_order=[:geo_plugin,:ip]
4
4
 
@@ -0,0 +1,161 @@
1
+ # encoding: utf-8
2
+ require File.join(File.dirname(__FILE__), 'helper')
3
+
4
+ Geokit::Geocoders::osm = 'OSM'
5
+
6
+ class OSMGeocoderTest < BaseGeocoderTest #:nodoc: all
7
+ OSM_FULL=<<-EOF.strip
8
+ [{"place_id":"425554497","licence":"Data Copyright OpenStreetMap Contributors, Some Rights Reserved. CC-BY-SA 2.0.","boundingbox":["37.792341","37.792441","-122.394074","-122.393974"],"lat":"37.792391","lon":"-122.394024","display_name":"100, Spear Street, Financial District, San Francisco, California, 94105, United States of America","class":"place","type":"house","address":{"house_number":"100","road":"Spear Street","place":"Financial District","city":"San Francisco","county":"San Francisco","state":"California","postcode":"94105","country":"United States of America","country_code":"us"}}]
9
+ EOF
10
+
11
+
12
+ OSM_CITY=<<-EOF.strip
13
+ [{"place_id":"1586484","licence":"Data Copyright OpenStreetMap Contributors, Some Rights Reserved. CC-BY-SA 2.0.","osm_type":"node","osm_id":"316944780","boundingbox":["37.7240965271","37.744100341797","-122.40126586914","-122.38125823975"],"lat":"37.7340974","lon":"-122.3912596","display_name":"San Francisco, California, United States of America","class":"place","type":"county","icon":"http://nominatim.openstreetmap.org/images/mapicons/poi_boundary_administrative.p.20.png","address":{"county":"San Francisco","state":"California","country":"United States of America","country_code":"us"}},{"place_id":"42109083","licence":"Data Copyright OpenStreetMap Contributors, Some Rights Reserved. CC-BY-SA 2.0.","osm_type":"way","osm_id":"33090874","boundingbox":["37.6398277282715","37.8230590820312","-123.173828125","-122.935707092285"],"lat":"37.7333682068208","lon":"-123.051926367593","display_name":"San Francisco, Marin, California, United States of America","class":"place","type":"city","icon":"http://nominatim.openstreetmap.org/images/mapicons/poi_place_city.p.20.png","address":{"city":"San Francisco","county":"Marin","state":"California","country":"United States of America","country_code":"us"}},{"place_id":"145970","licence":"Data Copyright OpenStreetMap Contributors, Some Rights Reserved. CC-BY-SA 2.0.","osm_type":"node","osm_id":"26819236","boundingbox":["37.768957366943","37.788961181641","-122.42920471191","-122.40919708252"],"lat":"37.7789601","lon":"-122.419199","display_name":"San Francisco, San Francisco County, California, United States of America, North America","class":"place","type":"city","icon":"http://nominatim.openstreetmap.org/images/mapicons/poi_place_city.p.20.png","address":{"city":"San Francisco","county":"San Francisco County","state":"California","country":"United States of America","country_code":"us","place":"North America"}},{"place_id":"42108900","licence":"Data Copyright OpenStreetMap Contributors, Some Rights Reserved. CC-BY-SA 2.0.","osm_type":"way","osm_id":"33090814","boundingbox":["37.7067184448242","37.9298248291016","-122.612289428711","-122.281776428223"],"lat":"37.7782304646168","lon":"-122.442503042395","display_name":"San Francisco, San Francisco County, California, United States of America","class":"place","type":"city","icon":"http://nominatim.openstreetmap.org/images/mapicons/poi_place_city.p.20.png","address":{"city":"San Francisco","county":"San Francisco County","state":"California","country":"United States of America","country_code":"us"}}]
14
+ EOF
15
+
16
+ OSM_REVERSE_MADRID=<<-EOF.strip
17
+ {"place_id":"41067113","licence":"Data Copyright OpenStreetMap Contributors, Some Rights Reserved. CC-BY-SA 2.0.","osm_type":"way","osm_id":"31822457","lat":"40.3787537310091","lon":"-3.70187699287946","display_name":"Línea 3, Calle del Doctor Tolosa Latour, Usera, Madrid, 28026, Spain","address":{"subway":"Línea 3","road":"Calle del Doctor Tolosa Latour","suburb":"Usera","city_district":"Usera","city":"Madrid","county":"Madrid","state":"Madrid","postcode":"28026","country":"Spain","country_code":"es"}}
18
+ EOF
19
+
20
+ OSM_REVERSE_PRILEP=<<-EOF.strip
21
+ {"place_id":"46960069","licence":"Data Copyright OpenStreetMap Contributors, Some Rights Reserved. CC-BY-SA 2.0.","osm_type":"way","osm_id":"39757255","lat":"41.3508581896005","lon":"21.549896984439","display_name":"Gimnasium Mirche Acev, Marksova, Prilep, Macedonia","address":{"school":"Gimnasium Mirche Acev","road":"Marksova","city":"Prilep","country":"Macedonia","country_code":"mk"}}
22
+ EOF
23
+
24
+ def setup
25
+ super
26
+ @osm_full_hash = {:street_address=>"100 Spear St", :city=>"San Francisco", :state=>"CA", :zip=>"94105", :country_code=>"US"}
27
+ @osm_city_hash = {:city=>"San Francisco", :state=>"CA"}
28
+ @osm_full_loc = Geokit::GeoLoc.new(@osm_full_hash)
29
+ @osm_city_loc = Geokit::GeoLoc.new(@osm_city_hash)
30
+ end
31
+
32
+ # the testing methods themselves
33
+ def test_osm_full_address
34
+ response = MockSuccess.new
35
+ response.expects(:body).returns(OSM_FULL)
36
+ url="http://nominatim.openstreetmap.org/search?format=json&polygon=0&addressdetails=1&q=#{Geokit::Inflector.url_escape(@full_address_short_zip)}"
37
+ Geokit::Geocoders::OSMGeocoder.expects(:call_geocoder_service).with(url).returns(response)
38
+ do_full_address_assertions(Geokit::Geocoders::OSMGeocoder.geocode(@full_address_short_zip))
39
+ end
40
+
41
+ def test_osm_full_address_accuracy
42
+ response = MockSuccess.new
43
+ response.expects(:body).returns(OSM_FULL)
44
+ url="http://nominatim.openstreetmap.org/search?format=json&polygon=0&addressdetails=1&q=#{Geokit::Inflector.url_escape(@full_address_short_zip)}"
45
+ Geokit::Geocoders::OSMGeocoder.expects(:call_geocoder_service).with(url).returns(response)
46
+ res = Geokit::Geocoders::OSMGeocoder.geocode(@full_address_short_zip)
47
+ assert_equal 'house', res.accuracy
48
+ end
49
+
50
+ def test_osm_full_address_with_geo_loc
51
+ response = MockSuccess.new
52
+ response.expects(:body).returns(OSM_FULL)
53
+ url="http://nominatim.openstreetmap.org/search?format=json&polygon=0&addressdetails=1&q=#{Geokit::Inflector.url_escape(@full_address_short_zip)}"
54
+ Geokit::Geocoders::OSMGeocoder.expects(:call_geocoder_service).with(url).returns(response)
55
+ do_full_address_assertions(Geokit::Geocoders::OSMGeocoder.geocode(@osm_full_loc))
56
+ end
57
+
58
+ def test_osm_city
59
+ response = MockSuccess.new
60
+ response.expects(:body).returns(OSM_CITY)
61
+ url="http://nominatim.openstreetmap.org/search?format=json&polygon=0&addressdetails=1&q=#{Geokit::Inflector.url_escape(@address)}"
62
+ Geokit::Geocoders::OSMGeocoder.expects(:call_geocoder_service).with(url).returns(response)
63
+ do_city_assertions(Geokit::Geocoders::OSMGeocoder.geocode(@address))
64
+ end
65
+
66
+ def test_osm_city_accuracy
67
+ response = MockSuccess.new
68
+ response.expects(:body).returns(OSM_CITY)
69
+ url="http://nominatim.openstreetmap.org/search?format=json&polygon=0&addressdetails=1&q=#{Geokit::Inflector.url_escape(@address)}"
70
+ Geokit::Geocoders::OSMGeocoder.expects(:call_geocoder_service).with(url).returns(response)
71
+ res = Geokit::Geocoders::OSMGeocoder.geocode(@address)
72
+ assert_equal "county", res.accuracy
73
+ end
74
+
75
+ def test_osm_city_with_geo_loc
76
+ response = MockSuccess.new
77
+ response.expects(:body).returns(OSM_CITY)
78
+ url="http://nominatim.openstreetmap.org/search?format=json&polygon=0&addressdetails=1&q=#{Geokit::Inflector.url_escape(@address)}"
79
+ Geokit::Geocoders::OSMGeocoder.expects(:call_geocoder_service).with(url).returns(response)
80
+ do_city_assertions(Geokit::Geocoders::OSMGeocoder.geocode(@osm_city_loc))
81
+ end
82
+
83
+ def test_reverse_geo_coding
84
+ response = MockSuccess.new
85
+ response.expects(:body).returns(OSM_REVERSE_PRILEP)
86
+ prilep = Geokit::GeoLoc.new
87
+ prilep.lat, prilep.lng = "41.3527177", "21.5497808"
88
+ url = "http://nominatim.openstreetmap.org/reverse?format=json&addressdetails=1&lat=#{prilep.lat}&lon=#{prilep.lng}"
89
+ Geokit::Geocoders::OSMGeocoder.expects(:call_geocoder_service).with(url).returns(response)
90
+ res = Geokit::Geocoders::OSMGeocoder.do_reverse_geocode(prilep.ll)
91
+
92
+ #OSM does not return the exast lat lng in response
93
+ #assert_equal prilep.lat.to_s.slice(1..5), res.lat.to_s.slice(1..5)
94
+ #assert_equal prilep.lng.to_s.slice(1..5), res.lng.to_s.slice(1..5)
95
+ assert_equal "MK", res.country_code
96
+ assert_equal "osm", res.provider
97
+
98
+ assert_equal "Prilep", res.city
99
+ assert_nil res.state
100
+
101
+ assert_equal "Macedonia", res.country
102
+ assert_nil res.precision
103
+ assert_equal true, res.success
104
+
105
+ assert_equal "Marksova, Prilep, MK", res.full_address
106
+ assert_equal "Marksova", res.street_address
107
+ end
108
+
109
+ def test_reverse_geo_code
110
+ response = MockSuccess.new
111
+ response.expects(:body).returns(OSM_REVERSE_MADRID)
112
+ location = Geokit::GeoLoc.new
113
+ # Madrid
114
+ location.lat, location.lng = "40.4167413", "-3.7032498"
115
+ url = "http://nominatim.openstreetmap.org/reverse?format=json&addressdetails=1&lat=#{location.lat}&lon=#{location.lng}"
116
+ Geokit::Geocoders::OSMGeocoder.expects(:call_geocoder_service).with(url).returns(response)
117
+ res = Geokit::Geocoders::OSMGeocoder.do_reverse_geocode(location.ll)
118
+
119
+ assert_equal "ES", res.country_code
120
+ assert_equal "osm", res.provider
121
+
122
+ assert_equal "Madrid", res.city
123
+ assert_equal "Madrid", res.state
124
+
125
+ assert_equal "Spain", res.country
126
+ assert_equal true, res.success
127
+
128
+ assert_equal "Calle Del Doctor Tolosa Latour, Usera, Madrid, Madrid, 28026, ES", res.full_address
129
+ assert_equal "28026", res.zip
130
+ assert_equal "Calle Del Doctor Tolosa Latour", res.street_address
131
+ end
132
+
133
+ def test_service_unavailable
134
+ response = MockFailure.new
135
+ url = url="http://nominatim.openstreetmap.org/search?format=json&polygon=0&addressdetails=1&q=#{Geokit::Inflector.url_escape(@address)}"
136
+ Geokit::Geocoders::OSMGeocoder.expects(:call_geocoder_service).with(url).returns(response)
137
+ assert !Geokit::Geocoders::OSMGeocoder.geocode(@osm_city_loc).success
138
+ end
139
+
140
+ private
141
+
142
+ # next two methods do the assertions for both address-level and city-level lookups
143
+ def do_full_address_assertions(res)
144
+ assert_equal "California", res.state
145
+ assert_equal "San Francisco", res.city
146
+ assert_equal "37.792391,-122.394024", res.ll
147
+ assert res.is_us?
148
+ assert_equal "Spear Street 100, San Francisco, California, 94105, US", res.full_address
149
+ assert_equal "osm", res.provider
150
+ end
151
+
152
+ def do_city_assertions(res)
153
+ assert_equal "California", res.state
154
+ assert_equal "San Francisco", res.city
155
+ assert_equal "37.7340974,-122.3912596", res.ll
156
+ assert res.is_us?
157
+ assert_equal "San Francisco, California, US", res.full_address
158
+ assert_nil res.street_address
159
+ assert_equal "osm", res.provider
160
+ end
161
+ end
@@ -0,0 +1,101 @@
1
+ # encoding: utf-8
2
+ require File.join(File.dirname(__FILE__), 'helper')
3
+
4
+ class PolygonTest < Test::Unit::TestCase #:nodoc: all
5
+
6
+ def setup
7
+
8
+ #Create a simple square-ish polygon for easy testing
9
+ @p1 = Geokit::LatLng.new(45.3142533036254, -93.47527313511819)
10
+ @p2 = Geokit::LatLng.new(45.31232182518015, -93.34893036168069)
11
+ @p3 = Geokit::LatLng.new(45.23694281999268, -93.35167694371194)
12
+ @p4 = Geokit::LatLng.new(45.23500870841669, -93.47801971714944)
13
+ @p5 = Geokit::LatLng.new(45.3142533036254, -93.47527313511819)
14
+
15
+ @points = [@p1, @p2, @p3, @p4, @p5]
16
+ @polygon = Geokit::Polygon.new(@points)
17
+
18
+ @point_inside = Geokit::LatLng.new(45.27428243796789, -93.41648483416066)
19
+ @point_outside = Geokit::LatLng.new(45.45411010558687, -93.78151703160256)
20
+
21
+ #Create a more complex polygon with overlapping lines. Looks like a star of david
22
+ @c1 = Geokit::LatLng.new(45.48661334374487, -93.74665833078325)
23
+ @c2 = Geokit::LatLng.new(45.53521281284293, -93.32611083984375)
24
+ @c3 = Geokit::LatLng.new(45.28648197278281, -93.3673095703125)
25
+ @c4 = Geokit::LatLng.new(45.31497759107127, -93.75764465890825)
26
+ @c5 = Geokit::LatLng.new(45.36179519142128, -93.812255859375)
27
+ @c6 = Geokit::LatLng.new(45.40230699238177, -93.74908447265625)
28
+ @c7 = Geokit::LatLng.new(45.236217535866025, -93.60076904296875)
29
+ @c8 = Geokit::LatLng.new(45.39989638818863, -93.282485967502)
30
+ @c9 = Geokit::LatLng.new(45.565986795411376, -93.5760498046875)
31
+ @c10 = Geokit::LatLng.new(45.4345991655272, -93.73017883859575)
32
+ @c11 = Geokit::LatLng.new(45.48661334374487, -93.74665833078325)
33
+
34
+ @complex_points = [@c1, @c2, @c3, @c4, @c5, @c6, @c7, @c8, @c9, @c10, @c11]
35
+ @complex_polygon = Geokit::Polygon.new(@complex_points)
36
+
37
+ #Test three points that should be "inside" this complex shape
38
+ @complex_inside_one = Geokit::LatLng.new(45.52438983143154, -93.59818268101662)
39
+ @complex_inside_two = Geokit::LatLng.new(45.50321887154943, -93.37845611851662)
40
+ @complex_inside_three = Geokit::LatLng.new(45.28334174918666, -93.59543609898537)
41
+
42
+ #Test three points that should be "outside" this complex shape
43
+ @complex_outside_one = Geokit::LatLng.new(45.45314676076135, -93.563850405626)
44
+ @complex_outside_two = Geokit::LatLng.new(45.30435378077673, -93.6859130859375)
45
+ @complex_outside_three = Geokit::LatLng.new(45.538820010517036, -93.486946108751)
46
+
47
+ # Test open sided polygon aka line - for closing on initialize
48
+ @op1 = Geokit::LatLng.new(44.97402795596173, -92.7297592163086)
49
+ @op2 = Geokit::LatLng.new(44.97395509241393, -92.68448066781275)
50
+ @op3 = Geokit::LatLng.new(44.94455954512172, -92.68413734505884)
51
+ @op4 = Geokit::LatLng.new(44.94383053857761, -92.72876930306666)
52
+
53
+ @open_points = [@op1, @op2, @op3, @op4]
54
+ @open_polygon = Geokit::Polygon.new(@open_points)
55
+
56
+ end
57
+
58
+ def test_point_inside_poly
59
+ #puts "\n\nTesting point inside poly... {@polygon.contains?(@point_inside)}\n\n"
60
+ assert @polygon.contains?(@point_inside)
61
+ end
62
+
63
+ def test_point_outside_poly
64
+ #puts "\n\nTesting point outside poly... {@polygon.contains?(@point_outside)}\n\n"
65
+ assert !@polygon.contains?(@point_outside)
66
+ end
67
+
68
+ def test_points_inside_complex_poly
69
+ #puts "\n\nTesting points INSIDE complex poly..."
70
+ #puts "\tone: {@complex_polygon.contains?(@complex_inside_one)}"
71
+ #puts "\ttwo: {@complex_polygon.contains?(@complex_inside_two)}"
72
+ #puts "\tthree: {@complex_polygon.contains?(@complex_inside_three)}\n\n"
73
+ assert @complex_polygon.contains?(@complex_inside_one)
74
+ assert @complex_polygon.contains?(@complex_inside_two)
75
+ assert @complex_polygon.contains?(@complex_inside_three)
76
+ end
77
+
78
+ def test_points_outside_complex_poly
79
+ #puts "\n\nTesting points OUTSIDE complex poly..."
80
+ #puts "\tone: {@complex_polygon.contains?(@complex_outside_one)}"
81
+ #puts "\ttwo: {@complex_polygon.contains?(@complex_outside_two)}"
82
+ #puts "\tthree: {@complex_polygon.contains?(@complex_outside_three)}\n\n"
83
+ assert !@complex_polygon.contains?(@complex_outside_one)
84
+ assert !@complex_polygon.contains?(@complex_outside_two)
85
+ assert !@complex_polygon.contains?(@complex_outside_three)
86
+ end
87
+
88
+ def test_open_polygon
89
+ # A polygon can only exist of the last point is equal to the first
90
+ # Otherwise, it would just be a line of points.
91
+
92
+ #puts "\n\nTesting intialize function to close an open polygon..."
93
+ #puts "\t Does poly_x[0] (#{@open_polygon.poly_x[0]}) == poly_x[-1] (#{@open_polygon.poly_x[-1]}) ?"
94
+ #puts "\t Does poly_y[0] (#{@open_polygon.poly_y[0]}) == poly_y[-1] (#{@open_polygon.poly_y[-1]}) ?"
95
+
96
+ assert @open_polygon.poly_x[0] == @open_polygon.poly_x[-1]
97
+ assert @open_polygon.poly_y[0] == @open_polygon.poly_y[-1]
98
+
99
+ end
100
+
101
+ end
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), 'test_base_geocoder')
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
2
 
3
3
  Geokit::Geocoders::geocoder_us = nil
4
4
 
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), 'test_base_geocoder')
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
2
 
3
3
  Geokit::Geocoders::yahoo = 'Yahoo'
4
4
 
@@ -11,6 +11,10 @@ class YahooGeocoderTest < BaseGeocoderTest #:nodoc: all
11
11
  {"ResultSet":{"version":"1.0","Error":0,"ErrorMessage":"No error","Locale":"us_US","Quality":40,"Found":1,"Results":[{"quality":40,"latitude":"37.7742","longitude":"-122.417068","offsetlat":"37.7742","offsetlon":"-122.417068","radius":10700,"name":"","line1":"","line2":"San Francisco, CA","line3":"","line4":"United States","house":"","street":"","xstreet":"","unittype":"","unit":"","postal":"","neighborhood":"","city":"San Francisco","county":"San Francisco County","state":"California","country":"United States","countrycode":"US","statecode":"CA","countycode":"","uzip":"94102","hash":"","woeid":2487956,"woetype":7}]}}
12
12
  EOF
13
13
 
14
+ YAHOO_NO_RESULTS=<<-EOF.strip
15
+ {"ResultSet":{"version":"1.0","Error":0,"ErrorMessage":"No error","Locale":"us_US","Quality":10,"Found":0}}
16
+ EOF
17
+
14
18
  def setup
15
19
  super
16
20
  @yahoo_full_hash = {:street_address=>"100 Spear St", :city=>"San Francisco", :state=>"CA", :zip=>"94105-1522", :country_code=>"US"}
@@ -70,6 +74,19 @@ class YahooGeocoderTest < BaseGeocoderTest #:nodoc: all
70
74
  do_city_assertions(Geokit::Geocoders::YahooGeocoder.geocode(@yahoo_city_loc))
71
75
  end
72
76
 
77
+ def test_no_results
78
+ no_results_address = "ZZ, ZZ, ZZ"
79
+ no_results_full_hash = {:street_address=>"ZZ", :city=>"ZZ", :state=>"ZZ"}
80
+ no_results_full_loc = Geokit::GeoLoc.new(no_results_full_hash)
81
+
82
+ response = MockSuccess.new
83
+ response.expects(:body).returns(YAHOO_NO_RESULTS)
84
+ url = "http://where.yahooapis.com/geocode?flags=J&appid=Yahoo&q=#{Geokit::Inflector.url_escape(no_results_address)}"
85
+ Geokit::Geocoders::YahooGeocoder.expects(:call_geocoder_service).with(url).returns(response)
86
+ result = Geokit::Geocoders::YahooGeocoder.geocode(no_results_address)
87
+ assert_equal ",", result.ll
88
+ end
89
+
73
90
  def test_service_unavailable
74
91
  response = MockFailure.new
75
92
  url = "http://where.yahooapis.com/geocode?flags=J&appid=Yahoo&q=#{Geokit::Inflector.url_escape(@address)}"
metadata CHANGED
@@ -1,128 +1,209 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: geokit
3
- version: !ruby/object:Gem::Version
4
- hash: 5
5
- prerelease:
6
- segments:
7
- - 1
8
- - 6
9
- - 5
10
- version: 1.6.5
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.6.6
11
5
  platform: ruby
12
- authors:
13
- - James Cox, Andre Lewis & Bill Eisenhauer
6
+ authors:
7
+ - Michael Noack, James Cox, Andre Lewis & Bill Eisenhauer
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2012-01-23 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
11
+ date: 2013-09-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
21
14
  name: multi_json
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.3.2
32
20
  type: :runtime
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.3.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>'
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>'
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: simplecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov-rcov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
35
70
  name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: mocha
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
36
91
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
38
- none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- version: "0"
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: coveralls
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
46
104
  type: :development
47
- version_requirements: *id002
48
- description: Geokit provides geocoding and distance calculation in an easy-to-use API
49
- email:
50
- - james+geokit@imaj.es
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Geokit provides geocoding and distance calculation in an easy-to-use
112
+ API
113
+ email:
114
+ - michael+geokit@noack.com.au
51
115
  executables: []
52
-
53
- extensions: []
54
-
55
- extra_rdoc_files:
116
+ extensions:
117
+ - ext/mkrf_conf.rb
118
+ extra_rdoc_files:
56
119
  - README.markdown
57
- files:
120
+ files:
121
+ - .gitignore
122
+ - .travis.yml
123
+ - CHANGELOG.md
124
+ - Gemfile
125
+ - LICENSE
126
+ - Manifest.txt
58
127
  - README.markdown
59
128
  - Rakefile
60
- - lib/geokit/geocoders.rb
129
+ - ext/mkrf_conf.rb
130
+ - geokit.gemspec
61
131
  - lib/geokit.rb
132
+ - lib/geokit/geocoders.rb
133
+ - lib/geokit/inflectors.rb
62
134
  - lib/geokit/mappable.rb
135
+ - lib/geokit/multi_geocoder.rb
136
+ - lib/geokit/services/ca_geocoder.rb
137
+ - lib/geokit/services/fcc.rb
138
+ - lib/geokit/services/geo_plugin.rb
139
+ - lib/geokit/services/geonames.rb
140
+ - lib/geokit/services/google.rb
141
+ - lib/geokit/services/google3.rb
142
+ - lib/geokit/services/ip.rb
143
+ - lib/geokit/services/openstreetmap.rb
144
+ - lib/geokit/services/us_geocoder.rb
145
+ - lib/geokit/services/yahoo.rb
146
+ - lib/geokit/version.rb
147
+ - test/helper.rb
63
148
  - test/test_base_geocoder.rb
64
149
  - test/test_bounds.rb
65
150
  - test/test_ca_geocoder.rb
66
151
  - test/test_geoloc.rb
67
- - test/test_google_geocoder3.rb
68
- - test/test_google_geocoder.rb
69
- - test/test_latlng.rb
70
- - test/test_multi_geocoder.rb
71
- - test/test_us_geocoder.rb
72
- - test/test_yahoo_geocoder.rb
73
152
  - test/test_geoplugin_geocoder.rb
153
+ - test/test_google_geocoder.rb
154
+ - test/test_google_geocoder3.rb
74
155
  - test/test_google_reverse_geocoder.rb
75
156
  - test/test_inflector.rb
76
157
  - test/test_ipgeocoder.rb
158
+ - test/test_latlng.rb
159
+ - test/test_multi_geocoder.rb
77
160
  - test/test_multi_ip_geocoder.rb
78
- homepage: https://github.com/imajes/geokit-gem
79
- licenses: []
80
-
161
+ - test/test_openstreetmap_geocoder.rb
162
+ - test/test_polygon_contains.rb
163
+ - test/test_us_geocoder.rb
164
+ - test/test_yahoo_geocoder.rb
165
+ homepage: http://github.com/geokit/geokit
166
+ licenses:
167
+ - MIT
168
+ metadata: {}
81
169
  post_install_message:
82
- rdoc_options:
170
+ rdoc_options:
83
171
  - --main
84
172
  - README.markdown
85
- require_paths:
173
+ require_paths:
86
174
  - lib
87
- required_ruby_version: !ruby/object:Gem::Requirement
88
- none: false
89
- requirements:
90
- - - ">="
91
- - !ruby/object:Gem::Version
92
- hash: 3
93
- segments:
94
- - 0
95
- version: "0"
96
- required_rubygems_version: !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ">="
100
- - !ruby/object:Gem::Version
101
- hash: 3
102
- segments:
103
- - 0
104
- version: "0"
175
+ required_ruby_version: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ! '>='
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ required_rubygems_version: !ruby/object:Gem::Requirement
181
+ requirements:
182
+ - - ! '>='
183
+ - !ruby/object:Gem::Version
184
+ version: '0'
105
185
  requirements: []
106
-
107
- rubyforge_project: geokit
108
- rubygems_version: 1.8.15
186
+ rubyforge_project:
187
+ rubygems_version: 2.0.3
109
188
  signing_key:
110
- specification_version: 3
111
- summary: "Geokit: encoding and distance calculation gem"
112
- test_files:
189
+ specification_version: 4
190
+ summary: ! 'Geokit: encoding and distance calculation gem'
191
+ test_files:
192
+ - test/helper.rb
113
193
  - test/test_base_geocoder.rb
114
194
  - test/test_bounds.rb
115
195
  - test/test_ca_geocoder.rb
116
196
  - test/test_geoloc.rb
117
197
  - test/test_geoplugin_geocoder.rb
118
- - test/test_google_geocoder3.rb
119
198
  - test/test_google_geocoder.rb
199
+ - test/test_google_geocoder3.rb
120
200
  - test/test_google_reverse_geocoder.rb
121
201
  - test/test_inflector.rb
122
202
  - test/test_ipgeocoder.rb
123
203
  - test/test_latlng.rb
124
204
  - test/test_multi_geocoder.rb
125
205
  - test/test_multi_ip_geocoder.rb
206
+ - test/test_openstreetmap_geocoder.rb
207
+ - test/test_polygon_contains.rb
126
208
  - test/test_us_geocoder.rb
127
209
  - test/test_yahoo_geocoder.rb
128
- has_rdoc: true