geokit 1.8.5 → 1.9.0

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.
Files changed (76) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +0 -1
  3. data/CHANGELOG.md +7 -0
  4. data/README.markdown +31 -14
  5. data/fixtures/vcr_cassettes/geonames_geocode.yml +1 -1
  6. data/fixtures/vcr_cassettes/geonames_geocode_premium.yml +42 -0
  7. data/fixtures/vcr_cassettes/google_country_code_biased_result_orly.yml +160 -0
  8. data/fixtures/vcr_cassettes/google_country_code_biased_result_toledo.yml +111 -0
  9. data/fixtures/vcr_cassettes/google_result_toledo_default_bias.yml +275 -0
  10. data/fixtures/vcr_cassettes/google_sublocality.yml +126 -0
  11. data/fixtures/vcr_cassettes/mapbox_forward_geocode.yml +59 -0
  12. data/fixtures/vcr_cassettes/mapbox_reverse_geocode.yml +63 -0
  13. data/fixtures/vcr_cassettes/opencage_city.yml +51 -0
  14. data/fixtures/vcr_cassettes/opencage_full.yml +65 -0
  15. data/fixtures/vcr_cassettes/opencage_language_response_es.yml +66 -0
  16. data/fixtures/vcr_cassettes/opencage_reverse_madrid.yml +51 -0
  17. data/fixtures/vcr_cassettes/opencage_reverse_prilep.yml +53 -0
  18. data/geokit.gemspec +5 -3
  19. data/lib/geokit/bounds.rb +40 -31
  20. data/lib/geokit/core_ext.rb +1 -1
  21. data/lib/geokit/geo_loc.rb +63 -41
  22. data/lib/geokit/geocoders.rb +13 -13
  23. data/lib/geokit/geocoders/bing.rb +9 -9
  24. data/lib/geokit/geocoders/ca_geocoder.rb +29 -29
  25. data/lib/geokit/geocoders/fcc.rb +4 -4
  26. data/lib/geokit/geocoders/free_geo_ip.rb +6 -7
  27. data/lib/geokit/geocoders/geo_plugin.rb +5 -6
  28. data/lib/geokit/geocoders/geocodio.rb +2 -2
  29. data/lib/geokit/geocoders/geonames.rb +18 -12
  30. data/lib/geokit/geocoders/google.rb +31 -30
  31. data/lib/geokit/geocoders/ip.rb +3 -4
  32. data/lib/geokit/geocoders/mapbox.rb +94 -0
  33. data/lib/geokit/geocoders/mapquest.rb +5 -5
  34. data/lib/geokit/geocoders/opencage.rb +93 -0
  35. data/lib/geokit/geocoders/openstreetmap.rb +9 -6
  36. data/lib/geokit/geocoders/ripe.rb +3 -3
  37. data/lib/geokit/geocoders/us_geocoder.rb +10 -9
  38. data/lib/geokit/geocoders/yahoo.rb +33 -34
  39. data/lib/geokit/geocoders/yandex.rb +17 -17
  40. data/lib/geokit/inflectors.rb +4 -10
  41. data/lib/geokit/lat_lng.rb +50 -26
  42. data/lib/geokit/mappable.rb +83 -83
  43. data/lib/geokit/multi_geocoder.rb +25 -20
  44. data/lib/geokit/net_adapter/net_http.rb +7 -4
  45. data/lib/geokit/polygon.rb +36 -4
  46. data/lib/geokit/version.rb +1 -1
  47. data/test/helper.rb +15 -13
  48. data/test/test_base_geocoder.rb +6 -7
  49. data/test/test_bing_geocoder.rb +20 -21
  50. data/test/test_bounds.rb +26 -28
  51. data/test/test_ca_geocoder.rb +9 -10
  52. data/test/test_fcc_geocoder.rb +1 -1
  53. data/test/test_free_geo_ip_geocoder.rb +1 -1
  54. data/test/test_geo_plugin_geocoder.rb +9 -9
  55. data/test/test_geoloc.rb +7 -6
  56. data/test/test_geonames_geocoder.rb +28 -6
  57. data/test/test_google_geocoder.rb +210 -176
  58. data/test/test_inflector.rb +0 -1
  59. data/test/test_ipgeocoder.rb +17 -18
  60. data/test/test_latlng.rb +105 -85
  61. data/test/test_map_quest.rb +18 -21
  62. data/test/test_mapbox_geocoder.rb +31 -0
  63. data/test/test_mappable.rb +46 -0
  64. data/test/test_maxmind_geocoder.rb +1 -3
  65. data/test/test_multi_geocoder.rb +8 -9
  66. data/test/test_multi_ip_geocoder.rb +3 -5
  67. data/test/test_net_adapter.rb +4 -4
  68. data/test/test_opencage_geocoder.rb +108 -0
  69. data/test/test_openstreetmap_geocoder.rb +62 -44
  70. data/test/{test_polygon_contains.rb → test_polygon.rb} +30 -20
  71. data/test/test_ripe_geocoder.rb +2 -0
  72. data/test/test_us_geocoder.rb +7 -8
  73. data/test/test_yahoo_geocoder.rb +20 -21
  74. data/test/test_yandex_geocoder.rb +34 -35
  75. metadata +79 -56
  76. data/fixtures/vcr_cassettes/google_country_code_biased_result.yml +0 -401
@@ -1,3 +1,3 @@
1
1
  module Geokit
2
- VERSION = '1.8.5'
2
+ VERSION = '1.9.0'
3
3
  end
@@ -17,7 +17,10 @@ if ENV['COVERAGE']
17
17
  require 'coveralls'
18
18
  Coveralls.wear!
19
19
 
20
- SimpleCov.formatter = Coveralls::SimpleCov::Formatter
20
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
21
+ SimpleCov::Formatter::RcovFormatter,
22
+ Coveralls::SimpleCov::Formatter
23
+ ]
21
24
  SimpleCov.start do
22
25
  add_filter '/test/'
23
26
  add_group 'lib', 'lib'
@@ -26,7 +29,7 @@ if ENV['COVERAGE']
26
29
  SimpleCov.result.format!
27
30
  percent = SimpleCov.result.covered_percent
28
31
  unless percent >= COVERAGE_THRESHOLD
29
- puts "Coverage must be above #{COVERAGE_THRESHOLD}%. It is #{"%.2f" % percent}%"
32
+ puts "Coverage must be above #{COVERAGE_THRESHOLD}%. It is #{'%.2f' % percent}%"
30
33
  Kernel.exit(1)
31
34
  end
32
35
  end
@@ -36,7 +39,7 @@ require 'test/unit'
36
39
  require 'mocha/setup'
37
40
  require 'net/http'
38
41
 
39
- require File.join(File.dirname(__FILE__), "../lib/geokit.rb")
42
+ require File.join(File.dirname(__FILE__), '../lib/geokit.rb')
40
43
 
41
44
  class MockSuccess < Net::HTTPSuccess #:nodoc: all
42
45
  def initialize
@@ -75,7 +78,7 @@ Geokit::Geocoders::Geocoder.class_eval do
75
78
  end
76
79
  end
77
80
 
78
- def assert_array_in_delta(expected_array, actual_array, delta = 0.001, message='')
81
+ def assert_array_in_delta(expected_array, actual_array, delta = 0.001, message = '')
79
82
  full_message = build_message(message, "<?> and\n<?> expected to be within\n<?> of each other.\n", expected_array, actual_array, delta)
80
83
  assert_block(full_message) do
81
84
  expected_array.zip(actual_array).all?{|expected_item, actual_item|
@@ -91,7 +94,7 @@ VCR.configure do |c|
91
94
  c.hook_into :webmock # or :fakeweb
92
95
  # Yahoo BOSS Ignore changing params
93
96
  c.default_cassette_options = {
94
- :match_requests_on => [:method,
97
+ match_requests_on: [:method,
95
98
  VCR.request_matchers.uri_without_params(
96
99
  :oauth_nonce, :oauth_timestamp, :oauth_signature
97
100
  )
@@ -101,7 +104,6 @@ end
101
104
 
102
105
  # Base class for testing geocoders.
103
106
  class BaseGeocoderTest < Test::Unit::TestCase #:nodoc: all
104
-
105
107
  class Geokit::Geocoders::TestGeocoder < Geokit::Geocoders::Geocoder
106
108
  def self.do_get(url)
107
109
  sleep(2)
@@ -110,25 +112,25 @@ class BaseGeocoderTest < Test::Unit::TestCase #:nodoc: all
110
112
 
111
113
  # Defines common test fixtures.
112
114
  def setup
113
- Geokit::Geocoders::request_timeout = 10
115
+ Geokit::Geocoders.request_timeout = 10
114
116
  @address = 'San Francisco, CA'
115
117
  @full_address = '100 Spear St, San Francisco, CA, 94105-1522, US'
116
118
  @full_address_short_zip = '100 Spear St, San Francisco, CA, 94105, US'
117
119
 
118
120
  @latlng = Geokit::LatLng.new(37.7742, -122.417068)
119
- @success = Geokit::GeoLoc.new({:city=>"SAN FRANCISCO", :state=>"CA", :country_code=>"US", :lat=>@latlng.lat, :lng=>@latlng.lng})
121
+ @success = Geokit::GeoLoc.new({city: 'SAN FRANCISCO', state: 'CA', country_code: 'US', lat: @latlng.lat, lng: @latlng.lng})
120
122
  @success.success = true
121
123
  end
122
124
 
123
125
  def test_timeout_call_web_service
124
- url = "http://www.anything.com"
125
- Geokit::Geocoders::request_timeout = 1
126
+ url = 'http://www.anything.com'
127
+ Geokit::Geocoders.request_timeout = 1
126
128
  assert_nil Geokit::Geocoders::TestGeocoder.call_geocoder_service(url)
127
129
  end
128
130
 
129
131
  def test_successful_call_web_service
130
- url = "http://www.anything.com"
131
- Geokit::Geocoders::Geocoder.expects(:do_get).with(url).returns("SUCCESS")
132
- assert_equal "SUCCESS", Geokit::Geocoders::Geocoder.call_geocoder_service(url)
132
+ url = 'http://www.anything.com'
133
+ Geokit::Geocoders::Geocoder.expects(:do_get).with(url).returns('SUCCESS')
134
+ assert_equal 'SUCCESS', Geokit::Geocoders::Geocoder.call_geocoder_service(url)
133
135
  end
134
136
  end
@@ -2,7 +2,6 @@ require File.join(File.dirname(__FILE__), 'helper')
2
2
 
3
3
  # Base class for testing geocoders.
4
4
  class BaseGeocoderTest < Test::Unit::TestCase #:nodoc: all
5
-
6
5
  class Geokit::Geocoders::TestGeocoder < Geokit::Geocoders::Geocoder
7
6
  def self.do_get(url)
8
7
  sleep(2)
@@ -16,19 +15,19 @@ class BaseGeocoderTest < Test::Unit::TestCase #:nodoc: all
16
15
  @full_address_short_zip = '100 Spear St, San Francisco, CA, 94105, US'
17
16
 
18
17
  @latlng = Geokit::LatLng.new(37.7742, -122.417068)
19
- @success = Geokit::GeoLoc.new({:city=>"SAN FRANCISCO", :state=>"CA", :country_code=>"US", :lat=>@latlng.lat, :lng=>@latlng.lng})
18
+ @success = Geokit::GeoLoc.new({city: 'SAN FRANCISCO', state: 'CA', country_code: 'US', lat: @latlng.lat, lng: @latlng.lng})
20
19
  @success.success = true
21
20
  end
22
21
 
23
22
  def test_timeout_call_web_service
24
- url = "http://www.anything.com"
25
- Geokit::Geocoders::request_timeout = 1
23
+ url = 'http://www.anything.com'
24
+ Geokit::Geocoders.request_timeout = 1
26
25
  assert_nil Geokit::Geocoders::TestGeocoder.call_geocoder_service(url)
27
26
  end
28
27
 
29
28
  def test_successful_call_web_service
30
- url = "http://www.anything.com"
31
- Geokit::Geocoders::Geocoder.expects(:do_get).with(url).returns("SUCCESS")
32
- assert_equal "SUCCESS", Geokit::Geocoders::Geocoder.call_geocoder_service(url)
29
+ url = 'http://www.anything.com'
30
+ Geokit::Geocoders::Geocoder.expects(:do_get).with(url).returns('SUCCESS')
31
+ assert_equal 'SUCCESS', Geokit::Geocoders::Geocoder.call_geocoder_service(url)
33
32
  end
34
33
  end
@@ -3,7 +3,6 @@ require File.join(File.dirname(__FILE__), 'helper')
3
3
  Geokit::Geocoders::BingGeocoder.key = 'AuWcmtBIoPeOubm9BtcN44hTmWw_wNoJ5NEO2L0RaKrGAUE_nlwciKAqwapdq7k7'
4
4
 
5
5
  class BingGeocoderTest < BaseGeocoderTest #:nodoc: all
6
-
7
6
  def setup
8
7
  super
9
8
  end
@@ -15,15 +14,15 @@ class BingGeocoderTest < BaseGeocoderTest #:nodoc: all
15
14
  # the testing methods themselves
16
15
  def test_bing_full_address
17
16
  VCR.use_cassette('bing_full') do
18
- key = Geokit::Geocoders::BingGeocoder.key
17
+ key = Geokit::Geocoders::BingGeocoder.key
19
18
  url = "https://dev.virtualearth.net/REST/v1/Locations/#{URI.escape(@full_address)}?key=#{key}&o=xml"
20
19
  res = Geokit::Geocoders::BingGeocoder.geocode(@full_address)
21
- assert_equal "CA", res.state
22
- assert_equal "San Francisco", res.city
20
+ assert_equal 'CA', res.state
21
+ assert_equal 'San Francisco', res.city
23
22
  assert_array_in_delta [37.792332, -122.393791], res.to_a
24
23
  assert res.country == 'United States'
25
- assert_equal "100 Spear St, San Francisco, CA 94105", res.full_address
26
- assert_equal "bing", res.provider
24
+ assert_equal '100 Spear St, San Francisco, CA 94105', res.full_address
25
+ assert_equal 'bing', res.provider
27
26
  assert_url url
28
27
  end
29
28
  end
@@ -31,32 +30,32 @@ class BingGeocoderTest < BaseGeocoderTest #:nodoc: all
31
30
  def test_bing_full_address_au
32
31
  address = '440 King William Street, Adelaide, Australia'
33
32
  VCR.use_cassette('bing_full_au') do
34
- key = Geokit::Geocoders::BingGeocoder.key
33
+ key = Geokit::Geocoders::BingGeocoder.key
35
34
  url = "https://dev.virtualearth.net/REST/v1/Locations/#{URI.escape(address)}?key=#{key}&o=xml"
36
35
  res = Geokit::Geocoders::BingGeocoder.geocode(address)
37
- assert_equal "SA", res.state
38
- assert_equal "Adelaide", res.city
36
+ assert_equal 'SA', res.state
37
+ assert_equal 'Adelaide', res.city
39
38
  assert_array_in_delta [-34.934582, 138.600784], res.to_a
40
39
  assert res.country == 'Australia'
41
- assert_equal "402-440 King William St, Adelaide, SA 5000", res.full_address
42
- assert_equal "Australia", res.country
43
- assert_equal "bing", res.provider
40
+ assert_equal '402-440 King William St, Adelaide, SA 5000', res.full_address
41
+ assert_equal 'Australia', res.country
42
+ assert_equal 'bing', res.provider
44
43
  assert_url url
45
44
  end
46
45
  end
47
46
 
48
47
  def test_bing_full_address_de
49
- address = "Platz der Republik 1, 11011 Berlin, Germany"
48
+ address = 'Platz der Republik 1, 11011 Berlin, Germany'
50
49
  VCR.use_cassette('bing_full_de') do
51
- key = Geokit::Geocoders::BingGeocoder.key
50
+ key = Geokit::Geocoders::BingGeocoder.key
52
51
  url = "https://dev.virtualearth.net/REST/v1/Locations/#{URI.escape(address)}?key=#{key}&o=xml"
53
52
  res = Geokit::Geocoders::BingGeocoder.geocode(address)
54
- assert_equal "BE", res.state
55
- assert_equal "Berlin", res.city
53
+ assert_equal 'BE', res.state
54
+ assert_equal 'Berlin', res.city
56
55
  assert_array_in_delta [52.518596, 13.375502], res.to_a
57
56
  assert res.country == 'Germany'
58
- assert_equal "Platz der Republik 1, 10557 Berlin", res.full_address
59
- assert_equal "bing", res.provider
57
+ assert_equal 'Platz der Republik 1, 10557 Berlin', res.full_address
58
+ assert_equal 'bing', res.provider
60
59
  assert_equal 'address', res.precision
61
60
  assert_equal 8, res.accuracy
62
61
  assert_url url
@@ -64,9 +63,9 @@ class BingGeocoderTest < BaseGeocoderTest #:nodoc: all
64
63
  end
65
64
 
66
65
  def test_bing_country
67
- address = "Australia"
66
+ address = 'Australia'
68
67
  VCR.use_cassette('bing_au') do
69
- key = Geokit::Geocoders::BingGeocoder.key
68
+ key = Geokit::Geocoders::BingGeocoder.key
70
69
  url = "https://dev.virtualearth.net/REST/v1/Locations/#{URI.escape(address)}?key=#{key}&o=xml"
71
70
  res = Geokit::Geocoders::BingGeocoder.geocode(address)
72
71
  assert_equal nil, res.state
@@ -74,7 +73,7 @@ class BingGeocoderTest < BaseGeocoderTest #:nodoc: all
74
73
  assert_array_in_delta [-25.585, 134.504], res.to_a
75
74
  assert res.country == 'Australia'
76
75
  assert_equal 'Australia', res.full_address
77
- assert_equal "bing", res.provider
76
+ assert_equal 'bing', res.provider
78
77
  assert_equal 'country', res.precision
79
78
  assert_equal 8, res.accuracy
80
79
  assert_url url
@@ -1,37 +1,35 @@
1
1
  require File.join(File.dirname(__FILE__), 'helper')
2
2
 
3
3
  class BoundsTest < Test::Unit::TestCase #:nodoc: all
4
-
5
4
  def setup
6
5
  # This is the area in Texas
7
- @sw = Geokit::LatLng.new(32.91663,-96.982841)
8
- @ne = Geokit::LatLng.new(32.96302,-96.919495)
9
- @bounds=Geokit::Bounds.new(@sw,@ne)
10
- @loc_a=Geokit::LatLng.new(32.918593,-96.958444) # inside bounds
11
- @loc_b=Geokit::LatLng.new(32.914144,-96.958444) # outside bouds
6
+ @sw = Geokit::LatLng.new(32.91663, -96.982841)
7
+ @ne = Geokit::LatLng.new(32.96302, -96.919495)
8
+ @bounds = Geokit::Bounds.new(@sw, @ne)
9
+ @loc_a = Geokit::LatLng.new(32.918593, -96.958444) # inside bounds
10
+ @loc_b = Geokit::LatLng.new(32.914144, -96.958444) # outside bouds
12
11
 
13
12
  # this is a cross-meridan area
14
- @cross_meridian=Geokit::Bounds.normalize([30,170],[40,-170])
15
- @inside_cm=Geokit::LatLng.new(35,175)
16
- @inside_cm_2=Geokit::LatLng.new(35,-175)
17
- @east_of_cm=Geokit::LatLng.new(35,-165)
18
- @west_of_cm=Geokit::LatLng.new(35,165)
19
-
13
+ @cross_meridian = Geokit::Bounds.normalize([30, 170], [40, -170])
14
+ @inside_cm = Geokit::LatLng.new(35, 175)
15
+ @inside_cm_2 = Geokit::LatLng.new(35, -175)
16
+ @east_of_cm = Geokit::LatLng.new(35, -165)
17
+ @west_of_cm = Geokit::LatLng.new(35, 165)
20
18
  end
21
19
 
22
20
  def test_equality
23
- assert_equal Geokit::Bounds.new(@sw,@ne), Geokit::Bounds.new(@sw,@ne)
21
+ assert_equal Geokit::Bounds.new(@sw, @ne), Geokit::Bounds.new(@sw, @ne)
24
22
  end
25
23
 
26
24
  def test_normalize
27
- res=Geokit::Bounds.normalize(@sw,@ne)
28
- assert_equal res,Geokit::Bounds.new(@sw,@ne)
29
- res=Geokit::Bounds.normalize([@sw,@ne])
30
- assert_equal res,Geokit::Bounds.new(@sw,@ne)
31
- res=Geokit::Bounds.normalize([@sw.lat,@sw.lng],[@ne.lat,@ne.lng])
32
- assert_equal res,Geokit::Bounds.new(@sw,@ne)
33
- res=Geokit::Bounds.normalize([[@sw.lat,@sw.lng],[@ne.lat,@ne.lng]])
34
- assert_equal res,Geokit::Bounds.new(@sw,@ne)
25
+ res = Geokit::Bounds.normalize(@sw, @ne)
26
+ assert_equal res, Geokit::Bounds.new(@sw, @ne)
27
+ res = Geokit::Bounds.normalize([@sw, @ne])
28
+ assert_equal res, Geokit::Bounds.new(@sw, @ne)
29
+ res = Geokit::Bounds.normalize([@sw.lat, @sw.lng], [@ne.lat, @ne.lng])
30
+ assert_equal res, Geokit::Bounds.new(@sw, @ne)
31
+ res = Geokit::Bounds.normalize([[@sw.lat, @sw.lng], [@ne.lat, @ne.lng]])
32
+ assert_equal res, Geokit::Bounds.new(@sw, @ne)
35
33
  end
36
34
 
37
35
  def test_point_inside_bounds
@@ -53,19 +51,19 @@ class BoundsTest < Test::Unit::TestCase #:nodoc: all
53
51
  end
54
52
 
55
53
  def test_center
56
- assert_in_delta 32.939828,@bounds.center.lat,0.00005
57
- assert_in_delta(-96.9511763,@bounds.center.lng,0.00005)
54
+ assert_in_delta 32.939828, @bounds.center.lat, 0.00005
55
+ assert_in_delta(-96.9511763, @bounds.center.lng, 0.00005)
58
56
  end
59
57
 
60
58
  def test_center_cross_meridian
61
- assert_in_delta 35.41160, @cross_meridian.center.lat,0.00005
62
- assert_in_delta 179.38112, @cross_meridian.center.lng,0.00005
59
+ assert_in_delta 35.41160, @cross_meridian.center.lat, 0.00005
60
+ assert_in_delta 179.38112, @cross_meridian.center.lng, 0.00005
63
61
  end
64
62
 
65
63
  def test_creation_from_circle
66
- bounds=Geokit::Bounds.from_point_and_radius([32.939829, -96.951176],2.5)
67
- inside=Geokit::LatLng.new 32.9695270000,-96.9901590000
68
- outside=Geokit::LatLng.new 32.8951550000,-96.9584440000
64
+ bounds = Geokit::Bounds.from_point_and_radius([32.939829, -96.951176], 2.5)
65
+ inside = Geokit::LatLng.new 32.9695270000, -96.9901590000
66
+ outside = Geokit::LatLng.new 32.8951550000, -96.9584440000
69
67
  assert bounds.contains?(inside)
70
68
  assert !bounds.contains?(outside)
71
69
  end
@@ -1,31 +1,30 @@
1
1
  require File.join(File.dirname(__FILE__), 'helper')
2
2
 
3
- Geokit::Geocoders::CaGeocoder::key = "SOMEKEYVALUE"
3
+ Geokit::Geocoders::CaGeocoder.key = 'SOMEKEYVALUE'
4
4
 
5
5
  class CaGeocoderTest < BaseGeocoderTest #:nodoc: all
6
-
7
- CA_SUCCESS=<<-EOF
6
+ CA_SUCCESS = <<-EOF
8
7
  <?xml version="1.0" encoding="UTF-8" ?>
9
8
  <geodata><latt>49.243086</latt><longt>-123.153684</longt></geodata>
10
9
  EOF
11
10
 
12
11
  def setup
13
- @ca_full_hash = {:street_address=>"2105 West 32nd Avenue",:city=>"Vancouver", :state=>"BC"}
12
+ @ca_full_hash = {street_address: '2105 West 32nd Avenue', city: 'Vancouver', state: 'BC'}
14
13
  @ca_full_loc = Geokit::GeoLoc.new(@ca_full_hash)
15
14
  end
16
15
 
17
16
  def test_geocoder_with_geo_loc_with_account
18
17
  response = MockSuccess.new
19
18
  response.expects(:body).returns(CA_SUCCESS)
20
- url = "http://geocoder.ca/?stno=2105&addresst=West+32nd+Avenue&city=Vancouver&prov=BC&auth=SOMEKEYVALUE&geoit=xml"
19
+ url = 'http://geocoder.ca/?stno=2105&addresst=West+32nd+Avenue&city=Vancouver&prov=BC&auth=SOMEKEYVALUE&geoit=xml'
21
20
  Geokit::Geocoders::CaGeocoder.expects(:call_geocoder_service).with(url).returns(response)
22
21
  verify(Geokit::Geocoders::CaGeocoder.geocode(@ca_full_loc))
23
22
  end
24
23
 
25
24
  def test_service_unavailable
26
25
  response = MockFailure.new
27
- #Net::HTTP.expects(:get_response).with(URI.parse("http://geocoder.ca/?stno=2105&addresst=West+32nd+Avenue&city=Vancouver&prov=BC&auth=SOMEKEYVALUE&geoit=xml")).returns(response)
28
- url = "http://geocoder.ca/?stno=2105&addresst=West+32nd+Avenue&city=Vancouver&prov=BC&auth=SOMEKEYVALUE&geoit=xml"
26
+ # Net::HTTP.expects(:get_response).with(URI.parse("http://geocoder.ca/?stno=2105&addresst=West+32nd+Avenue&city=Vancouver&prov=BC&auth=SOMEKEYVALUE&geoit=xml")).returns(response)
27
+ url = 'http://geocoder.ca/?stno=2105&addresst=West+32nd+Avenue&city=Vancouver&prov=BC&auth=SOMEKEYVALUE&geoit=xml'
29
28
  Geokit::Geocoders::CaGeocoder.expects(:call_geocoder_service).with(url).returns(response)
30
29
  assert !Geokit::Geocoders::CaGeocoder.geocode(@ca_full_loc).success
31
30
  end
@@ -33,9 +32,9 @@ class CaGeocoderTest < BaseGeocoderTest #:nodoc: all
33
32
  private
34
33
 
35
34
  def verify(location)
36
- assert_equal "BC", location.state
37
- assert_equal "Vancouver", location.city
38
- assert_equal "49.243086,-123.153684", location.ll
35
+ assert_equal 'BC', location.state
36
+ assert_equal 'Vancouver', location.city
37
+ assert_equal '49.243086,-123.153684', location.ll
39
38
  assert !location.is_us?
40
39
  end
41
40
  end
@@ -12,7 +12,7 @@ class FCCGeocoderTest < BaseGeocoderTest #:nodoc: all
12
12
 
13
13
  def test_fcc_reverse_geocode
14
14
  VCR.use_cassette('fcc_reverse_geocode') do
15
- url = "https://data.fcc.gov/api/block/find?format=json&latitude=34.05&longitude=-118.25"
15
+ url = 'https://data.fcc.gov/api/block/find?format=json&latitude=34.05&longitude=-118.25'
16
16
  res = Geokit::Geocoders::FCCGeocoder.reverse_geocode(@la)
17
17
  assert_url url
18
18
  assert_equal res.country_code, 'US'
@@ -12,7 +12,7 @@ class FreeGeoIpGeocoderTest < BaseGeocoderTest #:nodoc: all
12
12
 
13
13
  def test_free_geo_ip_geocode
14
14
  VCR.use_cassette('free_geo_ip_geocode') do
15
- url = "http://freegeoip.net/xml/#{@ip}"
15
+ url = "http://freegeoip.net/xml/#{@ip}"
16
16
  res = Geokit::Geocoders::FreeGeoIpGeocoder.geocode(@ip)
17
17
  assert_url url
18
18
  assert_equal res.city, 'Mountain View'
@@ -1,7 +1,7 @@
1
1
  require File.join(File.dirname(__FILE__), 'helper')
2
2
 
3
3
  class GeoPluginGeocoderTest < BaseGeocoderTest #:nodoc: all
4
- IP_SUCCESS=<<-EOF
4
+ IP_SUCCESS = <<-EOF
5
5
  <?xml version="1.0" encoding="UTF-8"?>
6
6
  <geoPlugin>
7
7
  <geoplugin_city>Belo Horizonte</geoplugin_city>
@@ -22,7 +22,7 @@ class GeoPluginGeocoderTest < BaseGeocoderTest #:nodoc: all
22
22
  def setup
23
23
  super
24
24
  @ip = '74.125.237.209'
25
- @success.provider = "geo_plugin"
25
+ @success.provider = 'geo_plugin'
26
26
  end
27
27
 
28
28
  def assert_url(expected_url)
@@ -31,7 +31,7 @@ class GeoPluginGeocoderTest < BaseGeocoderTest #:nodoc: all
31
31
 
32
32
  def test_geo_plugin_geocode
33
33
  VCR.use_cassette('geo_plugin_geocode') do
34
- url = "http://www.geoplugin.net/xml.gp?ip=#{@ip}"
34
+ url = "http://www.geoplugin.net/xml.gp?ip=#{@ip}"
35
35
  res = Geokit::Geocoders::GeoPluginGeocoder.geocode(@ip)
36
36
  assert_url url
37
37
  assert_equal res.city, 'Mountain View'
@@ -49,15 +49,15 @@ class GeoPluginGeocoderTest < BaseGeocoderTest #:nodoc: all
49
49
  assert_not_nil location
50
50
  assert_equal(-19.916700, location.lat)
51
51
  assert_equal(-43.933300, location.lng)
52
- assert_equal "Belo Horizonte", location.city
53
- assert_equal "Minas Gerais", location.state
54
- assert_equal "BR", location.country_code
55
- assert_equal "geo_plugin", location.provider
52
+ assert_equal 'Belo Horizonte', location.city
53
+ assert_equal 'Minas Gerais', location.state
54
+ assert_equal 'BR', location.country_code
55
+ assert_equal 'geo_plugin', location.provider
56
56
  assert location.success?
57
57
  end
58
58
 
59
59
  def test_invalid_ip
60
- location = Geokit::Geocoders::GeoPluginGeocoder.geocode("pixrum")
60
+ location = Geokit::Geocoders::GeoPluginGeocoder.geocode('pixrum')
61
61
  assert_not_nil location
62
62
  assert !location.success?
63
63
  end
@@ -66,7 +66,7 @@ class GeoPluginGeocoderTest < BaseGeocoderTest #:nodoc: all
66
66
  failure = MockFailure.new
67
67
  url = 'http://www.geoplugin.net/xml.gp?ip=69.10.10.10'
68
68
  Geokit::Geocoders::GeoPluginGeocoder.expects(:call_geocoder_service).with(url).returns(failure)
69
- location = Geokit::Geocoders::GeoPluginGeocoder.geocode("69.10.10.10")
69
+ location = Geokit::Geocoders::GeoPluginGeocoder.geocode('69.10.10.10')
70
70
  assert_not_nil location
71
71
  assert !location.success?
72
72
  end
@@ -1,7 +1,6 @@
1
1
  require File.join(File.dirname(__FILE__), 'helper')
2
2
 
3
3
  class GeoLocTest < Test::Unit::TestCase #:nodoc: all
4
-
5
4
  def setup
6
5
  @loc = Geokit::GeoLoc.new
7
6
  end
@@ -31,7 +30,7 @@ class GeoLocTest < Test::Unit::TestCase #:nodoc: all
31
30
  end
32
31
 
33
32
  def test_city
34
- @loc.city = "san francisco"
33
+ @loc.city = 'san francisco'
35
34
  assert_equal 'San Francisco', @loc.city
36
35
  end
37
36
 
@@ -60,11 +59,11 @@ class GeoLocTest < Test::Unit::TestCase #:nodoc: all
60
59
 
61
60
  def test_to_yaml
62
61
  @loc.city = 'San Francisco'
63
- @loc.state = 'CA'
62
+ @loc.state_code = 'CA'
64
63
  @loc.zip = '94105'
65
64
  @loc.country_code = 'US'
66
65
 
67
- yaml = YAML::parse(@loc.to_yaml)
66
+ yaml = YAML.parse(@loc.to_yaml)
68
67
  case yaml.class.to_s
69
68
  when 'YAML::Syck::Map', 'Syck::Map'
70
69
  tag = yaml.type_id
@@ -85,7 +84,9 @@ class GeoLocTest < Test::Unit::TestCase #:nodoc: all
85
84
  'lng', '',
86
85
  'precision', 'unknown',
87
86
  'province', '',
88
- 'state', 'CA',
87
+ 'state', '',
88
+ 'state_code', 'CA',
89
+ 'state_name', '',
89
90
  'street_address', '',
90
91
  'street_name', '',
91
92
  'street_number', '',
@@ -96,7 +97,7 @@ class GeoLocTest < Test::Unit::TestCase #:nodoc: all
96
97
  end
97
98
 
98
99
  def test_neighborhood
99
- @loc.neighborhood = "SoMa"
100
+ @loc.neighborhood = 'SoMa'
100
101
  assert_equal @loc.neighborhood, 'SoMa'
101
102
  end
102
103
  end