geocoder 1.1.6 → 1.1.7

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of geocoder might be problematic. Click here for more details.

Files changed (48) hide show
  1. data/CHANGELOG.md +15 -1
  2. data/README.md +82 -2
  3. data/examples/autoexpire_cache_dalli.rb +62 -0
  4. data/examples/{autoexpire_cache.rb → autoexpire_cache_redis.rb} +4 -4
  5. data/lib/generators/geocoder/config/templates/initializer.rb +1 -1
  6. data/lib/geocoder.rb +1 -1
  7. data/lib/geocoder/cache.rb +4 -0
  8. data/lib/geocoder/calculations.rb +33 -1
  9. data/lib/geocoder/lookup.rb +2 -0
  10. data/lib/geocoder/lookups/base.rb +10 -10
  11. data/lib/geocoder/lookups/esri.rb +52 -0
  12. data/lib/geocoder/lookups/mapquest.rb +1 -1
  13. data/lib/geocoder/lookups/maxmind.rb +19 -3
  14. data/lib/geocoder/lookups/ovi.rb +52 -0
  15. data/lib/geocoder/lookups/test.rb +6 -0
  16. data/lib/geocoder/lookups/yahoo.rb +4 -2
  17. data/lib/geocoder/query.rb +4 -4
  18. data/lib/geocoder/request.rb +1 -1
  19. data/lib/geocoder/results/esri.rb +51 -0
  20. data/lib/geocoder/results/google.rb +28 -0
  21. data/lib/geocoder/results/mapquest.rb +1 -1
  22. data/lib/geocoder/results/maxmind.rb +4 -5
  23. data/lib/geocoder/results/ovi.rb +62 -0
  24. data/lib/geocoder/results/test.rb +2 -1
  25. data/lib/geocoder/results/yandex.rb +12 -2
  26. data/lib/geocoder/stores/active_record.rb +38 -16
  27. data/lib/geocoder/stores/mongo_base.rb +2 -1
  28. data/lib/geocoder/version.rb +1 -1
  29. data/test/calculations_test.rb +6 -0
  30. data/test/fixtures/esri_madison_square_garden +59 -0
  31. data/test/fixtures/esri_no_results +8 -0
  32. data/test/fixtures/esri_reverse +21 -0
  33. data/test/fixtures/maxmind_24_24_24_21 +1 -1
  34. data/test/fixtures/maxmind_24_24_24_22 +1 -1
  35. data/test/fixtures/maxmind_24_24_24_23 +1 -1
  36. data/test/fixtures/maxmind_24_24_24_24 +1 -1
  37. data/test/fixtures/ovi_madison_square_garden +72 -0
  38. data/test/fixtures/ovi_no_results +8 -0
  39. data/test/fixtures/yandex_no_city_and_town +112 -0
  40. data/test/lookup_test.rb +1 -0
  41. data/test/near_test.rb +32 -0
  42. data/test/query_test.rb +5 -0
  43. data/test/request_test.rb +29 -0
  44. data/test/result_test.rb +9 -0
  45. data/test/services_test.rb +59 -5
  46. data/test/test_helper.rb +1 -1
  47. data/test/test_mode_test.rb +32 -23
  48. metadata +15 -3
@@ -24,7 +24,8 @@ module Geocoder::Store
24
24
 
25
25
  # Use BSON::OrderedHash if Ruby's hashes are unordered.
26
26
  # Conditions must be in order required by indexes (see mongo gem).
27
- empty = RUBY_VERSION.split('.')[1].to_i < 9 ? BSON::OrderedHash.new : {}
27
+ version = RUBY_VERSION.split('.').map { |i| i.to_i }
28
+ empty = version[0] < 2 && version[1] < 9 ? BSON::OrderedHash.new : {}
28
29
 
29
30
  conds = empty.clone
30
31
  field = geocoder_options[:coordinates]
@@ -1,3 +1,3 @@
1
1
  module Geocoder
2
- VERSION = "1.1.6"
2
+ VERSION = "1.1.7"
3
3
  end
@@ -38,6 +38,12 @@ class CalculationsTest < Test::Unit::TestCase
38
38
  assert (la_to_ny - 3942).abs < 10
39
39
  end
40
40
 
41
+ def test_distance_between_in_nautical_miles
42
+ assert_equal 60, Geocoder::Calculations.distance_between([0,0], [0,1], :units => :nm).round
43
+ la_to_ny = Geocoder::Calculations.distance_between([34.05,-118.25], [40.72,-74], :units => :nm).round
44
+ assert (la_to_ny - 2124).abs < 10
45
+ end
46
+
41
47
 
42
48
  # --- geographic center ---
43
49
 
@@ -0,0 +1,59 @@
1
+ {
2
+ "spatialReference": {
3
+ "wkid": 4326,
4
+ "latestWkid": 4326
5
+ },
6
+ "locations": [
7
+ {
8
+ "name": "Madison Square Garden",
9
+ "extent": {
10
+ "xmin": -74.000241000000003,
11
+ "ymin": 40.744050000000001,
12
+ "xmax": -73.988241000000002,
13
+ "ymax": 40.756050000000002
14
+ },
15
+ "feature": {
16
+ "geometry": {
17
+ "x": -73.994238897999651,
18
+ "y": 40.750049813000487
19
+ },
20
+ "attributes": {
21
+ "Loc_name": "Gaz.WorldGazetteer.POI2",
22
+ "Score": 100,
23
+ "Match_addr": "Madison Square Garden",
24
+ "Addr_type": "POI",
25
+ "Type": "Sports Complex",
26
+ "PlaceName": "Madison Square Garden",
27
+ "Rank": "18",
28
+ "AddBldg": "",
29
+ "AddNum": "",
30
+ "AddNumFrom": "",
31
+ "AddNumTo": "",
32
+ "Side": "",
33
+ "StPreDir": "",
34
+ "StPreType": "",
35
+ "StName": "",
36
+ "StType": "",
37
+ "StDir": "",
38
+ "Nbrhd": "",
39
+ "City": "New York",
40
+ "Subregion": "New York",
41
+ "Region": "New York",
42
+ "Postal": "10001",
43
+ "PostalExt": "",
44
+ "Country": "USA",
45
+ "LangCode": "",
46
+ "Distance": 0,
47
+ "X": -73.994240000000005,
48
+ "Y": 40.750050000000002,
49
+ "DisplayX": -73.994240000000005,
50
+ "DisplayY": 40.750050000000002,
51
+ "Xmin": -74.000241000000003,
52
+ "Xmax": -73.988241000000002,
53
+ "Ymin": 40.744050000000001,
54
+ "Ymax": 40.756050000000002
55
+ }
56
+ }
57
+ }
58
+ ]
59
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "spatialReference": {
3
+ "wkid": 4326,
4
+ "latestWkid": 4326
5
+ },
6
+ "locations": [
7
+ ]
8
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "address": {
3
+ "Address": "4 Avenue Gustave Eiffel",
4
+ "Neighborhood": "7e Arrondissement",
5
+ "City": "Paris",
6
+ "Subregion": "Paris",
7
+ "Region": "Île-de-France",
8
+ "Postal": "75007",
9
+ "PostalExt": null,
10
+ "CountryCode": "FRA",
11
+ "Loc_name": "FRA.PointAddress"
12
+ },
13
+ "location": {
14
+ "x": 2.2956200048981574,
15
+ "y": 48.858129997357558,
16
+ "spatialReference": {
17
+ "wkid": 4326,
18
+ "latestWkid": 4326
19
+ }
20
+ }
21
+ }
@@ -1 +1 @@
1
- US,
1
+ US
@@ -1 +1 @@
1
- US,NY,Jamaica,40.6915,-73.8057,
1
+ US,NY,Jamaica,40.6915,-73.8057
@@ -1 +1 @@
1
- US,NY,Jamaica,,40.6915,-73.8057,501,718,"Road Runner","Road Runner",
1
+ US,NY,Jamaica,,40.6915,-73.8057,501,718,"Road Runner","Road Runner"
@@ -1 +1 @@
1
- US,"United States",NY,"New York",Jamaica,40.6915,-73.8057,501,718,America/New_York,NA,,"Road Runner","Road Runner",rr.com,"AS11351 Road Runner HoldCo LLC",Cable/DSL,residential,779,99,37,76,,
1
+ US,"United States",NY,"New York",Jamaica,40.6915,-73.8057,501,718,America/New_York,NA,,"Road Runner","Road Runner",rr.com,"AS11351 Road Runner HoldCo LLC",Cable/DSL,residential,779,99,37,76,35
@@ -0,0 +1,72 @@
1
+ {
2
+ "Response": {
3
+ "MetaInfo": {
4
+ "Timestamp": "2013-02-08T16:26:39.382+0000"
5
+ },
6
+ "View": [
7
+ {
8
+ "_type": "SearchResultsViewType",
9
+ "ViewId": 0,
10
+ "Result": [
11
+ {
12
+ "Relevance": 1.0,
13
+ "MatchLevel": "houseNumber",
14
+ "MatchQuality": {
15
+ "State": 1.0,
16
+ "City": 1.0,
17
+ "Street": [
18
+ 1.0
19
+ ],
20
+ "HouseNumber": 1.0
21
+ },
22
+ "MatchType": "pointAddress",
23
+ "Location": {
24
+ "LocationId": "NT_ArsGdYbpo6dqjPQel9gTID_4",
25
+ "LocationType": "point",
26
+ "DisplayPosition": {
27
+ "Latitude": 40.7504692,
28
+ "Longitude": -73.9933777
29
+ },
30
+ "NavigationPosition": [
31
+ {
32
+ "Latitude": 40.7500305,
33
+ "Longitude": -73.9942398
34
+ }
35
+ ],
36
+ "MapView": {
37
+ "TopLeft": {
38
+ "Latitude": 40.7515934,
39
+ "Longitude": -73.9948616
40
+ },
41
+ "BottomRight": {
42
+ "Latitude": 40.7493451,
43
+ "Longitude": -73.9918938
44
+ }
45
+ },
46
+ "Address": {
47
+ "Label": "4 Penn Plz, New York, NY 10001, United States",
48
+ "Country": "USA",
49
+ "State": "NY",
50
+ "County": "New York",
51
+ "City": "New York",
52
+ "Street": "Penn Plz",
53
+ "HouseNumber": "4",
54
+ "PostalCode": "10001",
55
+ "AdditionalData": [
56
+ {
57
+ "value": "United States",
58
+ "key": "CountryName"
59
+ },
60
+ {
61
+ "value": "New York",
62
+ "key": "StateName"
63
+ }
64
+ ]
65
+ }
66
+ }
67
+ }
68
+ ]
69
+ }
70
+ ]
71
+ }
72
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "Response": {
3
+ "MetaInfo": {
4
+ "Timestamp": "2013-02-08T16:41:16.723+0000"
5
+ },
6
+ "View": []
7
+ }
8
+ }
@@ -0,0 +1,112 @@
1
+ {
2
+ "response":{
3
+ "GeoObjectCollection":{
4
+ "metaDataProperty":{
5
+ "GeocoderResponseMetaData":{
6
+ "request":"57.423359,55.892596",
7
+ "found":"3",
8
+ "results":"10",
9
+ "Point":{
10
+ "pos":"57.423359 55.892596"
11
+ }
12
+ }
13
+ },
14
+ "featureMember":[
15
+ {
16
+ "GeoObject":{
17
+ "metaDataProperty":{
18
+ "GeocoderMetaData":{
19
+ "kind":"area",
20
+ "text":"Россия, республика Башкортостан, Караидельский район",
21
+ "precision":"other",
22
+ "AddressDetails":{
23
+ "Country":{
24
+ "AddressLine":"республика Башкортостан, Караидельский район",
25
+ "CountryNameCode":"RU",
26
+ "CountryName":"Россия",
27
+ "AdministrativeArea":{
28
+ "AdministrativeAreaName":"республика Башкортостан",
29
+ "SubAdministrativeArea":{
30
+ "SubAdministrativeAreaName":"Караидельский район"
31
+ }
32
+ }
33
+ }
34
+ }
35
+ }
36
+ },
37
+ "description":"республика Башкортостан, Россия",
38
+ "name":"Караидельский район",
39
+ "boundedBy":{
40
+ "Envelope":{
41
+ "lowerCorner":"56.231384 55.462814",
42
+ "upperCorner":"57.705348 56.076117"
43
+ }
44
+ },
45
+ "Point":{
46
+ "pos":"57.423359 55.892596"
47
+ }
48
+ }
49
+ },
50
+ {
51
+ "GeoObject":{
52
+ "metaDataProperty":{
53
+ "GeocoderMetaData":{
54
+ "kind":"province",
55
+ "text":"Россия, республика Башкортостан",
56
+ "precision":"other",
57
+ "AddressDetails":{
58
+ "Country":{
59
+ "AddressLine":"республика Башкортостан",
60
+ "CountryNameCode":"RU",
61
+ "CountryName":"Россия",
62
+ "AdministrativeArea":{
63
+ "AdministrativeAreaName":"республика Башкортостан"
64
+ }
65
+ }
66
+ }
67
+ }
68
+ },
69
+ "description":"Россия",
70
+ "name":"республика Башкортостан",
71
+ "boundedBy":{
72
+ "Envelope":{
73
+ "lowerCorner":"53.157475 51.571991",
74
+ "upperCorner":"60.001577 56.533651"
75
+ }
76
+ },
77
+ "Point":{
78
+ "pos":"56.579526 54.127354"
79
+ }
80
+ }
81
+ },
82
+ {
83
+ "GeoObject":{
84
+ "metaDataProperty":{
85
+ "GeocoderMetaData":{
86
+ "kind":"country",
87
+ "text":"Россия",
88
+ "precision":"other",
89
+ "AddressDetails":{
90
+ "Country":{
91
+ "CountryNameCode":"RU",
92
+ "CountryName":"Россия"
93
+ }
94
+ }
95
+ }
96
+ },
97
+ "name":"Россия",
98
+ "boundedBy":{
99
+ "Envelope":{
100
+ "lowerCorner":"19.641673 36.84312",
101
+ "upperCorner":"179.999997 81.848739"
102
+ }
103
+ },
104
+ "Point":{
105
+ "pos":"37.617761 55.755773"
106
+ }
107
+ }
108
+ }
109
+ ]
110
+ }
111
+ }
112
+ }
data/test/lookup_test.rb CHANGED
@@ -34,6 +34,7 @@ class LookupTest < Test::Unit::TestCase
34
34
  end
35
35
 
36
36
  {
37
+ :esri => :l,
37
38
  :bing => :key,
38
39
  :geocoder_ca => :auth,
39
40
  :google => :language,
data/test/near_test.rb CHANGED
@@ -8,4 +8,36 @@ class NearTest < Test::Unit::TestCase
8
8
  assert_match /test_table_name.latitude BETWEEN 0.9276\d* AND 1.0723\d* AND test_table_name.longitude BETWEEN 1.9276\d* AND 2.0723\d* AND /,
9
9
  result[:conditions][0]
10
10
  end
11
+
12
+ def test_near_scope_options_with_defaults
13
+ result = Event.send(:near_scope_options, 1.0, 2.0, 5)
14
+
15
+ assert_match /AS distance/, result[:select]
16
+ assert_match /AS bearing/, result[:select]
17
+ assert_no_consecutive_comma(result[:select])
18
+ end
19
+
20
+ def test_near_scope_options_with_no_distance
21
+ result = Event.send(:near_scope_options, 1.0, 2.0, 5, :select_distance => false)
22
+
23
+ assert_no_match /AS distance/, result[:select]
24
+ assert_match /AS bearing/, result[:select]
25
+ assert_no_match /distance/, result[:condition]
26
+ assert_no_match /distance/, result[:order]
27
+ assert_no_consecutive_comma(result[:select])
28
+ end
29
+
30
+ def test_near_scope_options_with_no_bearing
31
+ result = Event.send(:near_scope_options, 1.0, 2.0, 5, :select_bearing => false)
32
+
33
+ assert_match /AS distance/, result[:select]
34
+ assert_no_match /AS bearing/, result[:select]
35
+ assert_no_consecutive_comma(result[:select])
36
+ end
37
+
38
+ private
39
+
40
+ def assert_no_consecutive_comma(string)
41
+ assert_no_match /, *,/, string, "two consecutive commas"
42
+ end
11
43
  end
data/test/query_test.rb CHANGED
@@ -10,6 +10,7 @@ class QueryTest < Test::Unit::TestCase
10
10
  assert !Geocoder::Query.new("232.65.123.94.43").ip_address?
11
11
  assert !Geocoder::Query.new("232.65.123").ip_address?
12
12
  assert !Geocoder::Query.new("::ffff:123.456.789").ip_address?
13
+ assert !Geocoder::Query.new("Test\n232.65.123.94").ip_address?
13
14
  end
14
15
 
15
16
  def test_blank_query_detection
@@ -18,6 +19,7 @@ class QueryTest < Test::Unit::TestCase
18
19
  assert Geocoder::Query.new("\t ").blank?
19
20
  assert !Geocoder::Query.new("a").blank?
20
21
  assert !Geocoder::Query.new("Москва").blank? # no ASCII characters
22
+ assert !Geocoder::Query.new("\na").blank?
21
23
 
22
24
  assert Geocoder::Query.new(nil, :params => {}).blank?
23
25
  assert !Geocoder::Query.new(nil, :params => {:woeid => 1234567}).blank?
@@ -32,11 +34,14 @@ class QueryTest < Test::Unit::TestCase
32
34
  assert Geocoder::Query.new("51.178844,5").coordinates?
33
35
  assert Geocoder::Query.new("51.178844, -1.826189").coordinates?
34
36
  assert !Geocoder::Query.new("232.65.123").coordinates?
37
+ assert !Geocoder::Query.new("Test\n51.178844, -1.826189").coordinates?
35
38
  end
36
39
 
37
40
  def test_loopback_ip_address
38
41
  assert Geocoder::Query.new("0.0.0.0").loopback_ip_address?
39
42
  assert Geocoder::Query.new("127.0.0.1").loopback_ip_address?
40
43
  assert !Geocoder::Query.new("232.65.123.234").loopback_ip_address?
44
+ assert !Geocoder::Query.new("127 Main St.").loopback_ip_address?
45
+ assert !Geocoder::Query.new("John Doe\n127 Main St.\nAnywhere, USA").loopback_ip_address?
41
46
  end
42
47
  end
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+
4
+ class RequestTest < Test::Unit::TestCase
5
+ class MockRequest
6
+ include Geocoder::Request
7
+ attr_accessor :env, :ip
8
+ def initialize(env={}, ip="")
9
+ @env = env
10
+ @ip = ip
11
+ end
12
+ end
13
+ def test_http_x_real_ip
14
+ req = MockRequest.new({"HTTP_X_REAL_IP" => "74.200.247.59"})
15
+ assert req.location.is_a?(Geocoder::Result::Freegeoip)
16
+ end
17
+ def test_http_x_forwarded_for_without_proxy
18
+ req = MockRequest.new({"HTTP_X_FORWARDED_FOR" => "74.200.247.59"})
19
+ assert req.location.is_a?(Geocoder::Result::Freegeoip)
20
+ end
21
+ def test_http_x_forwarded_for_with_proxy
22
+ req = MockRequest.new({"HTTP_X_FORWARDED_FOR" => "74.200.247.59, 74.200.247.59"})
23
+ assert req.location.is_a?(Geocoder::Result::Freegeoip)
24
+ end
25
+ def test_with_request_ip
26
+ req = MockRequest.new({}, "74.200.247.59")
27
+ assert req.location.is_a?(Geocoder::Result::Freegeoip)
28
+ end
29
+ end