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 +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/geocoder/lookups/ipinfo_io.rb +8 -1
- data/lib/geocoder/lookups/maxmind_geoip2.rb +1 -1
- data/lib/geocoder/request.rb +2 -5
- data/lib/geocoder/results/geocodio.rb +11 -3
- data/lib/geocoder/results/ipinfo_io.rb +2 -2
- data/lib/geocoder/sql.rb +5 -2
- data/lib/geocoder/stores/active_record.rb +17 -5
- data/lib/geocoder/stores/base.rb +1 -1
- data/lib/geocoder/version.rb +1 -1
- data/lib/tasks/geocoder.rake +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a859b82bf025e96ae97b006af3874e58766556b
|
4
|
+
data.tar.gz: 00eb37dfc6a988d08e3d4a2adcb924d0a778d9fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71456df3a167a0aaa7511c4e61869519d5dd05716d7db7be38801e997525d3d257df5511a772206a7495392b2d65fcc88a5793744cf1360bc1579af83da0e227
|
7
|
+
data.tar.gz: 95faab5c456a219888ad92ba6cd64c6e27a7bc19cfd729ae2997b9e61849f247acd95f9e6c47f616530fee59d879c23b1496d83fe2d6db735c0552d858b6de6e
|
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.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
|
-
{
|
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!}/#{
|
18
|
+
"#{protocol}://geoip.maxmind.com/geoip/v2.1/#{configured_service!}/#{query.sanitized_text.strip}"
|
19
19
|
end
|
20
20
|
|
21
21
|
private # ---------------------------------------------------------------
|
data/lib/geocoder/request.rb
CHANGED
@@ -78,8 +78,5 @@ module Geocoder
|
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
-
if defined?(ActionDispatch::Request)
|
82
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
39
|
+
%w(ip region postal)
|
40
40
|
end
|
41
41
|
|
42
42
|
response_attributes.each do |a|
|
data/lib/geocoder/sql.rb
CHANGED
@@ -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()
|
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
|
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 =
|
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 =
|
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
|
-
|
259
|
+
using_unextended_sqlite? ? 0 : "false"
|
248
260
|
end
|
249
261
|
|
250
262
|
##
|
data/lib/geocoder/stores/base.rb
CHANGED
data/lib/geocoder/version.rb
CHANGED
data/lib/tasks/geocoder.rake
CHANGED
@@ -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.
|
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-
|
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,
|