geocoder 0.9.12 → 1.0.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.
@@ -0,0 +1,16 @@
1
+ {
2
+ "response": {
3
+ "GeoObjectCollection": {
4
+ "metaDataProperty": {
5
+ "GeocoderResponseMetaData": {
6
+ "request": "blah",
7
+ "found": "0",
8
+ "results": "10"
9
+ }
10
+ },
11
+ "featureMember": [
12
+
13
+ ]
14
+ }
15
+ }
16
+ }
@@ -20,6 +20,24 @@ class GeocoderTest < Test::Unit::TestCase
20
20
 
21
21
  # --- sanity checks ---
22
22
 
23
+ def test_uses_proxy_when_specified
24
+ Geocoder::Configuration.http_proxy = 'localhost'
25
+ lookup = Geocoder::Lookup::Google.new
26
+ assert lookup.send(:http_client).proxy_class?
27
+ end
28
+
29
+ def test_doesnt_use_proxy_when_not_specified
30
+ lookup = Geocoder::Lookup::Google.new
31
+ assert !lookup.send(:http_client).proxy_class?
32
+ end
33
+
34
+ def test_exception_raised_on_bad_proxy_url
35
+ Geocoder::Configuration.http_proxy = ' \\_O< Quack Quack'
36
+ assert_raise Geocoder::ConfigurationError do
37
+ Geocoder::Lookup::Google.new.send(:http_client)
38
+ end
39
+ end
40
+
23
41
  def test_uses_https_for_secure_query
24
42
  Geocoder::Configuration.use_https = true
25
43
  g = Geocoder::Lookup::Google.new
@@ -369,6 +387,17 @@ class GeocoderTest < Test::Unit::TestCase
369
387
  end
370
388
 
371
389
 
390
+ # --- Yandex ---
391
+
392
+ def test_yandex_with_invalid_key
393
+ # keep test output clean: suppress timeout warning
394
+ orig = $VERBOSE; $VERBOSE = nil
395
+ Geocoder::Configuration.lookup = :yandex
396
+ assert_equal [], Geocoder.search("invalid key")
397
+ $VERBOSE = orig
398
+ end
399
+
400
+
372
401
  # --- Geocoder.ca ---
373
402
 
374
403
  def test_geocoder_ca_result_components
@@ -392,6 +421,23 @@ class GeocoderTest < Test::Unit::TestCase
392
421
  end
393
422
 
394
423
 
424
+ # --- Bing ---
425
+
426
+ def test_bing_result_components
427
+ Geocoder::Configuration.lookup = :bing
428
+ result = Geocoder.search("Madison Square Garden, New York, NY").first
429
+ assert_equal "Madison Square Garden, NY", result.address
430
+ assert_equal "NY", result.state
431
+ assert_equal "New York", result.city
432
+ end
433
+
434
+ def test_bing_no_results
435
+ Geocoder::Configuration.lookup = :bing
436
+ results = Geocoder.search("no results")
437
+ assert_equal 0, results.length
438
+ end
439
+
440
+
395
441
  # --- search queries ---
396
442
 
397
443
  def test_hash_to_query
@@ -416,13 +462,17 @@ class GeocoderTest < Test::Unit::TestCase
416
462
 
417
463
  def assert_result_has_required_attributes(result)
418
464
  m = "Lookup #{Geocoder::Configuration.lookup} does not support %s attribute."
419
- assert result.coordinates.is_a?(Array), m % "coordinates"
420
- assert result.latitude.is_a?(Float), m % "latitude"
421
- assert result.longitude.is_a?(Float), m % "longitude"
422
- assert result.city.is_a?(String), m % "city"
423
- assert result.postal_code.is_a?(String), m % "postal_code"
424
- assert result.country.is_a?(String), m % "country"
425
- assert result.country_code.is_a?(String), m % "country_code"
426
- assert_not_nil result.address, m % "address"
465
+ assert result.coordinates.is_a?(Array), m % "coordinates"
466
+ assert result.latitude.is_a?(Float), m % "latitude"
467
+ assert result.longitude.is_a?(Float), m % "longitude"
468
+ assert result.city.is_a?(String), m % "city"
469
+ assert result.state.is_a?(String), m % "state"
470
+ assert result.state_code.is_a?(String), m % "state_code"
471
+ assert result.province.is_a?(String), m % "province"
472
+ assert result.province_code.is_a?(String), m % "province_code"
473
+ assert result.postal_code.is_a?(String), m % "postal_code"
474
+ assert result.country.is_a?(String), m % "country"
475
+ assert result.country_code.is_a?(String), m % "country_code"
476
+ assert_not_nil result.address, m % "address"
427
477
  end
428
478
  end
data/test/test_helper.rb CHANGED
@@ -75,11 +75,27 @@ module Geocoder
75
75
  private #-----------------------------------------------------------------
76
76
  def fetch_raw_data(query, reverse = false)
77
77
  raise TimeoutError if query == "timeout"
78
- file = query == "no results" ? :no_results : :madison_square_garden
78
+ file = case query
79
+ when "no results"; :no_results
80
+ else :madison_square_garden
81
+ end
79
82
  read_fixture "yahoo_#{file}.json"
80
83
  end
81
84
  end
82
85
 
86
+ class Yandex < Base
87
+ private #-----------------------------------------------------------------
88
+ def fetch_raw_data(query, reverse = false)
89
+ raise TimeoutError if query == "timeout"
90
+ file = case query
91
+ when "no results"; :no_results
92
+ when "invalid key"; :invalid_key
93
+ else :kremlin
94
+ end
95
+ read_fixture "yandex_#{file}.json"
96
+ end
97
+ end
98
+
83
99
  class GeocoderCa < Base
84
100
  private #-----------------------------------------------------------------
85
101
  def fetch_raw_data(query, reverse = false)
@@ -87,7 +103,10 @@ module Geocoder
87
103
  if reverse
88
104
  read_fixture "geocoder_ca_reverse.json"
89
105
  else
90
- file = query == "no results" ? :no_results : :madison_square_garden
106
+ file = case query
107
+ when "no results"; :no_results
108
+ else :madison_square_garden
109
+ end
91
110
  read_fixture "geocoder_ca_#{file}.json"
92
111
  end
93
112
  end
@@ -100,6 +119,23 @@ module Geocoder
100
119
  read_fixture "freegeoip_74_200_247_59.json"
101
120
  end
102
121
  end
122
+
123
+ class Bing < Base
124
+ private #-----------------------------------------------------------------
125
+ def fetch_raw_data(query, reverse = false)
126
+ raise TimeoutError if query == "timeout"
127
+ if reverse
128
+ read_fixture "bing_reverse.json"
129
+ else
130
+ file = case query
131
+ when "no results"; :no_results
132
+ else :madison_square_garden
133
+ end
134
+ read_fixture "bing_#{file}.json"
135
+ end
136
+ end
137
+ end
138
+
103
139
  end
104
140
  end
105
141
 
@@ -194,7 +230,7 @@ class Test::Unit::TestCase
194
230
  end
195
231
 
196
232
  def all_lookups
197
- Geocoder.send(:valid_lookups)
233
+ Geocoder.valid_lookups
198
234
  end
199
235
 
200
236
  def street_lookups
metadata CHANGED
@@ -2,71 +2,82 @@
2
2
  name: geocoder
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.9.12
5
+ version: 1.0.0
6
6
  platform: ruby
7
7
  authors:
8
- - Alex Reisner
8
+ - Alex Reisner
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-06 00:00:00 -04:00
13
+ date: 2011-05-09 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
17
- description: Provides object geocoding (by street or IP address), reverse geocoding (coordinates to street address), and distance queries for ActiveRecord and Mongoid. Designed for Rails but works with other Rack frameworks too.
17
+ description: Provides object geocoding (by street or IP address), reverse geocoding (coordinates to street address), distance queries for ActiveRecord and Mongoid, result caching, and more. Designed for Rails but works with Sinatra and other Rack frameworks too.
18
18
  email:
19
- - alex@alexreisner.com
20
- executables: []
21
-
19
+ - alex@alexreisner.com
20
+ executables:
21
+ - geocode
22
22
  extensions: []
23
23
 
24
24
  extra_rdoc_files: []
25
25
 
26
26
  files:
27
- - .gitignore
28
- - CHANGELOG.rdoc
29
- - LICENSE
30
- - README.rdoc
31
- - Rakefile
32
- - VERSION
33
- - lib/geocoder.rb
34
- - lib/geocoder/cache.rb
35
- - lib/geocoder/calculations.rb
36
- - lib/geocoder/configuration.rb
37
- - lib/geocoder/lookups/base.rb
38
- - lib/geocoder/lookups/freegeoip.rb
39
- - lib/geocoder/lookups/geocoder_ca.rb
40
- - lib/geocoder/lookups/google.rb
41
- - lib/geocoder/lookups/yahoo.rb
42
- - lib/geocoder/models/active_record.rb
43
- - lib/geocoder/models/base.rb
44
- - lib/geocoder/models/mongoid.rb
45
- - lib/geocoder/railtie.rb
46
- - lib/geocoder/request.rb
47
- - lib/geocoder/results/base.rb
48
- - lib/geocoder/results/freegeoip.rb
49
- - lib/geocoder/results/geocoder_ca.rb
50
- - lib/geocoder/results/google.rb
51
- - lib/geocoder/results/yahoo.rb
52
- - lib/geocoder/stores/active_record.rb
53
- - lib/geocoder/stores/active_record_legacy.rb
54
- - lib/geocoder/stores/base.rb
55
- - lib/geocoder/stores/mongoid.rb
56
- - lib/tasks/geocoder.rake
57
- - test/fixtures/freegeoip_74_200_247_59.json
58
- - test/fixtures/geocoder_ca_madison_square_garden.json
59
- - test/fixtures/geocoder_ca_no_results.json
60
- - test/fixtures/geocoder_ca_reverse.json
61
- - test/fixtures/google_garbage.json
62
- - test/fixtures/google_madison_square_garden.json
63
- - test/fixtures/google_no_locality.json
64
- - test/fixtures/google_no_results.json
65
- - test/fixtures/yahoo_garbage.json
66
- - test/fixtures/yahoo_madison_square_garden.json
67
- - test/fixtures/yahoo_no_results.json
68
- - test/geocoder_test.rb
69
- - test/test_helper.rb
27
+ - .gitignore
28
+ - CHANGELOG.rdoc
29
+ - LICENSE
30
+ - README.rdoc
31
+ - Rakefile
32
+ - bin/geocode
33
+ - lib/geocoder.rb
34
+ - lib/geocoder/cache.rb
35
+ - lib/geocoder/calculations.rb
36
+ - lib/geocoder/cli.rb
37
+ - lib/geocoder/configuration.rb
38
+ - lib/geocoder/lookups/base.rb
39
+ - lib/geocoder/lookups/bing.rb
40
+ - lib/geocoder/lookups/freegeoip.rb
41
+ - lib/geocoder/lookups/geocoder_ca.rb
42
+ - lib/geocoder/lookups/google.rb
43
+ - lib/geocoder/lookups/yahoo.rb
44
+ - lib/geocoder/lookups/yandex.rb
45
+ - lib/geocoder/models/active_record.rb
46
+ - lib/geocoder/models/base.rb
47
+ - lib/geocoder/models/mongoid.rb
48
+ - lib/geocoder/railtie.rb
49
+ - lib/geocoder/request.rb
50
+ - lib/geocoder/results/base.rb
51
+ - lib/geocoder/results/bing.rb
52
+ - lib/geocoder/results/freegeoip.rb
53
+ - lib/geocoder/results/geocoder_ca.rb
54
+ - lib/geocoder/results/google.rb
55
+ - lib/geocoder/results/yahoo.rb
56
+ - lib/geocoder/results/yandex.rb
57
+ - lib/geocoder/stores/active_record.rb
58
+ - lib/geocoder/stores/base.rb
59
+ - lib/geocoder/stores/mongoid.rb
60
+ - lib/geocoder/version.rb
61
+ - lib/tasks/geocoder.rake
62
+ - test/fixtures/bing_madison_square_garden.json
63
+ - test/fixtures/bing_no_results.json
64
+ - test/fixtures/bing_reverse.json
65
+ - test/fixtures/freegeoip_74_200_247_59.json
66
+ - test/fixtures/geocoder_ca_madison_square_garden.json
67
+ - test/fixtures/geocoder_ca_no_results.json
68
+ - test/fixtures/geocoder_ca_reverse.json
69
+ - test/fixtures/google_garbage.json
70
+ - test/fixtures/google_madison_square_garden.json
71
+ - test/fixtures/google_no_locality.json
72
+ - test/fixtures/google_no_results.json
73
+ - test/fixtures/yahoo_garbage.json
74
+ - test/fixtures/yahoo_madison_square_garden.json
75
+ - test/fixtures/yahoo_no_results.json
76
+ - test/fixtures/yandex_invalid_key.json
77
+ - test/fixtures/yandex_kremlin.json
78
+ - test/fixtures/yandex_no_results.json
79
+ - test/geocoder_test.rb
80
+ - test/test_helper.rb
70
81
  has_rdoc: true
71
82
  homepage: http://www.rubygeocoder.com
72
83
  licenses: []
@@ -75,23 +86,23 @@ post_install_message:
75
86
  rdoc_options: []
76
87
 
77
88
  require_paths:
78
- - lib
89
+ - lib
79
90
  required_ruby_version: !ruby/object:Gem::Requirement
80
91
  none: false
81
92
  requirements:
82
- - - ">="
83
- - !ruby/object:Gem::Version
84
- version: "0"
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: "0"
85
96
  required_rubygems_version: !ruby/object:Gem::Requirement
86
97
  none: false
87
98
  requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- version: "0"
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: "0"
91
102
  requirements: []
92
103
 
93
104
  rubyforge_project:
94
- rubygems_version: 1.6.2
105
+ rubygems_version: 1.5.1
95
106
  signing_key:
96
107
  specification_version: 3
97
108
  summary: Complete geocoding solution for Ruby.
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.9.12
@@ -1,62 +0,0 @@
1
- module Geocoder::Store::ActiveRecord
2
- module Legacy
3
-
4
- ##
5
- # Fetch coordinates and update (save) +latitude+ and +longitude+ data.
6
- #
7
- def fetch_coordinates!
8
- warn "DEPRECATION WARNING: The 'fetch_coordinates!' method is deprecated and will be removed in geocoder v1.0. " +
9
- "Please use 'geocode' instead and then save your objects manually."
10
- do_lookup(false) do |o,rs|
11
- r = rs.first
12
- unless r.latitude.nil? or r.longitude.nil?
13
- o.send :update_attribute, self.class.geocoder_options[:latitude], r.latitude
14
- o.send :update_attribute, self.class.geocoder_options[:longitude], r.longitude
15
- end
16
- r.coordinates
17
- end
18
- end
19
-
20
- def fetch_coordinates(*args)
21
- warn "DEPRECATION WARNING: The 'fetch_coordinates' method will cease taking " +
22
- "an argument in geocoder v1.0. Please save your objects manually." if args.size > 0
23
- do_lookup(false) do |o,rs|
24
- r = rs.first
25
- unless r.latitude.nil? or r.longitude.nil?
26
- method = ((args.size > 0 && args.first) ? "update" : "write" ) + "_attribute"
27
- o.send method, self.class.geocoder_options[:latitude], r.latitude
28
- o.send method, self.class.geocoder_options[:longitude], r.longitude
29
- end
30
- r.coordinates
31
- end
32
- end
33
-
34
- ##
35
- # Fetch address and update (save) +address+ data.
36
- #
37
- def fetch_address!
38
- warn "DEPRECATION WARNING: The 'fetch_address!' method is deprecated and will be removed in geocoder v1.0. " +
39
- "Please use 'reverse_geocode' instead and then save your objects manually."
40
- do_lookup(true) do |o,rs|
41
- r = rs.first
42
- unless r.address.nil?
43
- o.send :update_attribute, self.class.geocoder_options[:fetched_address], r.address
44
- end
45
- r.address
46
- end
47
- end
48
-
49
- def fetch_address(*args)
50
- warn "DEPRECATION WARNING: The 'fetch_address' method will cease taking " +
51
- "an argument in geocoder v1.0. Please save your objects manually." if args.size > 0
52
- do_lookup(true) do |o,rs|
53
- r = rs.first
54
- unless r.latitude.nil? or r.longitude.nil?
55
- method = ((args.size > 0 && args.first) ? "update" : "write" ) + "_attribute"
56
- o.send method, self.class.geocoder_options[:fetched_address], r.address
57
- end
58
- r.address
59
- end
60
- end
61
- end
62
- end