geocoder 1.3.7 → 1.4.0

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: b3ba97fb2510ac5e0f739b4f7a11825f9d9bf277
4
- data.tar.gz: d69a73fd1c4a6536170ac28563475def5ffed69e
3
+ metadata.gz: 8a859b82bf025e96ae97b006af3874e58766556b
4
+ data.tar.gz: 00eb37dfc6a988d08e3d4a2adcb924d0a778d9fa
5
5
  SHA512:
6
- metadata.gz: a09fa3752902e9422511ea4b30b038e8b91f6a6c6ad37aad0d979864ca610b0c5e5ab80fc9b0aff94dca4bcf493056e8d84a9d1433abc3b4a6385fd1fced6ea5
7
- data.tar.gz: 77e358b416b3862952f8210f9a5752e0b1e11dc8247ed3f13966fe79c64af98fd7ef31a2b5310fb9fc36bfc98bde3330cf96baca1949229e99d159d724807856
6
+ metadata.gz: 71456df3a167a0aaa7511c4e61869519d5dd05716d7db7be38801e997525d3d257df5511a772206a7495392b2d65fcc88a5793744cf1360bc1579af83da0e227
7
+ data.tar.gz: 95faab5c456a219888ad92ba6cd64c6e27a7bc19cfd729ae2997b9e61849f247acd95f9e6c47f616530fee59d879c23b1496d83fe2d6db735c0552d858b6de6e
@@ -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.4.0 (2016 Sep 8)
7
+ -------------------
8
+ * Only consider an object geocoded if both lat and lon are present (previously was sufficient to have only one of the two) (thanks github.com/mltsy).
9
+ * Add support in :geocodio lookup for Canadian addresses (thanks github.com/bolandrm).
10
+ * Add support for SQLite extensions, if present (thanks github.com/stevecj).
11
+ * Always include Geocoder in Rack::Request, if defined (thanks github.com/wjordan).
12
+
6
13
  1.3.7 (2016 Jun 9)
7
14
  -------------------
8
15
  * Fix Ruby 1.9, 2.0 incompatibility (thanks github.com/ebouchut).
@@ -42,7 +42,14 @@ module Geocoder::Lookup
42
42
  end
43
43
 
44
44
  def reserved_result(ip)
45
- {"message" => "Input string is not a valid IP address", "code" => 401}
45
+ {
46
+ "ip" => ip,
47
+ "city" => "",
48
+ "region" => "",
49
+ "country" => "",
50
+ "loc" => "0,0",
51
+ "postal" => ""
52
+ }
46
53
  end
47
54
 
48
55
  def query_url_params(query)
@@ -15,7 +15,7 @@ module Geocoder::Lookup
15
15
  end
16
16
 
17
17
  def query_url(query)
18
- "#{protocol}://geoip.maxmind.com/geoip/v2.1/#{configured_service!}/#{URI.escape(query.sanitized_text.strip)}"
18
+ "#{protocol}://geoip.maxmind.com/geoip/v2.1/#{configured_service!}/#{query.sanitized_text.strip}"
19
19
  end
20
20
 
21
21
  private # ---------------------------------------------------------------
@@ -78,8 +78,5 @@ module Geocoder
78
78
  end
79
79
  end
80
80
 
81
- if defined?(ActionDispatch::Request)
82
- ActionDispatch::Request.__send__(:include, Geocoder::Request)
83
- elsif defined?(Rack::Request)
84
- Rack::Request.__send__(:include, Geocoder::Request)
85
- end
81
+ ActionDispatch::Request.__send__(:include, Geocoder::Request) if defined?(ActionDispatch::Request)
82
+ Rack::Request.__send__(:include, Geocoder::Request) if defined?(Rack::Request)
@@ -24,16 +24,24 @@ module Geocoder::Result
24
24
  alias_method :state_code, :state
25
25
 
26
26
  def zip
27
- address_components["zip"]
27
+ # Postal code is not returned for Canada geocode results
28
+ address_components["zip"] || ""
28
29
  end
29
30
  alias_method :postal_code, :zip
30
31
 
31
32
  def country
32
- "United States" # Geocodio only supports the US
33
+ # Geocodio supports US and Canada, however they don't return the full
34
+ # country name.
35
+
36
+ if country_code == "CA"
37
+ "Canada"
38
+ else
39
+ "United States"
40
+ end
33
41
  end
34
42
 
35
43
  def country_code
36
- "US" # Geocodio only supports the US
44
+ address_components['country']
37
45
  end
38
46
 
39
47
  def city
@@ -8,7 +8,7 @@ module Geocoder::Result
8
8
  end
9
9
 
10
10
  def coordinates
11
- @data['loc'].split(",").map(&:to_f)
11
+ @data['loc'].to_s.split(",").map(&:to_f)
12
12
  end
13
13
 
14
14
  def city
@@ -36,7 +36,7 @@ module Geocoder::Result
36
36
  end
37
37
 
38
38
  def self.response_attributes
39
- %w['ip', 'region', 'postal']
39
+ %w(ip region postal)
40
40
  end
41
41
 
42
42
  response_attributes.each do |a|
@@ -4,8 +4,8 @@ module Geocoder
4
4
 
5
5
  ##
6
6
  # Distance calculation for use with a database that supports POWER(),
7
- # SQRT(), PI(), and trigonometric functions SIN(), COS(), ASIN(),
8
- # ATAN2(), DEGREES(), and RADIANS().
7
+ # SQRT(), PI(), and trigonometric functions SIN(), COS(), ASIN(),
8
+ # ATAN2().
9
9
  #
10
10
  # Based on the excellent tutorial at:
11
11
  # http://www.scribd.com/doc/2569355/Geo-Distance-Search-with-MySQL
@@ -59,6 +59,9 @@ module Geocoder
59
59
  # and an options hash which must include a :bearing value
60
60
  # (:linear or :spherical).
61
61
  #
62
+ # For use with a database that supports MOD() and trigonometric functions
63
+ # SIN(), COS(), ASIN(), ATAN2().
64
+ #
62
65
  # Based on:
63
66
  # http://www.beginningspatial.com/calculating_bearing_one_point_another
64
67
  #
@@ -138,7 +138,7 @@ module Geocoder::Store
138
138
  ]
139
139
  bounding_box_conditions = Geocoder::Sql.within_bounding_box(*args)
140
140
 
141
- if using_sqlite?
141
+ if using_unextended_sqlite?
142
142
  conditions = bounding_box_conditions
143
143
  else
144
144
  min_radius = options.fetch(:min_radius, 0).to_f
@@ -160,7 +160,7 @@ module Geocoder::Store
160
160
  # capabilities (trig functions?).
161
161
  #
162
162
  def distance_sql(latitude, longitude, options = {})
163
- method_prefix = using_sqlite? ? "approx" : "full"
163
+ method_prefix = using_unextended_sqlite? ? "approx" : "full"
164
164
  Geocoder::Sql.send(
165
165
  method_prefix + "_distance",
166
166
  latitude, longitude,
@@ -179,7 +179,7 @@ module Geocoder::Store
179
179
  options[:bearing] = Geocoder.config.distances
180
180
  end
181
181
  if options[:bearing]
182
- method_prefix = using_sqlite? ? "approx" : "full"
182
+ method_prefix = using_unextended_sqlite? ? "approx" : "full"
183
183
  Geocoder::Sql.send(
184
184
  method_prefix + "_bearing",
185
185
  latitude, longitude,
@@ -225,8 +225,20 @@ module Geocoder::Store
225
225
  conditions
226
226
  end
227
227
 
228
+ def using_unextended_sqlite?
229
+ using_sqlite? && !using_sqlite_with_extensions?
230
+ end
231
+
228
232
  def using_sqlite?
229
- connection.adapter_name.match(/sqlite/i)
233
+ !!connection.adapter_name.match(/sqlite/i)
234
+ end
235
+
236
+ def using_sqlite_with_extensions?
237
+ connection.adapter_name.match(/sqlite/i) &&
238
+ defined?(::SqliteExt) &&
239
+ %W(MOD POWER SQRT PI SIN COS ASIN ATAN2).all?{ |fn_name|
240
+ connection.raw_connection.function_created?(fn_name)
241
+ }
230
242
  end
231
243
 
232
244
  def using_postgres?
@@ -244,7 +256,7 @@ module Geocoder::Store
244
256
  # Value which can be passed to where() to produce no results.
245
257
  #
246
258
  def false_condition
247
- using_sqlite? ? 0 : "false"
259
+ using_unextended_sqlite? ? 0 : "false"
248
260
  end
249
261
 
250
262
  ##
@@ -6,7 +6,7 @@ module Geocoder
6
6
  # Is this object geocoded? (Does it have latitude and longitude?)
7
7
  #
8
8
  def geocoded?
9
- to_coordinates.compact.size > 0
9
+ to_coordinates.compact.size == 2
10
10
  end
11
11
 
12
12
  ##
@@ -1,3 +1,3 @@
1
1
  module Geocoder
2
- VERSION = "1.3.7"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -7,7 +7,7 @@ namespace :geocode do
7
7
  reverse = ENV['REVERSE'] || ENV['reverse']
8
8
  raise "Please specify a CLASS (model)" unless class_name
9
9
  klass = class_from_string(class_name)
10
- batch = batch.to_i unless batch.nil?
10
+ batch = (batch.to_i unless batch.nil?) || 1000
11
11
  reverse = false unless reverse.to_s.downcase == 'true'
12
12
 
13
13
  if reverse
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.3.7
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Reisner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-09 00:00:00.000000000 Z
11
+ date: 2016-09-08 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,