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/.travis.yml CHANGED
@@ -2,6 +2,7 @@ rvm:
2
2
  - 1.8.7
3
3
  - 1.9.2
4
4
  - 1.9.3
5
+ - jruby-19mode
5
6
  gemfile:
6
7
  - Gemfile
7
8
  - gemfiles/Gemfile.mongoid-2.4.x
@@ -17,3 +18,6 @@ matrix:
17
18
  - rvm: 1.9.3
18
19
  gemfile: gemfiles/Gemfile.mongoid-2.4.x
19
20
  env: SSL_CERT_DIR=/etc/ssl/certs
21
+ - rvm: jruby-19mode
22
+ gemfile: gemfiles/Gemfile.mongoid-2.4.x
23
+ env: SSL_CERT_DIR=/etc/ssl/certs
@@ -1,8 +1,49 @@
1
- = Changelog
1
+ Changelog
2
+ =========
2
3
 
3
4
  Per-release changes to Geocoder.
4
5
 
5
- == 1.1.3 (2012 Aug 26)
6
+ 1.1.6 (2012 Dec 24)
7
+ -------------------
8
+
9
+ * Major changes to configuration syntax which allow for API-specific config options. Old config syntax is now DEPRECATED.
10
+ * Add support for MaxMind API (thanks github.com/gonzoyumo).
11
+ * Add optional Geocoder::InvalidApiKey exception for bad API credentials (Yahoo, Yandex, Bing, and Maxmind). Warn when bad key and exception not set in Geocoder.configure(:always_raise => [...]).
12
+ * Add support for X-Real-IP and X-Forwarded-For headers (thanks github.com/konsti).
13
+ * Add support for custom Nominatim host config: Geocoder.configure(:nominatim => {:host => "..."}).
14
+ * Raise exception when required API key is missing or incorrect format.
15
+ * Add support for Google's :region and :components parameters (thanks to github.com/tomlion).
16
+ * Fix: string escaping bug in OAuth lib (thanks github.com/m0thman).
17
+ * Fix: configured units were not always respected in SQL queries.
18
+ * Fix: in #nearbys, don't try to exclude self if not yet persisted.
19
+ * Fix: bug with cache stores that provided #delete but not #del.
20
+ * Change #nearbys so that it returns nil instead of [] when object is not geocoded.
21
+
22
+ 1.1.5 (2012 Nov 9)
23
+ ------------------
24
+
25
+ * Replace support for old Yahoo Placefinder with Yahoo BOSS (thanks github.com/pwoltman).
26
+ * Add support for actual Mapquest API (was previously just a proxy for Nominatim), including the paid service (thanks github.com/jedschneider).
27
+ * Add support for :select => :id_only option to near scope.
28
+ * Treat a given query as blank (don't do a lookup) if coordinates are given but latitude or longitude is nil.
29
+ * Speed up 'near' queries by adding bounding box condition (thanks github.com/mlandauer).
30
+ * Fix: don't redefine Object#hash in Yahoo result object (thanks github.com/m0thman).
31
+
32
+ 1.1.4 (2012 Oct 2)
33
+ ------------------
34
+
35
+ * Deprecate Geocoder::Result::Nominatim#class and #type methods. Use #place_class and #place_type instead.
36
+ * Add support for setting arbitrary parameters in geocoding request URL.
37
+ * Add support for Google's :bounds parameter (thanks to github.com/rosscooperman and github.com/peterjm for submitting suggestions).
38
+ * Add support for :select => :geo_only option to near scope (thanks github.com/gugl).
39
+ * Add ability to omit ORDER BY clause from .near scope (pass option :order => false).
40
+ * Fix: error on Yahoo lookup due to API change (thanks github.com/kynesun).
41
+ * Fix: problem with Mongoid field aliases not being respected.
42
+ * Fix: :exclude option to .near scope when primary key != :id (thanks github.com/smisml).
43
+ * Much code refactoring (added Geocoder::Query class and Geocoder::Sql module).
44
+
45
+ 1.1.3 (2012 Aug 26)
46
+ -------------------
6
47
 
7
48
  * Add support for Mapquest geocoding service (thanks github.com/razorinc).
8
49
  * Add :test lookup for easy testing of apps using Geocoder (thanks github.com/mguterl).
@@ -15,7 +56,8 @@ Per-release changes to Geocoder.
15
56
  * Fix: bug in distance_from_sql method (error occurred when coordinates not found).
16
57
  * Fix: incompatibility with Mongoid 3.0.x (thanks github.com/petergoldstein).
17
58
 
18
- == 1.1.2 (2012 May 24)
59
+ 1.1.2 (2012 May 24)
60
+ -------------------
19
61
 
20
62
  * Add ability to specify default units and distance calculation method (thanks github.com/abravalheri).
21
63
  * Add new (optional) configuration syntax (thanks github.com/abravalheri).
@@ -26,7 +68,8 @@ Per-release changes to Geocoder.
26
68
  * Fix: properly recognize IP addresses with ::ffff: prefix (thanks github.com/brian-ewell).
27
69
  * Fix: avoid exception during calculations when coordinates not known (thanks github.com/flori).
28
70
 
29
- == 1.1.1 (2012 Feb 16)
71
+ 1.1.1 (2012 Feb 16)
72
+ -------------------
30
73
 
31
74
  * Add distance_from_sql class method to geocoded class (thanks github.com/dwilkie).
32
75
  * Add OverQueryLimitError and raise when relevant for Google lookup.
@@ -34,7 +77,8 @@ Per-release changes to Geocoder.
34
77
  * Fix: within_bounding_box now uses correct lat/lon DB columns (thanks github.com/kongo).
35
78
  * Fix: error accessing city in some cases with Yandex result (thanks github.com/kor6n and sld).
36
79
 
37
- == 1.1.0 (2011 Dec 3)
80
+ 1.1.0 (2011 Dec 3)
81
+ ------------------
38
82
 
39
83
  * A block passed to geocoded_by is now always executed, even if the geocoding service returns no results. This means you need to make sure you have results before trying to assign data to your object.
40
84
  * Fix issues with joins and row counts (issues #49, 86, and 108) by not using GROUP BY clause with ActiveRecord scopes.
@@ -46,17 +90,20 @@ Per-release changes to Geocoder.
46
90
  * Add support for API key to Geocoder.ca geocoding service (thanks github.com/ryanLonac).
47
91
  * Add support for state to Yandex results (thanks github.com/tipugin).
48
92
 
49
- == 1.0.5 (2011 Oct 26)
93
+ 1.0.5 (2011 Oct 26)
94
+ -------------------
50
95
 
51
96
  * Fix error with `rake assets:precompile` (thanks github.com/Sush).
52
97
  * Fix HTTPS support (thanks github.com/rsanheim).
53
98
  * Improve cache interface.
54
99
 
55
- == 1.0.4 (2011 Sep 18)
100
+ 1.0.4 (2011 Sep 18)
101
+ -------------------
56
102
 
57
103
  * Remove klass method from rake task, which could conflict with app methods (thanks github.com/mguterl).
58
104
 
59
- == 1.0.3 (2011 Sep 17)
105
+ 1.0.3 (2011 Sep 17)
106
+ -------------------
60
107
 
61
108
  * Add support for Google Premier geocoding service (thanks github.com/steveh).
62
109
  * Update Google API URL (thanks github.com/soorajb).
@@ -64,19 +111,22 @@ Per-release changes to Geocoder.
64
111
  * Fix: rake assets:precompile (Rails 3.1) not working in some situations.
65
112
  * Fix: stop double-adjusting units when using kilometers (thanks github.com/hairyheron).
66
113
 
67
- == 1.0.2 (2011 June 25)
114
+ 1.0.2 (2011 June 25)
115
+ --------------------
68
116
 
69
117
  * Add support for MongoMapper (thanks github.com/spagalloco).
70
118
  * Fix: user-specified coordinates field wasn't working with Mongoid (thanks github.com/thisduck).
71
119
  * Fix: invalid location given to near scope was returning all results (Active Record) or error (Mongoid) (thanks github.com/ogennadi).
72
120
 
73
- == 1.0.1 (2011 May 17)
121
+ 1.0.1 (2011 May 17)
122
+ -------------------
74
123
 
75
124
  * Add option to not rescue from certain exceptions (thanks github.com/ahmedrb).
76
125
  * Fix STI child/parent geocoding bug (thanks github.com/ogennadi).
77
126
  * Other bugfixes.
78
127
 
79
- == 1.0.0 (2011 May 9)
128
+ 1.0.0 (2011 May 9)
129
+ ------------------
80
130
 
81
131
  * Add command line interface.
82
132
  * Add support for local proxy (thanks github.com/Olivier).
@@ -85,11 +135,13 @@ Per-release changes to Geocoder.
85
135
  * Fix single table inheritance bug (reported by github.com/enrico).
86
136
  * Fix bug when Google result supplies no city (thanks github.com/jkeen).
87
137
 
88
- == 0.9.13 (2011 Apr 11)
138
+ 0.9.13 (2011 Apr 11)
139
+ --------------------
89
140
 
90
141
  * Fix "can't find special index: 2d" error when using Mongoid with Ruby 1.8.
91
142
 
92
- == 0.9.12 (2011 Apr 6)
143
+ 0.9.12 (2011 Apr 6)
144
+ -------------------
93
145
 
94
146
  * Add support for Mongoid.
95
147
  * Add bearing_to/from methods to geocoded objects.
@@ -100,7 +152,8 @@ Per-release changes to Geocoder.
100
152
  * DEPRECATION: Geocoder.near should not take <tt>:limit</tt> or <tt>:offset</tt> options.
101
153
  * DEPRECATION: Change argument format of all methods that take lat/lon as separate arguments. Now you must pass the coordinates as an array [lat,lon], but you may alternatively pass a address string (will look up coordinates) or a geocoded object (or any object that implements a to_coordinates method which returns a [lat,lon] array).
102
154
 
103
- == 0.9.11 (2011 Mar 25)
155
+ 0.9.11 (2011 Mar 25)
156
+ --------------------
104
157
 
105
158
  * Add support for result caching.
106
159
  * Add support for Geocoder.ca geocoding service.
@@ -110,12 +163,14 @@ Per-release changes to Geocoder.
110
163
  * DEPRECATION: <tt>Geocoder.search</tt> now returns an array instead of a single result.
111
164
  * DEPRECATION: <tt>obj.nearbys</tt> second argument is now an options hash (instead of units). Please change <tt>obj.nearbys(20, :km)</tt> to: <tt>obj.nearbys(20, :units => :km)</tt>.
112
165
 
113
- == 0.9.10 (2011 Mar 9)
166
+ 0.9.10 (2011 Mar 9)
167
+ -------------------
114
168
 
115
169
  * Fix broken scopes (github.com/mikepinde).
116
170
  * Fix broken Ruby 1.9 and JRuby compatibility (don't require json gem).
117
171
 
118
- == 0.9.9 (2011 Mar 9)
172
+ 0.9.9 (2011 Mar 9)
173
+ ------------------
119
174
 
120
175
  * Add support for IP address geocoding via FreeGeoIp.net.
121
176
  * Add support for Yahoo PlaceFinder geocoding API.
@@ -130,7 +185,8 @@ Per-release changes to Geocoder.
130
185
  * DEPRECATION: <tt>fetch_address!</tt> has been superceded by +reverse_geocode+ (then save your object manually).
131
186
  * Fix: don't die when trying to get coordinates with a nil address (github.com/zmack).
132
187
 
133
- == 0.9.8 (2011 Feb 8)
188
+ 0.9.8 (2011 Feb 8)
189
+ ------------------
134
190
 
135
191
  * Include <tt>geocode:all</tt> Rake task in gem (was missing!).
136
192
  * Add <tt>Geocoder.search</tt> for access to Google's full response.
@@ -138,87 +194,105 @@ Per-release changes to Geocoder.
138
194
  * Emit warnings on Google connection problems and errors.
139
195
  * Refactor: insert Geocoder into ActiveRecord via Railtie.
140
196
 
141
- == 0.9.7 (2011 Feb 1)
197
+ 0.9.7 (2011 Feb 1)
198
+ ------------------
142
199
 
143
200
  * Add reverse geocoding (+reverse_geocoded_by+).
144
201
  * Prevent exception (uninitialized constant Geocoder::Net) when net/http not already required (github.com/sleepycat).
145
202
  * Refactor: split monolithic Geocoder module into several smaller ones.
146
203
 
147
- == 0.9.6 (2011 Jan 19)
204
+ 0.9.6 (2011 Jan 19)
205
+ -------------------
148
206
 
149
207
  * Fix incompatibility with will_paginate gem.
150
208
  * Include table names in GROUP BY clause of nearby scope to avoid ambiguity in joins (github.com/matchu).
151
209
 
152
- == 0.9.5 (2010 Oct 15)
210
+ 0.9.5 (2010 Oct 15)
211
+ -------------------
153
212
 
154
213
  * Fix broken PostgreSQL compatibility (now 100% compatible).
155
214
  * Switch from Google's XML to JSON geocoding API.
156
215
  * Separate Rails 2 and Rails 3-compatible branches.
157
216
  * Don't allow :conditions hash in 'options' argument to 'nearbys' method (was deprecated in 0.9.3).
158
217
 
159
- == 0.9.4 (2010 Aug 2)
218
+ 0.9.4 (2010 Aug 2)
219
+ ------------------
160
220
 
161
221
  * Google Maps API key no longer required (uses geocoder v3).
162
222
 
163
- == 0.9.3 (2010 Aug 2)
223
+ 0.9.3 (2010 Aug 2)
224
+ ------------------
164
225
 
165
226
  * Fix incompatibility with Rails 3 RC 1.
166
227
  * Deprecate 'options' argument to 'nearbys' method.
167
228
  * Allow inclusion of 'nearbys' in Arel method chains.
168
229
 
169
- == 0.9.2 (2010 Jun 3)
230
+ 0.9.2 (2010 Jun 3)
231
+ ------------------
170
232
 
171
233
  * Fix LIMIT clause bug in PostgreSQL (reported by github.com/kenzie).
172
234
 
173
- == 0.9.1 (2010 May 4)
235
+ 0.9.1 (2010 May 4)
236
+ ------------------
174
237
 
175
238
  * Use scope instead of named_scope in Rails 3.
176
239
 
177
- == 0.9.0 (2010 Apr 2)
240
+ 0.9.0 (2010 Apr 2)
241
+ ------------------
178
242
 
179
243
  * Fix bug in PostgreSQL support (caused "PGError: ERROR: column "distance" does not exist"), reported by github.com/developish.
180
244
 
181
- == 0.8.9 (2010 Feb 11)
245
+ 0.8.9 (2010 Feb 11)
246
+ -------------------
182
247
 
183
248
  * Add Rails 3 compatibility.
184
249
  * Avoid querying Google when query would be an empty string.
185
250
 
186
- == 0.8.8 (2009 Dec 7)
251
+ 0.8.8 (2009 Dec 7)
252
+ ------------------
187
253
 
188
254
  * Automatically select a less accurate but compatible distance algorithm when SQLite database detected (fixes SQLite incompatibility).
189
255
 
190
- == 0.8.7 (2009 Nov 4)
256
+ 0.8.7 (2009 Nov 4)
257
+ ------------------
191
258
 
192
259
  * Added Geocoder.geographic_center method.
193
260
  * Replaced _get_coordinates class method with read_coordinates instance method.
194
261
 
195
- == 0.8.6 (2009 Oct 27)
262
+ 0.8.6 (2009 Oct 27)
263
+ -------------------
196
264
 
197
265
  * The fetch_coordinates method now assigns coordinates to attributes (behaves like fetch_coordinates! used to) and fetch_coordinates! both assigns and saves the attributes.
198
266
  * Added geocode:all rake task.
199
267
 
200
- == 0.8.5 (2009 Oct 26)
268
+ 0.8.5 (2009 Oct 26)
269
+ -------------------
201
270
 
202
271
  * Avoid calling deprecated method from within Geocoder itself.
203
272
 
204
- == 0.8.4 (2009 Oct 23)
273
+ 0.8.4 (2009 Oct 23)
274
+ -------------------
205
275
 
206
276
  * Deprecate <tt>find_near</tt> class method in favor of +near+ named scope.
207
277
 
208
- == 0.8.3 (2009 Oct 23)
278
+ 0.8.3 (2009 Oct 23)
279
+ -------------------
209
280
 
210
281
  * Update Google URL query string parameter to reflect recent changes in Google's API.
211
282
 
212
- == 0.8.2 (2009 Oct 12)
283
+ 0.8.2 (2009 Oct 12)
284
+ -------------------
213
285
 
214
286
  * Allow a model's geocoder search string method to be something other than an ActiveRecord attribute.
215
287
  * Clean up documentation.
216
288
 
217
- == 0.8.1 (2009 Oct 8)
289
+ 0.8.1 (2009 Oct 8)
290
+ ------------------
218
291
 
219
292
  * Extract XML-fetching code from <tt>Geocoder.search</tt> and place in Geocoder._fetch_xml (for ease of mocking).
220
293
  * Add tests for coordinate-fetching instance methods.
221
294
 
222
- == 0.8.0 (2009 Oct 1)
295
+ 0.8.0 (2009 Oct 1)
296
+ ------------------
223
297
 
224
298
  First release.