geocoder 1.4.5 → 1.4.6
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 +5 -0
- data/README.md +16 -3
- data/lib/geocoder/lookup.rb +1 -0
- data/lib/geocoder/lookups/bing.rb +5 -0
- data/lib/geocoder/lookups/geocodio.rb +1 -1
- data/lib/geocoder/lookups/google_premier.rb +1 -1
- data/lib/geocoder/lookups/ipdata_co.rb +57 -0
- data/lib/geocoder/lookups/location_iq.rb +4 -0
- data/lib/geocoder/lookups/nominatim.rb +5 -1
- data/lib/geocoder/request.rb +12 -1
- data/lib/geocoder/results/ipdata_co.rb +45 -0
- data/lib/geocoder/stores/active_record.rb +2 -2
- data/lib/geocoder/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 581d1e425470b88287f22a34b3290577ae9b2f3c
|
4
|
+
data.tar.gz: bec7133e542e5da09e6f66828fce5b793c599db3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b81c979316bfafed7ccc6806ac7eb0441a4a94103769132f01a4614c5629ac2c0ae555cc2cfa6311bca85c4f9791636db2d62eeafd1a031722ca1b2cb6fec28a
|
7
|
+
data.tar.gz: 68e7fd710e2b3558dc25f5714cf8d69b9ed3fbcfc1ab7811a1c692e4a1533bdc0192efd121ae4812c91294d269f123fdd96793cf1ecac1930e8101236b6a1eef
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,11 @@ 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.6 (2018 Feb 28)
|
7
|
+
-------------------
|
8
|
+
* Add support for :ipdata_co lookup (thanks github.com/roschaefer).
|
9
|
+
* Update for Rails 5.2 compatibility (thanks github.com/stevenharman).
|
10
|
+
|
6
11
|
1.4.5 (2017 Nov 29)
|
7
12
|
-------------------
|
8
13
|
* Add support for :pickpoint lookup (thanks github.com/cylon-v).
|
data/README.md
CHANGED
@@ -662,11 +662,11 @@ Data Science Toolkit provides an API whose response format is like Google's but
|
|
662
662
|
|
663
663
|
* **API key**: required
|
664
664
|
* **Quota**: 2,500 free requests/day then purchase $0.0005 for each, also has volume pricing and plans.
|
665
|
-
* **Region**:
|
665
|
+
* **Region**: USA & Canada
|
666
666
|
* **SSL support**: yes
|
667
667
|
* **Languages**: en
|
668
|
-
* **Documentation**:
|
669
|
-
* **Terms of Service**:
|
668
|
+
* **Documentation**: https://geocod.io/docs/
|
669
|
+
* **Terms of Service**: https://geocod.io/terms-of-use/
|
670
670
|
* **Limitations**: No restrictions on use
|
671
671
|
|
672
672
|
#### SmartyStreets (`:smarty_streets`)
|
@@ -856,6 +856,18 @@ This uses the PostcodeAnywhere UK Geocode service, this will geocode any string
|
|
856
856
|
* **Documentation**: https://db-ip.com/api/doc.php
|
857
857
|
* **Terms of Service**: https://db-ip.com/tos.php
|
858
858
|
|
859
|
+
#### Ipdata.co (`:ipdata_co`)
|
860
|
+
|
861
|
+
* **API key**: optional, see: https://ipdata.co/pricing.html
|
862
|
+
* **Quota**: 1500/day (up to 600k with paid API keys)
|
863
|
+
* **Region**: world
|
864
|
+
* **SSL support**: yes
|
865
|
+
* **Languages**: English
|
866
|
+
* **Documentation**: https://ipdata.co/docs.html
|
867
|
+
* **Terms of Service**: https://ipdata.co/terms.html
|
868
|
+
* **Limitations**: ?
|
869
|
+
|
870
|
+
|
859
871
|
### IP Address Local Database Services
|
860
872
|
|
861
873
|
#### MaxMind Local (`:maxmind_local`) - EXPERIMENTAL
|
@@ -1067,6 +1079,7 @@ Notes:
|
|
1067
1079
|
|
1068
1080
|
- Keys must be strings not symbols when calling `add_stub` or `set_default_stub`. For example `'latitude' =>` not `:latitude =>`.
|
1069
1081
|
- To clear stubs (e.g. prior to another spec), use `Geocoder::Lookup::Test.reset`. This will clear all stubs _including the default stub_.
|
1082
|
+
- The stubbed result objects returned by the Test lookup do not support all the methods real result objects do. If you need to test interaction with real results it may be better to use an external stubbing tool and something like WebMock or VCR to prevent network calls.
|
1070
1083
|
|
1071
1084
|
|
1072
1085
|
Command Line Interface
|
data/lib/geocoder/lookup.rb
CHANGED
@@ -44,6 +44,11 @@ module Geocoder::Lookup
|
|
44
44
|
return doc['resourceSets'].first['estimatedTotal'] > 0 ? doc['resourceSets'].first['resources'] : []
|
45
45
|
elsif doc['statusCode'] == 401 and doc["authenticationResultCode"] == "InvalidCredentials"
|
46
46
|
raise_error(Geocoder::InvalidApiKey) || Geocoder.log(:warn, "Invalid Bing API key.")
|
47
|
+
elsif doc['statusCode'] == 403
|
48
|
+
raise_error(Geocoder::RequestDenied) || Geocoder.log(:warn, "Bing Geocoding API error: Forbidden Request")
|
49
|
+
elsif [500, 503].include?(doc['statusCode'])
|
50
|
+
raise_error(Geocoder::ServiceUnavailable) ||
|
51
|
+
Geocoder.log(:warn, "Bing Geocoding API error: Service Unavailable")
|
47
52
|
else
|
48
53
|
Geocoder.log(:warn, "Bing Geocoding API error: #{doc['statusCode']} (#{doc['statusDescription']}).")
|
49
54
|
end
|
@@ -10,7 +10,7 @@ module Geocoder::Lookup
|
|
10
10
|
|
11
11
|
def query_url(query)
|
12
12
|
path = query.reverse_geocode? ? "reverse" : "geocode"
|
13
|
-
"#{protocol}://api.geocod.io/v1/#{path}?#{url_query_string(query)}"
|
13
|
+
"#{protocol}://api.geocod.io/v1.2/#{path}?#{url_query_string(query)}"
|
14
14
|
end
|
15
15
|
|
16
16
|
def results(query)
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'geocoder/lookups/base'
|
2
|
+
require 'geocoder/results/ipdata_co'
|
3
|
+
|
4
|
+
module Geocoder::Lookup
|
5
|
+
class IpdataCo < Base
|
6
|
+
|
7
|
+
def name
|
8
|
+
"ipdata.co"
|
9
|
+
end
|
10
|
+
|
11
|
+
def supported_protocols
|
12
|
+
[:https]
|
13
|
+
end
|
14
|
+
|
15
|
+
def query_url(query)
|
16
|
+
"#{protocol}://#{host}/#{query.sanitized_text}"
|
17
|
+
end
|
18
|
+
|
19
|
+
private # ---------------------------------------------------------------
|
20
|
+
|
21
|
+
def results(query)
|
22
|
+
Geocoder.configure(:ipdata_co => {:http_headers => { "api-key" => configuration.api_key }}) if configuration.api_key
|
23
|
+
# don't look up a loopback address, just return the stored result
|
24
|
+
return [reserved_result(query.text)] if query.loopback_ip_address?
|
25
|
+
# note: Ipdata.co returns plain text on bad request
|
26
|
+
(doc = fetch_data(query)) ? [doc] : []
|
27
|
+
end
|
28
|
+
|
29
|
+
def reserved_result(ip)
|
30
|
+
{
|
31
|
+
"ip" => ip,
|
32
|
+
"city" => "",
|
33
|
+
"region_code" => "",
|
34
|
+
"region_name" => "",
|
35
|
+
"metrocode" => "",
|
36
|
+
"zipcode" => "",
|
37
|
+
"latitude" => "0",
|
38
|
+
"longitude" => "0",
|
39
|
+
"country_name" => "Reserved",
|
40
|
+
"country_code" => "RD"
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
def host
|
45
|
+
"api.ipdata.co"
|
46
|
+
end
|
47
|
+
|
48
|
+
def check_response_for_errors!(response)
|
49
|
+
if response.code.to_i == 403
|
50
|
+
raise_error(Geocoder::RequestDenied) ||
|
51
|
+
Geocoder.log(:warn, "Geocoding API error: 403 API key does not exist")
|
52
|
+
else
|
53
|
+
super(response)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -9,7 +9,7 @@ module Geocoder::Lookup
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def map_link_url(coordinates)
|
12
|
-
"
|
12
|
+
"https://www.openstreetmap.org/?lat=#{coordinates[0]}&lon=#{coordinates[1]}&zoom=15&layers=M"
|
13
13
|
end
|
14
14
|
|
15
15
|
def query_url(query)
|
@@ -18,6 +18,10 @@ module Geocoder::Lookup
|
|
18
18
|
"#{protocol}://#{host}/#{method}?" + url_query_string(query)
|
19
19
|
end
|
20
20
|
|
21
|
+
def supported_protocols
|
22
|
+
[:https]
|
23
|
+
end
|
24
|
+
|
21
25
|
private # ---------------------------------------------------------------
|
22
26
|
|
23
27
|
def results(query)
|
data/lib/geocoder/request.rb
CHANGED
@@ -81,7 +81,18 @@ module Geocoder
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def geocoder_remove_port_from_addresses(ip_addresses)
|
84
|
-
ip_addresses.map
|
84
|
+
ip_addresses.map do |ip|
|
85
|
+
# IPv4
|
86
|
+
if ip.count('.') > 0
|
87
|
+
ip.split(':').first
|
88
|
+
# IPv6 bracket notation
|
89
|
+
elsif match = ip.match(/\[(\S+)\]/)
|
90
|
+
match.captures.first
|
91
|
+
# IPv6 bare notation
|
92
|
+
else
|
93
|
+
ip
|
94
|
+
end
|
95
|
+
end
|
85
96
|
end
|
86
97
|
|
87
98
|
def geocoder_reject_non_ipv4_addresses(ip_addresses)
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'geocoder/results/base'
|
2
|
+
|
3
|
+
module Geocoder::Result
|
4
|
+
class IpdataCo < Base
|
5
|
+
|
6
|
+
def address(format = :full)
|
7
|
+
s = state_code.to_s == "" ? "" : ", #{state_code}"
|
8
|
+
"#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, "")
|
9
|
+
end
|
10
|
+
|
11
|
+
def city
|
12
|
+
@data['city']
|
13
|
+
end
|
14
|
+
|
15
|
+
def state
|
16
|
+
@data['region']
|
17
|
+
end
|
18
|
+
|
19
|
+
def state_code
|
20
|
+
@data['region_code']
|
21
|
+
end
|
22
|
+
|
23
|
+
def country
|
24
|
+
@data['country_name']
|
25
|
+
end
|
26
|
+
|
27
|
+
def country_code
|
28
|
+
@data['country_code']
|
29
|
+
end
|
30
|
+
|
31
|
+
def postal_code
|
32
|
+
@data['postal']
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.response_attributes
|
36
|
+
%w[ip asn organisation currency currency_symbol calling_code flag time_zone is_eu]
|
37
|
+
end
|
38
|
+
|
39
|
+
response_attributes.each do |a|
|
40
|
+
define_method a do
|
41
|
+
@data[a]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -87,8 +87,6 @@ module Geocoder::Store
|
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
|
-
private # ----------------------------------------------------------------
|
91
|
-
|
92
90
|
##
|
93
91
|
# Get options hash suitable for passing to ActiveRecord.find to get
|
94
92
|
# records within a radius (in kilometers) of the given point.
|
@@ -168,6 +166,8 @@ module Geocoder::Store
|
|
168
166
|
}
|
169
167
|
end
|
170
168
|
|
169
|
+
private # ----------------------------------------------------------------
|
170
|
+
|
171
171
|
##
|
172
172
|
# SQL for calculating distance based on the current database's
|
173
173
|
# capabilities (trig functions?).
|
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.4.
|
4
|
+
version: 1.4.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Reisner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-28 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,
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- lib/geocoder/lookups/google_premier.rb
|
70
70
|
- lib/geocoder/lookups/here.rb
|
71
71
|
- lib/geocoder/lookups/ipapi_com.rb
|
72
|
+
- lib/geocoder/lookups/ipdata_co.rb
|
72
73
|
- lib/geocoder/lookups/ipinfo_io.rb
|
73
74
|
- lib/geocoder/lookups/latlon.rb
|
74
75
|
- lib/geocoder/lookups/location_iq.rb
|
@@ -119,6 +120,7 @@ files:
|
|
119
120
|
- lib/geocoder/results/google_premier.rb
|
120
121
|
- lib/geocoder/results/here.rb
|
121
122
|
- lib/geocoder/results/ipapi_com.rb
|
123
|
+
- lib/geocoder/results/ipdata_co.rb
|
122
124
|
- lib/geocoder/results/ipinfo_io.rb
|
123
125
|
- lib/geocoder/results/latlon.rb
|
124
126
|
- lib/geocoder/results/location_iq.rb
|