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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 69826a3c50884c70a7a937f80f1280f234687e2f
4
- data.tar.gz: 4bcdee80b4db4db6c7efbd2886d9fab96b4976bf
3
+ metadata.gz: 80ea51ef32a14fb44a364344b6475fecbf9713df
4
+ data.tar.gz: 1a6900cbcfc8cd21151da45fc55f94805c6adc51
5
5
  SHA512:
6
- metadata.gz: c9d0cbaa046ebc593590340937a29b687e98107ea87606b4fc10ab3bd000376471f4b940f3848bd68a75e1e8f273843e29278ca4449e8ce5219a46ed9daf468e
7
- data.tar.gz: ed245fd8affec37d6f60f54bedf3fb35a704cf6f4f134537bdcac5356bd245c64df0f707b690990585deae794d24bf30c16aaa0f754ee52b8a09c2b79236a509
6
+ metadata.gz: ac94efc831b73cb9639fa49fdc7957d95de7d3b8250b4477744141267d30ead2315397c5ffe9b73df17bd86a51bdebf736a23bf46dd2f552d16e215329dc0e01
7
+ data.tar.gz: 22bc25f4cd0c191ed23df83716efa803ab4d0dd21c12717dbe6dfee99917bdf21850e4ec6e2c4e0a1f79e57d1d75b4154d3bccfb1f4c1f490358d68ce50d9d1e
@@ -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`, `:google_premier`)
384
+ #### Google (`:google`)
385
385
 
386
- * **API key**: required for Premier, optional for the free service (if using the free service with API key, https is required. Add `:use_https => true` to `Geocoder.configure`)
387
- * **Key signup**: https://developers.google.com/maps/documentation/business/
388
- * **Quota**: 2,500 requests/day, 100,000 with Google Maps API Premier
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**: ar, eu, bg, bn, ca, cs, da, de, el, en, en-AU, en-GB, es, eu, fa, fi, fil, fr, gl, gu, hi, hr, hu, id, it, iw, ja, kn, ko, lt, lv, ml, mr, nl, no, pl, pt, pt-BR, pt-PT, ro, ru, sk, sl, sr, sv, tl, ta, te, th, tr, uk, vi, zh-CN, zh-TW (see http://spreadsheets.google.com/pub?key=p9pdwsai2hDMsLkXsoM05KQ&gid=1)
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**: http://code.google.com/apis/maps/documentation/geocoding/#JSON
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
- * **Notes**: To use Google Premier set `Geocoder.configure(:lookup => :google_premier, :api_key => [key, client, channel])`.
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 CC-BY-SA (you must provide attribution).
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 CC-BY-SA or (you must provide attribution).
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**: no
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**: no
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
 
@@ -1,5 +1,6 @@
1
1
  require "geocoder/configuration"
2
2
  require "geocoder/logger"
3
+ require "geocoder/kernel_logger"
3
4
  require "geocoder/query"
4
5
  require "geocoder/calculations"
5
6
  require "geocoder/exceptions"
@@ -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);
@@ -29,4 +29,7 @@ module Geocoder
29
29
  class ServiceUnavailable < Error
30
30
  end
31
31
 
32
+ class LookupTimeout < ::Timeout::Error
33
+ end
34
+
32
35
  end
@@ -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
@@ -18,14 +18,11 @@ module Geocoder
18
18
  }
19
19
 
20
20
  def log(level, message)
21
- return nil unless valid_level?(level)
22
-
23
- logger = Geocoder.config[:logger]
24
-
25
- if logger == :kernel
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 kernel_log(level, message)
39
- case level
40
- when :debug, :info
41
- puts message
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
- [:debug, :info, :warn, :error, :fatal].include? level
44
+ SEVERITY.keys.include?(level)
53
45
  end
54
46
  end
55
47
  end
@@ -13,7 +13,7 @@ module Geocoder::Lookup
13
13
  end
14
14
 
15
15
  def query_url(query)
16
- "http://api.map.baidu.com/geocoder/v2/?" + url_query_string(query)
16
+ "#{protocol}://api.map.baidu.com/geocoder/v2/?" + url_query_string(query)
17
17
  end
18
18
 
19
19
  # HTTP only
@@ -13,7 +13,7 @@ module Geocoder::Lookup
13
13
  end
14
14
 
15
15
  def query_url(query)
16
- "http://api.map.baidu.com/location/ip?" + url_query_string(query)
16
+ "#{protocol}://api.map.baidu.com/location/ip?" + url_query_string(query)
17
17
  end
18
18
 
19
19
  # HTTP only
@@ -271,20 +271,20 @@ module Geocoder
271
271
  # return the response object.
272
272
  #
273
273
  def make_api_request(query)
274
- timeout(configuration.timeout) do
275
- uri = URI.parse(query_url(query))
276
- Geocoder.log(:debug, "Geocoder: HTTP request being made for #{uri.to_s}")
277
- http_client.start(uri.host, uri.port, use_ssl: use_ssl?) do |client|
278
- req = Net::HTTP::Get.new(uri.request_uri, configuration.http_headers)
279
- if configuration.basic_auth[:user] and configuration.basic_auth[:password]
280
- req.basic_auth(
281
- configuration.basic_auth[:user],
282
- configuration.basic_auth[:password]
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
- "http://#{configuration.api_key}@geocoder.us/member/service/csv/geocode?" + url_query_string(query)
17
+ "#{protocol}://#{configuration.api_key}@geocoder.us/member/service/csv/geocode?" + url_query_string(query)
14
18
  else
15
- "http://geocoder.us/service/csv/geocode?" + url_query_string(query)
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
@@ -9,7 +9,7 @@ module Geocoder::Lookup
9
9
  end
10
10
 
11
11
  def query_url(query)
12
- "http://www.telize.com/geoip/#{query.sanitized_text}"
12
+ "#{protocol}://www.telize.com/geoip/#{query.sanitized_text}"
13
13
  end
14
14
 
15
15
  # currently doesn't support HTTPS
@@ -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).
@@ -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).
@@ -1,3 +1,3 @@
1
1
  module Geocoder
2
- VERSION = "1.2.9"
2
+ VERSION = "1.2.10"
3
3
  end
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.9
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-06-12 00:00:00.000000000 Z
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