geocoder 1.2.9 → 1.2.10
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +21 -14
- data/lib/geocoder.rb +1 -0
- data/lib/geocoder/configuration.rb +3 -1
- data/lib/geocoder/exceptions.rb +3 -0
- data/lib/geocoder/kernel_logger.rb +25 -0
- data/lib/geocoder/logger.rb +13 -21
- data/lib/geocoder/lookups/baidu.rb +1 -1
- data/lib/geocoder/lookups/baidu_ip.rb +1 -1
- data/lib/geocoder/lookups/base.rb +12 -12
- data/lib/geocoder/lookups/geocoder_us.rb +6 -2
- data/lib/geocoder/lookups/google.rb +9 -0
- data/lib/geocoder/lookups/telize.rb +1 -1
- data/lib/geocoder/lookups/yandex.rb +4 -0
- data/lib/geocoder/stores/active_record.rb +11 -0
- data/lib/geocoder/stores/base.rb +0 -11
- data/lib/geocoder/stores/mongo_base.rb +13 -0
- data/lib/geocoder/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80ea51ef32a14fb44a364344b6475fecbf9713df
|
4
|
+
data.tar.gz: 1a6900cbcfc8cd21151da45fc55f94805c6adc51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac94efc831b73cb9639fa49fdc7957d95de7d3b8250b4477744141267d30ead2315397c5ffe9b73df17bd86a51bdebf736a23bf46dd2f552d16e215329dc0e01
|
7
|
+
data.tar.gz: 22bc25f4cd0c191ed23df83716efa803ab4d0dd21c12717dbe6dfee99917bdf21850e4ec6e2c4e0a1f79e57d1d75b4154d3bccfb1f4c1f490358d68ce50d9d1e
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,13 @@ Changelog
|
|
3
3
|
|
4
4
|
Major changes to Geocoder for each release. Please see the Git log for complete list of changes.
|
5
5
|
|
6
|
+
1.2.10 (2015 Aug 7)
|
7
|
+
-----------------
|
8
|
+
* Force Yandex to use HTTPS (thanks github.com/donbobka).
|
9
|
+
* Force :google to use HTTPS if API key set.
|
10
|
+
* Fix out-of-the-box verbosity issues (GH #881).
|
11
|
+
* Deprecate .near and #nearbys for MongoDB-backed models.
|
12
|
+
|
6
13
|
1.2.9 (2015 Jun 12)
|
7
14
|
-------------------
|
8
15
|
* Don't cache unsuccessful responses from Bing (thanks github.com/peteb).
|
data/README.md
CHANGED
@@ -381,19 +381,26 @@ The above combines global and service-specific options and could be useful if yo
|
|
381
381
|
|
382
382
|
The following is a comparison of the supported geocoding APIs. The "Limitations" listed for each are a very brief and incomplete summary of some special limitations beyond basic data source attribution. Please read the official Terms of Service for a service before using it.
|
383
383
|
|
384
|
-
#### Google (`:google
|
384
|
+
#### Google (`:google`)
|
385
385
|
|
386
|
-
* **API key**:
|
387
|
-
* **Key signup**: https://developers.google.com/
|
388
|
-
* **Quota**: 2,500 requests/
|
386
|
+
* **API key**: optional, but quota is higher if key is used (use of key requires HTTPS so be sure to set: `:use_https => true` in `Geocoder.configure`)
|
387
|
+
* **Key signup**: https://console.developers.google.com//flows/enableapi?apiid=geocoding_backend&keyType=SERVER_SIDE
|
388
|
+
* **Quota**: 2,500 requests/24 hrs, 5 requests/second
|
389
389
|
* **Region**: world
|
390
|
-
* **SSL support**: yes
|
391
|
-
* **Languages**:
|
390
|
+
* **SSL support**: yes (required if key is used)
|
391
|
+
* **Languages**: see https://developers.google.com/maps/faq#languagesupport
|
392
392
|
* **Extra options**: `:bounds` - pass SW and NE coordinates as an array of two arrays to bias results towards a viewport
|
393
|
-
* **Documentation**:
|
393
|
+
* **Documentation**: https://developers.google.com/maps/documentation/geocoding/intro
|
394
394
|
* **Terms of Service**: http://code.google.com/apis/maps/terms.html#section_10_12
|
395
395
|
* **Limitations**: "You must not use or display the Content without a corresponding Google map, unless you are explicitly permitted to do so in the Maps APIs Documentation, or through written permission from Google." "You must not pre-fetch, cache, or store any Content, except that you may store: (i) limited amounts of Content for the purpose of improving the performance of your Maps API Implementation..."
|
396
|
-
|
396
|
+
|
397
|
+
#### Google Maps API for Work (`:google_premier`)
|
398
|
+
|
399
|
+
Similar to `:google`, with the following differences:
|
400
|
+
|
401
|
+
* **API key**: required, plus client and channel (set `Geocoder.configure(:lookup => :google_premier, :api_key => [key, client, channel])`)
|
402
|
+
* **Key signup**: https://developers.google.com/maps/documentation/business/
|
403
|
+
* **Quota**: 100,000 requests/24 hrs, 10 requests/second
|
397
404
|
|
398
405
|
#### Google Places Details (`:google_places_details`)
|
399
406
|
|
@@ -442,7 +449,7 @@ The [Google Places Details API](https://developers.google.com/places/documentati
|
|
442
449
|
* **Languages**: ?
|
443
450
|
* **Documentation**: http://wiki.openstreetmap.org/wiki/Nominatim
|
444
451
|
* **Terms of Service**: http://wiki.openstreetmap.org/wiki/Nominatim_usage_policy
|
445
|
-
* **Limitations**: Please limit request rate to 1 per second and include your contact information in User-Agent headers (eg: `Geocoder.configure(:http_headers => { "User-Agent" => "your contact info" })`). Data licensed under
|
452
|
+
* **Limitations**: Please limit request rate to 1 per second and include your contact information in User-Agent headers (eg: `Geocoder.configure(:http_headers => { "User-Agent" => "your contact info" })`). [Data licensed under Open Database License (ODbL) (you must provide attribution).](http://www.openstreetmap.org/copyright)
|
446
453
|
|
447
454
|
#### OpenCageData (`:opencagedata`)
|
448
455
|
|
@@ -453,14 +460,14 @@ The [Google Places Details API](https://developers.google.com/places/documentati
|
|
453
460
|
* **SSL support**: yes
|
454
461
|
* **Languages**: worldwide
|
455
462
|
* **Documentation**: http://geocoder.opencagedata.com/api.html
|
456
|
-
* **Limitations**: Data licensed under
|
463
|
+
* **Limitations**: [Data licensed under Open Database License (ODbL) (you must provide attribution).](http://www.openstreetmap.org/copyright)
|
457
464
|
|
458
465
|
#### Yandex (`:yandex`)
|
459
466
|
|
460
467
|
* **API key**: none
|
461
468
|
* **Quota**: 25000 requests / day
|
462
469
|
* **Region**: world
|
463
|
-
* **SSL support**:
|
470
|
+
* **SSL support**: HTTPS only
|
464
471
|
* **Languages**: Russian, Belarusian, Ukrainian, English, Turkish (only for maps of Turkey)
|
465
472
|
* **Documentation**: http://api.yandex.com.tr/maps/doc/intro/concepts/intro.xml
|
466
473
|
* **Terms of Service**: http://api.yandex.com.tr/maps/doc/intro/concepts/intro.xml#rules
|
@@ -567,13 +574,13 @@ Data Science Toolkit provides an API whose reponse format is like Google's but w
|
|
567
574
|
#### Geocodio (`:geocodio`)
|
568
575
|
|
569
576
|
* **API key**: required
|
570
|
-
* **Quota**: 2,500 free requests/day then purchase $.001 for each
|
577
|
+
* **Quota**: 2,500 free requests/day then purchase $.001 for each, also has volume pricing and plans
|
571
578
|
* **Region**: US
|
572
|
-
* **SSL support**:
|
579
|
+
* **SSL support**: yes
|
573
580
|
* **Languages**: en
|
574
581
|
* **Documentation**: http://geocod.io/docs
|
575
582
|
* **Terms of Service**: http://geocod.io/terms-of-use
|
576
|
-
* **Limitations**:
|
583
|
+
* **Limitations**: No restrictions on use
|
577
584
|
|
578
585
|
#### SmartyStreets (`:smarty_streets`)
|
579
586
|
|
data/lib/geocoder.rb
CHANGED
@@ -57,7 +57,8 @@ module Geocoder
|
|
57
57
|
:units,
|
58
58
|
:distances,
|
59
59
|
:basic_auth,
|
60
|
-
:logger
|
60
|
+
:logger,
|
61
|
+
:kernel_logger_level
|
61
62
|
]
|
62
63
|
|
63
64
|
attr_accessor :data
|
@@ -100,6 +101,7 @@ module Geocoder
|
|
100
101
|
@data[:cache_prefix] = "geocoder:" # prefix (string) to use for all cache keys
|
101
102
|
@data[:basic_auth] = {} # user and password for basic auth ({:user => "user", :password => "password"})
|
102
103
|
@data[:logger] = :kernel # :kernel or Logger instance
|
104
|
+
@data[:kernel_logger_level] = ::Logger::WARN # log level, if kernel logger is used
|
103
105
|
|
104
106
|
# exceptions that should not be rescued by default
|
105
107
|
# (if you want to implement custom error handling);
|
data/lib/geocoder/exceptions.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Geocoder
|
2
|
+
class KernelLogger
|
3
|
+
include Singleton
|
4
|
+
|
5
|
+
def add(level, message)
|
6
|
+
return unless log_message_at_level?(level)
|
7
|
+
case level
|
8
|
+
when ::Logger::DEBUG, ::Logger::INFO
|
9
|
+
puts message
|
10
|
+
when ::Logger::WARN
|
11
|
+
warn message
|
12
|
+
when ::Logger::ERROR
|
13
|
+
raise message
|
14
|
+
when ::Logger::FATAL
|
15
|
+
fail message
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private # ----------------------------------------------------------------
|
20
|
+
|
21
|
+
def log_message_at_level?(level)
|
22
|
+
level >= Geocoder.config.kernel_logger_level
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/geocoder/logger.rb
CHANGED
@@ -18,14 +18,11 @@ module Geocoder
|
|
18
18
|
}
|
19
19
|
|
20
20
|
def log(level, message)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
kernel_log(level, message)
|
27
|
-
elsif logger.kind_of? ::Logger
|
28
|
-
logger.add(SEVERITY[level], message)
|
21
|
+
unless valid_level?(level)
|
22
|
+
raise StandardError, "Geocoder tried to log a message with an invalid log level."
|
23
|
+
end
|
24
|
+
if current_logger.respond_to? :add
|
25
|
+
current_logger.add(SEVERITY[level], message)
|
29
26
|
else
|
30
27
|
raise Geocoder::ConfigurationError, "Please specify valid logger for Geocoder. " +
|
31
28
|
"Logger specified must be :kernel or must respond to `add(level, message)`."
|
@@ -33,23 +30,18 @@ module Geocoder
|
|
33
30
|
nil
|
34
31
|
end
|
35
32
|
|
36
|
-
private
|
37
|
-
|
38
|
-
def
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
when :warn
|
43
|
-
warn message
|
44
|
-
when :error
|
45
|
-
raise message
|
46
|
-
when :fatal
|
47
|
-
fail message
|
33
|
+
private # ----------------------------------------------------------------
|
34
|
+
|
35
|
+
def current_logger
|
36
|
+
logger = Geocoder.config[:logger]
|
37
|
+
if logger == :kernel
|
38
|
+
logger = Geocoder::KernelLogger.instance
|
48
39
|
end
|
40
|
+
logger
|
49
41
|
end
|
50
42
|
|
51
43
|
def valid_level?(level)
|
52
|
-
|
44
|
+
SEVERITY.keys.include?(level)
|
53
45
|
end
|
54
46
|
end
|
55
47
|
end
|
@@ -271,20 +271,20 @@ module Geocoder
|
|
271
271
|
# return the response object.
|
272
272
|
#
|
273
273
|
def make_api_request(query)
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
)
|
284
|
-
end
|
285
|
-
client.request(req)
|
274
|
+
uri = URI.parse(query_url(query))
|
275
|
+
Geocoder.log(:debug, "Geocoder: HTTP request being made for #{uri.to_s}")
|
276
|
+
http_client.start(uri.host, uri.port, use_ssl: use_ssl?, open_timeout: configuration.timeout, read_timeout: configuration.timeout) do |client|
|
277
|
+
req = Net::HTTP::Get.new(uri.request_uri, configuration.http_headers)
|
278
|
+
if configuration.basic_auth[:user] and configuration.basic_auth[:password]
|
279
|
+
req.basic_auth(
|
280
|
+
configuration.basic_auth[:user],
|
281
|
+
configuration.basic_auth[:password]
|
282
|
+
)
|
286
283
|
end
|
284
|
+
client.request(req)
|
287
285
|
end
|
286
|
+
rescue Net::OpenTimeout, Net::ReadTimeout
|
287
|
+
raise Geocoder::LookupTimeout
|
288
288
|
end
|
289
289
|
|
290
290
|
def use_ssl?
|
@@ -8,11 +8,15 @@ module Geocoder::Lookup
|
|
8
8
|
"Geocoder.us"
|
9
9
|
end
|
10
10
|
|
11
|
+
def supported_protocols
|
12
|
+
[:http]
|
13
|
+
end
|
14
|
+
|
11
15
|
def query_url(query)
|
12
16
|
if configuration.api_key
|
13
|
-
"
|
17
|
+
"#{protocol}://#{configuration.api_key}@geocoder.us/member/service/csv/geocode?" + url_query_string(query)
|
14
18
|
else
|
15
|
-
"
|
19
|
+
"#{protocol}://geocoder.us/service/csv/geocode?" + url_query_string(query)
|
16
20
|
end
|
17
21
|
end
|
18
22
|
|
@@ -12,6 +12,15 @@ module Geocoder::Lookup
|
|
12
12
|
"http://maps.google.com/maps?q=#{coordinates.join(',')}"
|
13
13
|
end
|
14
14
|
|
15
|
+
def supported_protocols
|
16
|
+
# Google requires HTTPS if an API key is used.
|
17
|
+
if configuration.api_key
|
18
|
+
[:https]
|
19
|
+
else
|
20
|
+
[:http, :https]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
15
24
|
def query_url(query)
|
16
25
|
"#{protocol}://maps.googleapis.com/maps/api/geocode/json?" + url_query_string(query)
|
17
26
|
end
|
@@ -15,6 +15,10 @@ module Geocoder::Lookup
|
|
15
15
|
def query_url(query)
|
16
16
|
"#{protocol}://geocode-maps.yandex.ru/1.x/?" + url_query_string(query)
|
17
17
|
end
|
18
|
+
|
19
|
+
def supported_protocols
|
20
|
+
[:https]
|
21
|
+
end
|
18
22
|
|
19
23
|
private # ---------------------------------------------------------------
|
20
24
|
|
@@ -251,6 +251,17 @@ module Geocoder::Store
|
|
251
251
|
end
|
252
252
|
end
|
253
253
|
|
254
|
+
##
|
255
|
+
# Get nearby geocoded objects.
|
256
|
+
# Takes the same options hash as the near class method (scope).
|
257
|
+
# Returns nil if the object is not geocoded.
|
258
|
+
#
|
259
|
+
def nearbys(radius = 20, options = {})
|
260
|
+
return nil unless geocoded?
|
261
|
+
options.merge!(:exclude => self) unless send(self.class.primary_key).nil?
|
262
|
+
self.class.near(self, radius, options)
|
263
|
+
end
|
264
|
+
|
254
265
|
##
|
255
266
|
# Look up coordinates and assign to +latitude+ and +longitude+ attributes
|
256
267
|
# (or other as specified in +geocoded_by+). Returns coordinates (array).
|
data/lib/geocoder/stores/base.rb
CHANGED
@@ -55,17 +55,6 @@ module Geocoder
|
|
55
55
|
point, to_coordinates, options)
|
56
56
|
end
|
57
57
|
|
58
|
-
##
|
59
|
-
# Get nearby geocoded objects.
|
60
|
-
# Takes the same options hash as the near class method (scope).
|
61
|
-
# Returns nil if the object is not geocoded.
|
62
|
-
#
|
63
|
-
def nearbys(radius = 20, options = {})
|
64
|
-
return nil unless geocoded?
|
65
|
-
options.merge!(:exclude => self) unless send(self.class.primary_key).nil?
|
66
|
-
self.class.near(self, radius, options)
|
67
|
-
end
|
68
|
-
|
69
58
|
##
|
70
59
|
# Look up coordinates and assign to +latitude+ and +longitude+ attributes
|
71
60
|
# (or other as specified in +geocoded_by+). Returns coordinates (array).
|
@@ -13,6 +13,7 @@ module Geocoder::Store
|
|
13
13
|
}
|
14
14
|
|
15
15
|
scope :near, lambda{ |location, *args|
|
16
|
+
warn "DEPRECATION WARNING: The .near method will be removed for MongoDB-backed models in Geocoder 1.3.0. Please use MongoDB's built-in query language instead."
|
16
17
|
coords = Geocoder::Calculations.extract_coordinates(location)
|
17
18
|
|
18
19
|
# no results if no lat/lon given
|
@@ -55,6 +56,18 @@ module Geocoder::Store
|
|
55
56
|
coords.is_a?(Array) ? coords.reverse : []
|
56
57
|
end
|
57
58
|
|
59
|
+
##
|
60
|
+
# Get nearby geocoded objects.
|
61
|
+
# Takes the same options hash as the near class method (scope).
|
62
|
+
# Returns nil if the object is not geocoded.
|
63
|
+
#
|
64
|
+
def nearbys(radius = 20, options = {})
|
65
|
+
warn "DEPRECATION WARNING: The #nearbys method will be removed for MongoDB-backed models in Geocoder 1.3.0. Please use MongoDB's built-in query language instead."
|
66
|
+
return nil unless geocoded?
|
67
|
+
options.merge!(:exclude => self) unless send(self.class.primary_key).nil?
|
68
|
+
self.class.near(self, radius, options)
|
69
|
+
end
|
70
|
+
|
58
71
|
##
|
59
72
|
# Look up coordinates and assign to +latitude+ and +longitude+ attributes
|
60
73
|
# (or other as specified in +geocoded_by+). Returns coordinates (array).
|
data/lib/geocoder/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geocoder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Reisner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Provides object geocoding (by street or IP address), reverse geocoding
|
14
14
|
(coordinates to street address), distance queries for ActiveRecord and Mongoid,
|
@@ -43,6 +43,7 @@ files:
|
|
43
43
|
- lib/geocoder/configuration_hash.rb
|
44
44
|
- lib/geocoder/exceptions.rb
|
45
45
|
- lib/geocoder/ip_address.rb
|
46
|
+
- lib/geocoder/kernel_logger.rb
|
46
47
|
- lib/geocoder/logger.rb
|
47
48
|
- lib/geocoder/lookup.rb
|
48
49
|
- lib/geocoder/lookups/baidu.rb
|