geocoder 1.1.3 → 1.1.6

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 (98) hide show
  1. data/.travis.yml +4 -0
  2. data/{CHANGELOG.rdoc → CHANGELOG.md} +109 -35
  3. data/README.md +645 -0
  4. data/examples/autoexpire_cache.rb +28 -0
  5. data/lib/generators/geocoder/config/templates/initializer.rb +18 -22
  6. data/lib/geocoder/cache.rb +2 -1
  7. data/lib/geocoder/calculations.rb +13 -13
  8. data/lib/geocoder/cli.rb +17 -19
  9. data/lib/geocoder/configuration.rb +68 -42
  10. data/lib/geocoder/configuration_hash.rb +11 -0
  11. data/lib/geocoder/exceptions.rb +3 -0
  12. data/lib/geocoder/lookup.rb +81 -0
  13. data/lib/geocoder/lookups/base.rb +106 -56
  14. data/lib/geocoder/lookups/bing.rb +25 -11
  15. data/lib/geocoder/lookups/freegeoip.rb +11 -7
  16. data/lib/geocoder/lookups/geocoder_ca.rb +17 -9
  17. data/lib/geocoder/lookups/google.rb +29 -8
  18. data/lib/geocoder/lookups/google_premier.rb +20 -11
  19. data/lib/geocoder/lookups/mapquest.rb +29 -19
  20. data/lib/geocoder/lookups/maxmind.rb +72 -0
  21. data/lib/geocoder/lookups/nominatim.rb +21 -13
  22. data/lib/geocoder/lookups/test.rb +12 -6
  23. data/lib/geocoder/lookups/yahoo.rb +63 -13
  24. data/lib/geocoder/lookups/yandex.rb +26 -11
  25. data/lib/geocoder/models/mongoid.rb +1 -2
  26. data/lib/geocoder/query.rb +103 -0
  27. data/lib/geocoder/request.rb +7 -1
  28. data/lib/geocoder/results/base.rb +8 -2
  29. data/lib/geocoder/results/google.rb +6 -0
  30. data/lib/geocoder/results/mapquest.rb +19 -34
  31. data/lib/geocoder/results/maxmind.rb +136 -0
  32. data/lib/geocoder/results/nominatim.rb +14 -3
  33. data/lib/geocoder/results/yahoo.rb +9 -2
  34. data/lib/geocoder/sql.rb +106 -0
  35. data/lib/geocoder/stores/active_record.rb +75 -142
  36. data/lib/geocoder/stores/base.rb +3 -2
  37. data/lib/geocoder/stores/mongo_base.rb +2 -2
  38. data/lib/geocoder/version.rb +1 -1
  39. data/lib/geocoder.rb +11 -89
  40. data/lib/hash_recursive_merge.rb +74 -0
  41. data/lib/oauth_util.rb +112 -0
  42. data/test/active_record_test.rb +15 -0
  43. data/test/cache_test.rb +19 -0
  44. data/test/calculations_test.rb +11 -4
  45. data/test/configuration_test.rb +26 -51
  46. data/test/error_handling_test.rb +15 -11
  47. data/test/fixtures/bing_invalid_key +1 -0
  48. data/test/fixtures/mapquest_madison_square_garden +52 -0
  49. data/test/fixtures/mapquest_no_results +7 -0
  50. data/test/fixtures/maxmind_24_24_24_21 +1 -0
  51. data/test/fixtures/maxmind_24_24_24_22 +1 -0
  52. data/test/fixtures/maxmind_24_24_24_23 +1 -0
  53. data/test/fixtures/maxmind_24_24_24_24 +1 -0
  54. data/test/fixtures/maxmind_74_200_247_59 +1 -0
  55. data/test/fixtures/maxmind_invalid_key +1 -0
  56. data/test/fixtures/maxmind_no_results +1 -0
  57. data/test/fixtures/yahoo_error +1 -0
  58. data/test/fixtures/yahoo_invalid_key +2 -0
  59. data/test/fixtures/yahoo_madison_square_garden +52 -0
  60. data/test/fixtures/yahoo_no_results +10 -0
  61. data/test/fixtures/yahoo_over_limit +2 -0
  62. data/test/https_test.rb +3 -3
  63. data/test/integration/smoke_test.rb +8 -6
  64. data/test/lookup_test.rb +92 -13
  65. data/test/near_test.rb +11 -0
  66. data/test/oauth_util_test.rb +30 -0
  67. data/test/proxy_test.rb +2 -2
  68. data/test/query_test.rb +42 -0
  69. data/test/result_test.rb +4 -3
  70. data/test/services_test.rb +164 -26
  71. data/test/test_helper.rb +93 -112
  72. data/test/test_mode_test.rb +3 -4
  73. metadata +52 -35
  74. data/README.rdoc +0 -552
  75. data/test/fixtures/mapquest_madison_square_garden.json +0 -27
  76. data/test/fixtures/mapquest_no_results.json +0 -1
  77. data/test/fixtures/yahoo_garbage.json +0 -50
  78. data/test/fixtures/yahoo_madison_square_garden.json +0 -46
  79. data/test/fixtures/yahoo_no_results.json +0 -10
  80. data/test/input_handling_test.rb +0 -43
  81. /data/test/fixtures/{bing_madison_square_garden.json → bing_madison_square_garden} +0 -0
  82. /data/test/fixtures/{bing_no_results.json → bing_no_results} +0 -0
  83. /data/test/fixtures/{bing_reverse.json → bing_reverse} +0 -0
  84. /data/test/fixtures/{freegeoip_74_200_247_59.json → freegeoip_74_200_247_59} +0 -0
  85. /data/test/fixtures/{freegeoip_no_results.json → freegeoip_no_results} +0 -0
  86. /data/test/fixtures/{geocoder_ca_madison_square_garden.json → geocoder_ca_madison_square_garden} +0 -0
  87. /data/test/fixtures/{geocoder_ca_no_results.json → geocoder_ca_no_results} +0 -0
  88. /data/test/fixtures/{geocoder_ca_reverse.json → geocoder_ca_reverse} +0 -0
  89. /data/test/fixtures/{google_garbage.json → google_garbage} +0 -0
  90. /data/test/fixtures/{google_madison_square_garden.json → google_madison_square_garden} +0 -0
  91. /data/test/fixtures/{google_no_city_data.json → google_no_city_data} +0 -0
  92. /data/test/fixtures/{google_no_locality.json → google_no_locality} +0 -0
  93. /data/test/fixtures/{google_no_results.json → google_no_results} +0 -0
  94. /data/test/fixtures/{nominatim_madison_square_garden.json → nominatim_madison_square_garden} +0 -0
  95. /data/test/fixtures/{nominatim_no_results.json → nominatim_no_results} +0 -0
  96. /data/test/fixtures/{yandex_invalid_key.json → yandex_invalid_key} +0 -0
  97. /data/test/fixtures/{yandex_kremlin.json → yandex_kremlin} +0 -0
  98. /data/test/fixtures/{yandex_no_results.json → yandex_no_results} +0 -0
data/lib/oauth_util.rb ADDED
@@ -0,0 +1,112 @@
1
+ # A utility for signing an url using OAuth in a way that's convenient for debugging
2
+ # Note: the standard Ruby OAuth lib is here http://github.com/mojodna/oauth
3
+ # Source: http://gist.github.com/383159
4
+ # License: http://gist.github.com/375593
5
+ # Usage: see example.rb below
6
+ #
7
+ # NOTE: This file has been modified from the original Gist:
8
+ #
9
+ # 1. Fix to prevent param-array conversion, as mentioned in Gist comment.
10
+ # 2. Query string escaping has been changed. See:
11
+ # https://github.com/alexreisner/geocoder/pull/360
12
+ #
13
+
14
+ require 'uri'
15
+ require 'cgi'
16
+ require 'openssl'
17
+ require 'base64'
18
+
19
+ class OauthUtil
20
+
21
+ attr_accessor :consumer_key, :consumer_secret, :token, :token_secret, :req_method,
22
+ :sig_method, :oauth_version, :callback_url, :params, :req_url, :base_str
23
+
24
+ def initialize
25
+ @consumer_key = ''
26
+ @consumer_secret = ''
27
+ @token = ''
28
+ @token_secret = ''
29
+ @req_method = 'GET'
30
+ @sig_method = 'HMAC-SHA1'
31
+ @oauth_version = '1.0'
32
+ @callback_url = ''
33
+ end
34
+
35
+ # openssl::random_bytes returns non-word chars, which need to be removed. using alt method to get length
36
+ # ref http://snippets.dzone.com/posts/show/491
37
+ def nonce
38
+ Array.new( 5 ) { rand(256) }.pack('C*').unpack('H*').first
39
+ end
40
+
41
+ def percent_encode( string )
42
+
43
+ # ref http://snippets.dzone.com/posts/show/1260
44
+ return URI.escape( string, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]") ).gsub('*', '%2A')
45
+ end
46
+
47
+ # @ref http://oauth.net/core/1.0/#rfc.section.9.2
48
+ def signature
49
+ key = percent_encode( @consumer_secret ) + '&' + percent_encode( @token_secret )
50
+
51
+ # ref: http://blog.nathanielbibler.com/post/63031273/openssl-hmac-vs-ruby-hmac-benchmarks
52
+ digest = OpenSSL::Digest::Digest.new( 'sha1' )
53
+ hmac = OpenSSL::HMAC.digest( digest, key, @base_str )
54
+
55
+ # ref http://groups.google.com/group/oauth-ruby/browse_thread/thread/9110ed8c8f3cae81
56
+ Base64.encode64( hmac ).chomp.gsub( /\n/, '' )
57
+ end
58
+
59
+ # sort (very important as it affects the signature), concat, and percent encode
60
+ # @ref http://oauth.net/core/1.0/#rfc.section.9.1.1
61
+ # @ref http://oauth.net/core/1.0/#9.2.1
62
+ # @ref http://oauth.net/core/1.0/#rfc.section.A.5.1
63
+ def query_string
64
+ pairs = []
65
+ @params.sort.each { | key, val |
66
+ pairs.push( "#{ CGI.escape(key.to_s).gsub(/%(5B|5D)/n) { [$1].pack('H*') } }=#{ CGI.escape(val.to_s) }" )
67
+ }
68
+ pairs.join '&'
69
+ end
70
+
71
+ # organize params & create signature
72
+ def sign( parsed_url )
73
+
74
+ @params = {
75
+ 'oauth_consumer_key' => @consumer_key,
76
+ 'oauth_nonce' => nonce,
77
+ 'oauth_signature_method' => @sig_method,
78
+ 'oauth_timestamp' => Time.now.to_i.to_s,
79
+ 'oauth_version' => @oauth_version
80
+ }
81
+
82
+ # if url has query, merge key/values into params obj overwriting defaults
83
+ if parsed_url.query
84
+ CGI.parse( parsed_url.query ).each do |k,v|
85
+ if v.is_a?(Array) && v.count == 1
86
+ @params[k] = v.first
87
+ else
88
+ @params[k] = v
89
+ end
90
+ end
91
+ end
92
+
93
+ # @ref http://oauth.net/core/1.0/#rfc.section.9.1.2
94
+ @req_url = parsed_url.scheme + '://' + parsed_url.host + parsed_url.path
95
+
96
+ # create base str. make it an object attr for ez debugging
97
+ # ref http://oauth.net/core/1.0/#anchor14
98
+ @base_str = [
99
+ @req_method,
100
+ percent_encode( req_url ),
101
+
102
+ # normalization is just x-www-form-urlencoded
103
+ percent_encode( query_string )
104
+
105
+ ].join( '&' )
106
+
107
+ # add signature
108
+ @params[ 'oauth_signature' ] = signature
109
+
110
+ return self
111
+ end
112
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+
4
+ class ActiveRecordTest < Test::Unit::TestCase
5
+
6
+ def test_exclude_condition_when_model_has_a_custom_primary_key
7
+ venue = VenuePlus.new(*venue_params(:msg))
8
+
9
+ # just call private method directly so we don't have to stub .near scope
10
+ conditions = venue.class.send(:add_exclude_condition, ["fake_condition"], venue)
11
+
12
+ assert_match( /#{VenuePlus.primary_key}/, conditions.join)
13
+ end
14
+
15
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+
4
+ class CacheTest < Test::Unit::TestCase
5
+
6
+ def test_second_occurrence_of_request_is_cache_hit
7
+ Geocoder.configure(:cache => {})
8
+ Geocoder::Lookup.all_services_except_test.each do |l|
9
+ Geocoder.configure(:lookup => l)
10
+ set_api_key!(l)
11
+ results = Geocoder.search("Madison Square Garden")
12
+ assert !results.first.cache_hit,
13
+ "Lookup #{l} returned erroneously cached result."
14
+ results = Geocoder.search("Madison Square Garden")
15
+ assert results.first.cache_hit,
16
+ "Lookup #{l} did not return cached result."
17
+ end
18
+ end
19
+ end
@@ -3,10 +3,10 @@ require 'test_helper'
3
3
 
4
4
  class CalculationsTest < Test::Unit::TestCase
5
5
  def setup
6
- Geocoder.configure do |config|
7
- config.units = :mi
8
- config.distances = :linear
9
- end
6
+ Geocoder.configure(
7
+ :units => :mi,
8
+ :distances => :linear
9
+ )
10
10
  end
11
11
 
12
12
  # --- degree distance ---
@@ -185,4 +185,11 @@ class CalculationsTest < Test::Unit::TestCase
185
185
  assert !Geocoder::Calculations.coordinates_present?(Geocoder::Calculations::NAN)
186
186
  assert !Geocoder::Calculations.coordinates_present?(3.23, nil)
187
187
  end
188
+
189
+ def test_extract_coordinates
190
+ coords = [-23,47]
191
+ l = Landmark.new("Madagascar", coords[0], coords[1])
192
+ assert_equal coords, Geocoder::Calculations.extract_coordinates(l)
193
+ assert_equal coords, Geocoder::Calculations.extract_coordinates(coords)
194
+ end
188
195
  end
@@ -7,69 +7,44 @@ class ConfigurationTest < Test::Unit::TestCase
7
7
  end
8
8
 
9
9
  def test_exception_raised_on_bad_lookup_config
10
- Geocoder::Configuration.lookup = :stoopid
10
+ Geocoder.configure(:lookup => :stoopid)
11
11
  assert_raises Geocoder::ConfigurationError do
12
12
  Geocoder.search "something dumb"
13
13
  end
14
14
  end
15
15
 
16
- # --- class method configuration ---
17
- def test_configurated_by_class_method
18
- Geocoder::Configuration.units = :mi
19
- distance = Geocoder::Calculations.distance_between([0,0], [0,1]).round
20
- assert_not_equal 111, distance
21
- assert_equal 69, distance
22
-
23
- Geocoder::Configuration.units = :km
24
- distance = Geocoder::Calculations.distance_between([0,0], [0,1]).round
25
- assert_equal 111, distance
26
- assert_not_equal 69, distance
27
-
28
- Geocoder::Configuration.distances = :spherical
29
- angle = Geocoder::Calculations.bearing_between([50,-85], [40.750354, -73.993371]).round
30
- assert_equal 136, angle
31
- assert_not_equal 130, angle
16
+ def test_setting_with_class_method
17
+ Geocoder::Configuration.units = :test
18
+ assert_equal :test, Geocoder.config.units
19
+ end
32
20
 
33
- Geocoder::Configuration.distances = :linear
34
- angle = Geocoder::Calculations.bearing_between([50,-85], [40.750354, -73.993371]).round
35
- assert_not_equal 136, angle
36
- assert_equal 130, angle
21
+ def test_setting_with_configure_method
22
+ Geocoder.configure(:units => :test)
23
+ assert_equal :test, Geocoder.config.units
37
24
  end
38
25
 
39
- # --- Geocoder#configure distances configuration ---
40
- def test_geocoder_configuration
41
- # DSL
26
+ def test_setting_with_block_syntax
27
+ orig = $VERBOSE; $VERBOSE = nil
42
28
  Geocoder.configure do |config|
43
- config.units = :mi
44
- config.distances = :linear
29
+ config.units = :test
45
30
  end
31
+ assert_equal :test, Geocoder.config.units
32
+ ensure
33
+ $VERBOSE = orig
34
+ end
46
35
 
47
- assert_equal Geocoder::Configuration.units, :mi
48
- distance = Geocoder::Calculations.distance_between([0,0], [0,1]).round
49
- assert_not_equal 111, distance
50
- assert_equal 69, distance
51
-
52
- assert_equal Geocoder::Configuration.distances, :linear
53
- angle = Geocoder::Calculations.bearing_between([50,-85], [40.750354, -73.993371]).round
54
- assert_not_equal 136, angle
55
- assert_equal 130, angle
56
-
57
- # Direct
58
- Geocoder.configure.units = :km
59
- Geocoder.configure.distances = :spherical
60
-
61
- assert_equal Geocoder::Configuration.units, :km
62
- distance = Geocoder::Calculations.distance_between([0,0], [0,1]).round
63
- assert_equal 111, distance
64
- assert_not_equal 69, distance
65
-
66
- assert_equal Geocoder::Configuration.distances, :spherical
67
- angle = Geocoder::Calculations.bearing_between([50,-85], [40.750354, -73.993371]).round
68
- assert_equal 136, angle
69
- assert_not_equal 130, angle
36
+ def test_config_for_lookup
37
+ Geocoder.configure(
38
+ :timeout => 5,
39
+ :api_key => "aaa",
40
+ :google => {
41
+ :timeout => 2
42
+ }
43
+ )
44
+ assert_equal 2, Geocoder.config_for_lookup(:google).timeout
45
+ assert_equal "aaa", Geocoder.config_for_lookup(:google).api_key
70
46
  end
71
47
 
72
- # Geocoder per-model configuration
73
48
  def test_model_configuration
74
49
  Landmark.reverse_geocoded_by :latitude, :longitude, :method => :spherical, :units => :km
75
50
  assert_equal :km, Landmark.geocoder_options[:units]
@@ -90,7 +65,7 @@ class ConfigurationTest < Test::Unit::TestCase
90
65
  v.longitude = 0
91
66
 
92
67
  # method option > global configuration
93
- Geocoder.configure.units = :km
68
+ Geocoder.configure(:units => :km)
94
69
  assert_equal 69, v.distance_to([0,1], :mi).round
95
70
 
96
71
  # per-model configuration > global configuration
@@ -4,35 +4,39 @@ require 'test_helper'
4
4
  class ErrorHandlingTest < Test::Unit::TestCase
5
5
 
6
6
  def teardown
7
- Geocoder::Configuration.always_raise = []
7
+ Geocoder.configure(:always_raise => [])
8
8
  end
9
9
 
10
10
  def test_does_not_choke_on_timeout
11
11
  # keep test output clean: suppress timeout warning
12
12
  orig = $VERBOSE; $VERBOSE = nil
13
- all_lookups_except_test.each do |l|
14
- Geocoder::Configuration.lookup = l
13
+ Geocoder::Lookup.all_services_except_test.each do |l|
14
+ Geocoder.configure(:lookup => l)
15
+ set_api_key!(l)
15
16
  assert_nothing_raised { Geocoder.search("timeout") }
16
17
  end
18
+ ensure
17
19
  $VERBOSE = orig
18
20
  end
19
21
 
20
22
  def test_always_raise_timeout_error
21
- Geocoder::Configuration.always_raise = [TimeoutError]
22
- all_lookups_except_test.each do |l|
23
- lookup = Geocoder.send(:get_lookup, l)
23
+ Geocoder.configure(:always_raise => [TimeoutError])
24
+ Geocoder::Lookup.all_services_except_test.each do |l|
25
+ lookup = Geocoder::Lookup.get(l)
26
+ set_api_key!(l)
24
27
  assert_raises TimeoutError do
25
- lookup.send(:results, "timeout")
28
+ lookup.send(:results, Geocoder::Query.new("timeout"))
26
29
  end
27
30
  end
28
31
  end
29
32
 
30
33
  def test_always_raise_socket_error
31
- Geocoder::Configuration.always_raise = [SocketError]
32
- all_lookups_except_test.each do |l|
33
- lookup = Geocoder.send(:get_lookup, l)
34
+ Geocoder.configure(:always_raise => [SocketError])
35
+ Geocoder::Lookup.all_services_except_test.each do |l|
36
+ lookup = Geocoder::Lookup.get(l)
37
+ set_api_key!(l)
34
38
  assert_raises SocketError do
35
- lookup.send(:results, "socket_error")
39
+ lookup.send(:results, Geocoder::Query.new("socket_error"))
36
40
  end
37
41
  end
38
42
  end
@@ -0,0 +1 @@
1
+ {"authenticationResultCode":"InvalidCredentials","brandLogoUri":"http:\\/\\/dev.virtualearth.net\\/Branding\\/logo_powered_by.png","copyright":"Copyright \xC2\xA9 2012 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.","errorDetails":["Access was denied. You may have entered your credentials incorrectly, or you might not have access to the requested resource or operation."],"resourceSets":[],"statusCode":401,"statusDescription":"Unauthorized","traceId":"5c539f6e70c44b2e858741b6c932318e|EWRM001670|02.00.83.1900|"}
@@ -0,0 +1,52 @@
1
+ {
2
+ "results": [
3
+ {
4
+ "locations": [
5
+ {
6
+ "latLng": {
7
+ "lng": -73.994637,
8
+ "lat": 40.720409
9
+ },
10
+ "adminArea4": "New York County",
11
+ "adminArea5Type": "City",
12
+ "adminArea4Type": "County",
13
+ "adminArea5": "New York",
14
+ "street": "46 West 31st Street",
15
+ "adminArea1": "US",
16
+ "adminArea3": "NY",
17
+ "type": "s",
18
+ "displayLatLng": {
19
+ "lng": -73.994637,
20
+ "lat": 40.720409
21
+ },
22
+ "linkId": 0,
23
+ "postalCode": "10001",
24
+ "sideOfStreet": "N",
25
+ "dragPoint": false,
26
+ "adminArea1Type": "Country",
27
+ "geocodeQuality": "CITY",
28
+ "geocodeQualityCode": "A5XAX",
29
+ "mapUrl": "http://www.mapquestapi.com/staticmap/v3/getmap?type=map&size=225,160&pois=purple-1,40.720409,-73.994637,0,0|&center=40.720409,-73.994637&zoom=9&key=Gmjtd|luua2hu2nd,7x=o5-lz8lg&rand=604519389",
30
+ "adminArea3Type": "State"
31
+ }
32
+ ],
33
+ "providedLocation": {
34
+ "location": "Madison Square Garden, New York, NY"
35
+ }
36
+ }
37
+ ],
38
+ "options": {
39
+ "ignoreLatLngInput": false,
40
+ "maxResults": -1,
41
+ "thumbMaps": true
42
+ },
43
+ "info": {
44
+ "copyright": {
45
+ "text": "© 2012 MapQuest, Inc.",
46
+ "imageUrl": "http://api.mqcdn.com/res/mqlogo.gif",
47
+ "imageAltText": "© 2012 MapQuest, Inc."
48
+ },
49
+ "statuscode": 0,
50
+ "messages": []
51
+ }
52
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "results": [
3
+ {
4
+ "locations": []
5
+ }
6
+ ]
7
+ }
@@ -0,0 +1 @@
1
+ US,
@@ -0,0 +1 @@
1
+ US,NY,Jamaica,40.6915,-73.8057,
@@ -0,0 +1 @@
1
+ US,NY,Jamaica,,40.6915,-73.8057,501,718,"Road Runner","Road Runner",
@@ -0,0 +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,,
@@ -0,0 +1 @@
1
+ US,TX,Plano,75093,33.034698,-96.813400,623,972,"Layered Technologies , US","Layered Technologies , US",
@@ -0,0 +1 @@
1
+ ,,,,,,,,,,INVALID_LICENSE_KEY
@@ -0,0 +1 @@
1
+ ,,,,,,,,,,IP_NOT_FOUND
@@ -0,0 +1 @@
1
+ {"bossresponse":{"responsecode":"6000","reason":"internal error"}}
@@ -0,0 +1,2 @@
1
+ <?xml version='1.0' encoding='UTF-8'?>\n<yahoo:error xmlns:yahoo='http://yahooapis.com/v1/base.rng'\n xml:lang='en-US'>
2
+ <yahoo:description>Please provide valid credentials. OAuth oauth_problem="consumer_key_unknown", realm="yahooapis.com"</yahoo:description>\n</yahoo:error>
@@ -0,0 +1,52 @@
1
+ {
2
+ "bossresponse": {
3
+ "responsecode": "200",
4
+ "placefinder": {
5
+ "start": "0",
6
+ "count": "1",
7
+ "request": "flags=JXTSR&location=Madison%20Square%20Garden%2C%20NY%2C%20NY&%unsafe%appid=%5B%22dj0yJmk9ZmZ5NXFrNGhNcEthJmQ9WVdrOVFUSlhPV2x1TjJVbWNHbzlORE0wT0RFME9UWXkmcz1jb25zdW1lcnNlY3JldCZ4PTAy%22%2C%20%22b57b1b98eb21f171231f5b441cba505261d6c9bb%22%5D&gflags=AC&locale=en_US",
8
+ "results": [
9
+ {
10
+ "quality": "90",
11
+ "latitude": "40.750381",
12
+ "longitude": "-73.993988",
13
+ "offsetlat": "40.750381",
14
+ "offsetlon": "-73.993988",
15
+ "radius": "400",
16
+ "boundingbox": {
17
+ "north": "40.750832",
18
+ "south": "40.749931",
19
+ "east": "-73.993393",
20
+ "west": "-73.994591"
21
+ },
22
+ "name": "Madison Square Garden",
23
+ "line1": "Madison Square Garden",
24
+ "line2": "New York, NY 10001",
25
+ "line3": "",
26
+ "line4": "United States",
27
+ "cross": "",
28
+ "house": "",
29
+ "street": "",
30
+ "xstreet": "",
31
+ "unittype": "",
32
+ "unit": "",
33
+ "postal": "10001",
34
+ "neighborhood": "Garment District|Midtown|Midtown West|Manhattan",
35
+ "city": "New York",
36
+ "county": "New York County",
37
+ "state": "New York",
38
+ "country": "United States",
39
+ "countrycode": "US",
40
+ "statecode": "NY",
41
+ "countycode": "",
42
+ "timezone": "America/New_York",
43
+ "areacode": "212",
44
+ "uzip": "10001",
45
+ "hash": "",
46
+ "woeid": "23617041",
47
+ "woetype": "20"
48
+ }
49
+ ]
50
+ }
51
+ }
52
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "bossresponse": {
3
+ "responsecode": "200",
4
+ "placefinder": {
5
+ "start": "0",
6
+ "count": "0",
7
+ "request": "flags=JXTSR&location=asdfasdf28394782sdfj2983&%unsafe%appid=%5B%22dj0yJmk9ZmZ5NXFrNGhNcEthJmQ9WVdrOVFUSlhPV2x1TjJVbWNHbzlORE0wT0RFME9UWXkmcz1jb25zdW1lcnNlY3JldCZ4PTAy%22%2C%20%22b57b1b98eb21f171231f5b441cba505261d6c9bb%22%5D&gflags=AC&locale=en_US"
8
+ }
9
+ }
10
+ }
@@ -0,0 +1,2 @@
1
+ <?xml version="1.0" encoding="utf-8"?> <yahoo:error xmlns:yahoo="http://yahooapis.com/v1/base.rng\ <http://yahooapis.com/v1/base.rng%5C>" xml:lang="en-US">
2
+ <yahoo:description>Rate Limit Exceeded</yahoo:description> <yahoo:detail>Key has exceeded its configured rate limit.</yahoo:detail> </yahoo:error>
data/test/https_test.rb CHANGED
@@ -4,13 +4,13 @@ require 'test_helper'
4
4
  class HttpsTest < Test::Unit::TestCase
5
5
 
6
6
  def test_uses_https_for_secure_query
7
- Geocoder::Configuration.use_https = true
7
+ Geocoder.configure(:use_https => true)
8
8
  g = Geocoder::Lookup::Google.new
9
- assert_match /^https:/, g.send(:query_url, {:a => 1, :b => 2})
9
+ assert_match /^https:/, g.query_url(Geocoder::Query.new("test"))
10
10
  end
11
11
 
12
12
  def test_uses_http_by_default
13
13
  g = Geocoder::Lookup::Google.new
14
- assert_match /^http:/, g.send(:query_url, {:a => 1, :b => 2})
14
+ assert_match /^http:/, g.query_url(Geocoder::Query.new("test"))
15
15
  end
16
16
  end
@@ -8,17 +8,19 @@ class SmokeTest < Test::Unit::TestCase
8
8
 
9
9
  def test_simple_zip_code_search
10
10
  result = Geocoder.search "27701"
11
- assert_equal "Durham", result.first.city
12
- assert_equal "North Carolina", result.first.state
11
+ assert_not_nil (r = result.first)
12
+ assert_equal "Durham", r.city
13
+ assert_equal "North Carolina", r.state
13
14
  end
14
15
 
15
16
  def test_simple_zip_code_search_with_ssl
16
- Geocoder::Configuration.use_https = true
17
+ Geocoder.configure(:use_https => true)
17
18
  result = Geocoder.search "27701"
18
- assert_equal "Durham", result.first.city
19
- assert_equal "North Carolina", result.first.state
19
+ assert_not_nil (r = result.first)
20
+ assert_equal "Durham", r.city
21
+ assert_equal "North Carolina", r.state
20
22
  ensure
21
- Geocoder::Configuration.use_https = false
23
+ Geocoder.configure(:use_https => false)
22
24
  end
23
25
 
24
26
  end