geocoder 1.4.9 → 1.6.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +60 -0
- data/LICENSE +1 -1
- data/README.md +350 -979
- data/bin/console +13 -0
- data/examples/autoexpire_cache_redis.rb +2 -0
- data/lib/easting_northing.rb +171 -0
- data/lib/generators/geocoder/config/templates/initializer.rb +1 -1
- data/lib/geocoder/cache.rb +4 -0
- data/lib/geocoder/calculations.rb +1 -1
- data/lib/geocoder/cli.rb +2 -2
- data/lib/geocoder/configuration.rb +3 -2
- data/lib/geocoder/configuration_hash.rb +4 -4
- data/lib/geocoder/exceptions.rb +1 -1
- data/lib/geocoder/ip_address.rb +16 -2
- data/lib/geocoder/lookup.rb +9 -5
- data/lib/geocoder/lookups/abstract_api.rb +46 -0
- data/lib/geocoder/lookups/amap.rb +7 -3
- data/lib/geocoder/lookups/baidu.rb +14 -10
- data/lib/geocoder/lookups/baidu_ip.rb +7 -36
- data/lib/geocoder/lookups/ban_data_gouv_fr.rb +18 -5
- data/lib/geocoder/lookups/base.rb +27 -4
- data/lib/geocoder/lookups/bing.rb +10 -13
- data/lib/geocoder/lookups/db_ip_com.rb +9 -6
- data/lib/geocoder/lookups/dstk.rb +4 -2
- data/lib/geocoder/lookups/esri.rb +44 -28
- data/lib/geocoder/lookups/freegeoip.rb +11 -7
- data/lib/geocoder/lookups/geocoder_ca.rb +4 -4
- data/lib/geocoder/lookups/geocodio.rb +5 -5
- data/lib/geocoder/lookups/geoportail_lu.rb +7 -7
- data/lib/geocoder/lookups/google.rb +15 -10
- data/lib/geocoder/lookups/google_places_details.rb +11 -17
- data/lib/geocoder/lookups/google_places_search.rb +30 -4
- data/lib/geocoder/lookups/google_premier.rb +14 -0
- data/lib/geocoder/lookups/here.rb +29 -23
- data/lib/geocoder/lookups/ip2location.rb +67 -0
- data/lib/geocoder/lookups/ipapi_com.rb +9 -13
- data/lib/geocoder/lookups/ipdata_co.rb +9 -4
- data/lib/geocoder/lookups/ipgeolocation.rb +51 -0
- data/lib/geocoder/lookups/ipinfo_io.rb +11 -29
- data/lib/geocoder/lookups/ipregistry.rb +68 -0
- data/lib/geocoder/lookups/ipstack.rb +11 -12
- data/lib/geocoder/lookups/latlon.rb +5 -6
- data/lib/geocoder/lookups/location_iq.rb +10 -4
- data/lib/geocoder/lookups/mapbox.rb +7 -6
- data/lib/geocoder/lookups/mapquest.rb +4 -5
- data/lib/geocoder/lookups/maxmind.rb +6 -6
- data/lib/geocoder/lookups/maxmind_geoip2.rb +8 -7
- data/lib/geocoder/lookups/maxmind_local.rb +7 -1
- data/lib/geocoder/lookups/nationaal_georegister_nl.rb +38 -0
- data/lib/geocoder/lookups/nominatim.rb +4 -4
- data/lib/geocoder/lookups/opencagedata.rb +6 -5
- data/lib/geocoder/lookups/osmnames.rb +57 -0
- data/lib/geocoder/lookups/pelias.rb +8 -9
- data/lib/geocoder/lookups/pickpoint.rb +9 -3
- data/lib/geocoder/lookups/pointpin.rb +10 -9
- data/lib/geocoder/lookups/postcode_anywhere_uk.rb +4 -5
- data/lib/geocoder/lookups/postcodes_io.rb +6 -3
- data/lib/geocoder/lookups/smarty_streets.rb +26 -11
- data/lib/geocoder/lookups/telize.rb +24 -4
- data/lib/geocoder/lookups/tencent.rb +59 -0
- data/lib/geocoder/lookups/test.rb +4 -0
- data/lib/geocoder/lookups/uk_ordnance_survey_names.rb +59 -0
- data/lib/geocoder/lookups/yandex.rb +7 -8
- data/lib/geocoder/query.rb +14 -0
- data/lib/geocoder/railtie.rb +1 -1
- data/lib/geocoder/results/abstract_api.rb +146 -0
- data/lib/geocoder/results/baidu.rb +10 -14
- data/lib/geocoder/results/ban_data_gouv_fr.rb +27 -2
- data/lib/geocoder/results/base.rb +13 -1
- data/lib/geocoder/results/bing.rb +1 -1
- data/lib/geocoder/results/db_ip_com.rb +1 -6
- data/lib/geocoder/results/freegeoip.rb +0 -5
- data/lib/geocoder/results/geocoder_ca.rb +3 -3
- data/lib/geocoder/results/geoip2.rb +0 -4
- data/lib/geocoder/results/geoportail_lu.rb +5 -3
- data/lib/geocoder/results/here.rb +4 -1
- data/lib/geocoder/results/ip2location.rb +22 -0
- data/lib/geocoder/results/ipdata_co.rb +0 -5
- data/lib/geocoder/results/ipgeolocation.rb +59 -0
- data/lib/geocoder/results/ipregistry.rb +304 -0
- data/lib/geocoder/results/maxmind.rb +0 -5
- data/lib/geocoder/results/maxmind_local.rb +0 -5
- data/lib/geocoder/results/nationaal_georegister_nl.rb +62 -0
- data/lib/geocoder/results/nominatim.rb +4 -0
- data/lib/geocoder/results/osmnames.rb +56 -0
- data/lib/geocoder/results/smarty_streets.rb +48 -18
- data/lib/geocoder/results/telize.rb +0 -5
- data/lib/geocoder/results/tencent.rb +72 -0
- data/lib/geocoder/results/test.rb +1 -1
- data/lib/geocoder/results/uk_ordnance_survey_names.rb +59 -0
- data/lib/geocoder/results/yandex.rb +217 -59
- data/lib/geocoder/sql.rb +4 -4
- data/lib/geocoder/stores/active_record.rb +1 -3
- data/lib/geocoder/util.rb +29 -0
- data/lib/geocoder/version.rb +1 -1
- data/lib/maxmind_database.rb +3 -3
- metadata +27 -23
- data/lib/geocoder/lookups/geocoder_us.rb +0 -43
- data/lib/geocoder/lookups/mapzen.rb +0 -15
- data/lib/geocoder/lookups/okf.rb +0 -44
- data/lib/geocoder/lookups/ovi.rb +0 -62
- data/lib/geocoder/results/geocoder_us.rb +0 -39
- data/lib/geocoder/results/mapzen.rb +0 -5
- data/lib/geocoder/results/okf.rb +0 -106
- data/lib/geocoder/results/ovi.rb +0 -71
- data/lib/hash_recursive_merge.rb +0 -74
@@ -12,10 +12,6 @@ module Geocoder::Lookup
|
|
12
12
|
["key"]
|
13
13
|
end
|
14
14
|
|
15
|
-
def query_url(query)
|
16
|
-
"#{protocol}://api.map.baidu.com/geocoder/v2/?" + url_query_string(query)
|
17
|
-
end
|
18
|
-
|
19
15
|
# HTTP only
|
20
16
|
def supported_protocols
|
21
17
|
[:http]
|
@@ -23,26 +19,34 @@ module Geocoder::Lookup
|
|
23
19
|
|
24
20
|
private # ---------------------------------------------------------------
|
25
21
|
|
22
|
+
def base_query_url(query)
|
23
|
+
"#{protocol}://api.map.baidu.com/geocoder/v2/?"
|
24
|
+
end
|
25
|
+
|
26
|
+
def content_key
|
27
|
+
'result'
|
28
|
+
end
|
29
|
+
|
26
30
|
def results(query, reverse = false)
|
27
31
|
return [] unless doc = fetch_data(query)
|
28
32
|
case doc['status']
|
29
33
|
when 0
|
30
|
-
return [doc[
|
34
|
+
return [doc[content_key]] unless doc[content_key].blank?
|
31
35
|
when 1, 3, 4
|
32
36
|
raise_error(Geocoder::Error, "server error.") ||
|
33
|
-
Geocoder.log(:warn, "
|
37
|
+
Geocoder.log(:warn, "#{name} Geocoding API error: server error.")
|
34
38
|
when 2
|
35
39
|
raise_error(Geocoder::InvalidRequest, "invalid request.") ||
|
36
|
-
Geocoder.log(:warn, "
|
40
|
+
Geocoder.log(:warn, "#{name} Geocoding API error: invalid request.")
|
37
41
|
when 5
|
38
42
|
raise_error(Geocoder::InvalidApiKey, "invalid api key") ||
|
39
|
-
Geocoder.log(:warn, "
|
43
|
+
Geocoder.log(:warn, "#{name} Geocoding API error: invalid api key.")
|
40
44
|
when 101, 102, 200..299
|
41
45
|
raise_error(Geocoder::RequestDenied, "request denied") ||
|
42
|
-
Geocoder.log(:warn, "
|
46
|
+
Geocoder.log(:warn, "#{name} Geocoding API error: request denied.")
|
43
47
|
when 300..399
|
44
48
|
raise_error(Geocoder::OverQueryLimitError, "over query limit.") ||
|
45
|
-
Geocoder.log(:warn, "
|
49
|
+
Geocoder.log(:warn, "#{name} Geocoding API error: over query limit.")
|
46
50
|
end
|
47
51
|
return []
|
48
52
|
end
|
@@ -1,50 +1,21 @@
|
|
1
|
-
require 'geocoder/lookups/
|
1
|
+
require 'geocoder/lookups/baidu'
|
2
2
|
require 'geocoder/results/baidu_ip'
|
3
3
|
|
4
4
|
module Geocoder::Lookup
|
5
|
-
class BaiduIp <
|
5
|
+
class BaiduIp < Baidu
|
6
6
|
|
7
7
|
def name
|
8
8
|
"Baidu IP"
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
["key"]
|
13
|
-
end
|
14
|
-
|
15
|
-
def query_url(query)
|
16
|
-
"#{protocol}://api.map.baidu.com/location/ip?" + url_query_string(query)
|
17
|
-
end
|
11
|
+
private # ---------------------------------------------------------------
|
18
12
|
|
19
|
-
|
20
|
-
|
21
|
-
[:http]
|
13
|
+
def base_query_url(query)
|
14
|
+
"#{protocol}://api.map.baidu.com/location/ip?"
|
22
15
|
end
|
23
16
|
|
24
|
-
|
25
|
-
|
26
|
-
def results(query, reverse = false)
|
27
|
-
return [] unless doc = fetch_data(query)
|
28
|
-
case doc['status']
|
29
|
-
when 0
|
30
|
-
return [doc['content']] unless doc['content'].blank?
|
31
|
-
when 1, 3, 4
|
32
|
-
raise_error(Geocoder::Error, "server error.") ||
|
33
|
-
Geocoder.log(:warn, "Baidu IP Geocoding API error: server error.")
|
34
|
-
when 2
|
35
|
-
raise_error(Geocoder::InvalidRequest, "invalid request.") ||
|
36
|
-
Geocoder.log(:warn, "Baidu IP Geocoding API error: invalid request.")
|
37
|
-
when 5
|
38
|
-
raise_error(Geocoder::InvalidApiKey, "invalid api key.") ||
|
39
|
-
Geocoder.log(:warn, "Baidu IP Geocoding API error: invalid api key.")
|
40
|
-
when 101, 102, 200..299
|
41
|
-
raise_error(Geocoder::RequestDenied, "request denied.") ||
|
42
|
-
Geocoder.log(:warn, "Baidu IP Geocoding API error: request denied.")
|
43
|
-
when 300..399
|
44
|
-
raise_error(Geocoder::OverQueryLimitError, "over query limit") ||
|
45
|
-
Geocoder.log(:warn, "Baidu IP Geocoding API error: over query limit.")
|
46
|
-
end
|
47
|
-
return []
|
17
|
+
def content_key
|
18
|
+
'content'
|
48
19
|
end
|
49
20
|
|
50
21
|
def query_url_params(query)
|
@@ -14,15 +14,15 @@ module Geocoder::Lookup
|
|
14
14
|
"https://www.openstreetmap.org/#map=19/#{coordinates.join('/')}"
|
15
15
|
end
|
16
16
|
|
17
|
-
|
17
|
+
private # ---------------------------------------------------------------
|
18
|
+
|
19
|
+
def base_query_url(query)
|
18
20
|
method = query.reverse_geocode? ? "reverse" : "search"
|
19
|
-
"#{protocol}://api-adresse.data.gouv.fr/#{method}/?"
|
21
|
+
"#{protocol}://api-adresse.data.gouv.fr/#{method}/?"
|
20
22
|
end
|
21
23
|
|
22
|
-
private # ---------------------------------------------------------------
|
23
|
-
|
24
24
|
def any_result?(doc)
|
25
|
-
doc['features'].any?
|
25
|
+
doc['features'] and doc['features'].any?
|
26
26
|
end
|
27
27
|
|
28
28
|
def results(query)
|
@@ -86,6 +86,12 @@ module Geocoder::Lookup
|
|
86
86
|
unless (citycode = query.options[:citycode]).nil? || !code_param_is_valid?(citycode)
|
87
87
|
params[:citycode] = citycode.to_s
|
88
88
|
end
|
89
|
+
unless (lat = query.options[:lat]).nil? || !latitude_is_valid?(lat)
|
90
|
+
params[:lat] = lat
|
91
|
+
end
|
92
|
+
unless (lon = query.options[:lon]).nil? || !longitude_is_valid?(lon)
|
93
|
+
params[:lon] = lon
|
94
|
+
end
|
89
95
|
params
|
90
96
|
end
|
91
97
|
|
@@ -126,5 +132,12 @@ module Geocoder::Lookup
|
|
126
132
|
(1..99999).include?(param.to_i)
|
127
133
|
end
|
128
134
|
|
135
|
+
def latitude_is_valid?(param)
|
136
|
+
param.to_f <= 90 && param.to_f >= -90
|
137
|
+
end
|
138
|
+
|
139
|
+
def longitude_is_valid?(param)
|
140
|
+
param.to_f <= 180 && param.to_f >= -180
|
141
|
+
end
|
129
142
|
end
|
130
143
|
end
|
@@ -4,7 +4,6 @@ require 'uri'
|
|
4
4
|
|
5
5
|
unless defined?(ActiveSupport::JSON)
|
6
6
|
begin
|
7
|
-
require 'rubygems' # for Ruby 1.8
|
8
7
|
require 'json'
|
9
8
|
rescue LoadError
|
10
9
|
raise LoadError, "Please install the 'json' or 'json_pure' gem to parse geocoder results."
|
@@ -72,8 +71,12 @@ module Geocoder
|
|
72
71
|
##
|
73
72
|
# URL to use for querying the geocoding engine.
|
74
73
|
#
|
74
|
+
# Subclasses should not modify this method. Instead they should define
|
75
|
+
# base_query_url and url_query_string. If absolutely necessary to
|
76
|
+
# subclss this method, they must also subclass #cache_key.
|
77
|
+
#
|
75
78
|
def query_url(query)
|
76
|
-
|
79
|
+
base_query_url(query) + url_query_string(query)
|
77
80
|
end
|
78
81
|
|
79
82
|
##
|
@@ -97,6 +100,14 @@ module Geocoder
|
|
97
100
|
|
98
101
|
private # -------------------------------------------------------------
|
99
102
|
|
103
|
+
##
|
104
|
+
# String which, when concatenated with url_query_string(query)
|
105
|
+
# produces the full query URL. Should include the "?" a the end.
|
106
|
+
#
|
107
|
+
def base_query_url(query)
|
108
|
+
fail
|
109
|
+
end
|
110
|
+
|
100
111
|
##
|
101
112
|
# An object with configuration data for this particular lookup.
|
102
113
|
#
|
@@ -147,7 +158,14 @@ module Geocoder
|
|
147
158
|
# something else (like the URL before OAuth encoding).
|
148
159
|
#
|
149
160
|
def cache_key(query)
|
150
|
-
|
161
|
+
base_query_url(query) + hash_to_query(cache_key_params(query))
|
162
|
+
end
|
163
|
+
|
164
|
+
def cache_key_params(query)
|
165
|
+
# omit api_key and token because they may vary among requests
|
166
|
+
query_url_params(query).reject do |key,value|
|
167
|
+
key.to_s.match(/(key|token)/)
|
168
|
+
end
|
151
169
|
end
|
152
170
|
|
153
171
|
##
|
@@ -179,6 +197,8 @@ module Geocoder
|
|
179
197
|
raise_error(err) or Geocoder.log(:warn, "Geocoding API connection cannot be established.")
|
180
198
|
rescue Errno::ECONNREFUSED => err
|
181
199
|
raise_error(err) or Geocoder.log(:warn, "Geocoding API connection refused.")
|
200
|
+
rescue Geocoder::NetworkError => err
|
201
|
+
raise_error(err) or Geocoder.log(:warn, "Geocoding API connection is either unreacheable or reset by the peer")
|
182
202
|
rescue Timeout::Error => err
|
183
203
|
raise_error(err) or Geocoder.log(:warn, "Geocoding API not responding fast enough " +
|
184
204
|
"(use Geocoder.configure(:timeout => ...) to set limit).")
|
@@ -191,7 +211,10 @@ module Geocoder
|
|
191
211
|
JSON.parse(data)
|
192
212
|
end
|
193
213
|
rescue
|
194
|
-
raise_error(ResponseParseError.new(data))
|
214
|
+
unless raise_error(ResponseParseError.new(data))
|
215
|
+
Geocoder.log(:warn, "Geocoding API's response was not valid JSON")
|
216
|
+
Geocoder.log(:debug, "Raw response: #{data}")
|
217
|
+
end
|
195
218
|
end
|
196
219
|
|
197
220
|
##
|
@@ -16,24 +16,20 @@ module Geocoder::Lookup
|
|
16
16
|
["key"]
|
17
17
|
end
|
18
18
|
|
19
|
-
def query_url(query)
|
20
|
-
base_url(query) + url_query_string(query)
|
21
|
-
end
|
22
|
-
|
23
19
|
private # ---------------------------------------------------------------
|
24
20
|
|
25
|
-
def
|
26
|
-
|
27
|
-
|
28
|
-
if
|
21
|
+
def base_query_url(query)
|
22
|
+
text = CGI.escape(query.sanitized_text.strip)
|
23
|
+
url = "#{protocol}://dev.virtualearth.net/REST/v1/Locations/"
|
24
|
+
if query.reverse_geocode?
|
25
|
+
url + "#{text}?"
|
26
|
+
else
|
29
27
|
if r = query.options[:region]
|
30
|
-
url << "
|
28
|
+
url << "#{r}/"
|
31
29
|
end
|
32
30
|
# use the more forgiving 'unstructured' query format to allow special
|
33
31
|
# chars, newlines, brackets, typos.
|
34
|
-
url + "?q
|
35
|
-
else
|
36
|
-
url + "/#{URI.escape(query.sanitized_text.strip)}?"
|
32
|
+
url + "?q=#{text}&"
|
37
33
|
end
|
38
34
|
end
|
39
35
|
|
@@ -57,7 +53,8 @@ module Geocoder::Lookup
|
|
57
53
|
|
58
54
|
def query_url_params(query)
|
59
55
|
{
|
60
|
-
key: configuration.api_key
|
56
|
+
key: configuration.api_key,
|
57
|
+
language: (query.language || configuration.language)
|
61
58
|
}.merge(super)
|
62
59
|
end
|
63
60
|
|
@@ -16,15 +16,18 @@ module Geocoder::Lookup
|
|
16
16
|
['api_key']
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
|
-
query_params = if query.options[:params]
|
21
|
-
"?#{url_query_string(query)}"
|
22
|
-
end
|
19
|
+
private # ----------------------------------------------------------------
|
23
20
|
|
24
|
-
|
21
|
+
def base_query_url(query)
|
22
|
+
"#{protocol}://api.db-ip.com/v2/#{configuration.api_key}/#{query.sanitized_text}?"
|
25
23
|
end
|
26
24
|
|
27
|
-
|
25
|
+
##
|
26
|
+
# Same as query_url but without the api key.
|
27
|
+
#
|
28
|
+
def cache_key(query)
|
29
|
+
"#{protocol}://api.db-ip.com/v2/#{query.sanitized_text}?" + hash_to_query(cache_key_params(query))
|
30
|
+
end
|
28
31
|
|
29
32
|
def results(query)
|
30
33
|
return [] unless (doc = fetch_data(query))
|
@@ -12,9 +12,11 @@ module Geocoder::Lookup
|
|
12
12
|
"Data Science Toolkit"
|
13
13
|
end
|
14
14
|
|
15
|
-
|
15
|
+
private # ----------------------------------------------------------------
|
16
|
+
|
17
|
+
def base_query_url(query)
|
16
18
|
host = configuration[:host] || "www.datasciencetoolkit.org"
|
17
|
-
"#{protocol}://#{host}/maps/api/geocode/json?"
|
19
|
+
"#{protocol}://#{host}/maps/api/geocode/json?"
|
18
20
|
end
|
19
21
|
end
|
20
22
|
end
|
@@ -4,14 +4,14 @@ require 'geocoder/esri_token'
|
|
4
4
|
|
5
5
|
module Geocoder::Lookup
|
6
6
|
class Esri < Base
|
7
|
-
|
7
|
+
|
8
8
|
def name
|
9
9
|
"Esri"
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
def supported_protocols
|
13
|
+
[:https]
|
14
|
+
end
|
15
15
|
|
16
16
|
private # ---------------------------------------------------------------
|
17
17
|
|
@@ -34,17 +34,6 @@ module Geocoder::Lookup
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
def cache_key(query)
|
38
|
-
base_query_url(query) + hash_to_query(cache_key_params(query))
|
39
|
-
end
|
40
|
-
|
41
|
-
def cache_key_params(query)
|
42
|
-
# omit api_key and token because they may vary among requests
|
43
|
-
query_url_params(query).reject do |key,value|
|
44
|
-
[:api_key, :token].include?(key)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
37
|
def query_url_params(query)
|
49
38
|
params = {
|
50
39
|
:f => "pjson",
|
@@ -55,31 +44,58 @@ module Geocoder::Lookup
|
|
55
44
|
else
|
56
45
|
params[:text] = query.sanitized_text
|
57
46
|
end
|
58
|
-
|
59
|
-
params[:
|
47
|
+
|
48
|
+
params[:token] = token(query)
|
49
|
+
|
50
|
+
if for_storage_value = for_storage(query)
|
51
|
+
params[:forStorage] = for_storage_value
|
52
|
+
end
|
60
53
|
params[:sourceCountry] = configuration[:source_country] if configuration[:source_country]
|
54
|
+
params[:preferredLabelValues] = configuration[:preferred_label_values] if configuration[:preferred_label_values]
|
55
|
+
|
61
56
|
params.merge(super)
|
62
57
|
end
|
63
58
|
|
64
|
-
def
|
65
|
-
|
66
|
-
|
59
|
+
def for_storage(query)
|
60
|
+
if query.options.has_key?(:for_storage)
|
61
|
+
query.options[:for_storage]
|
62
|
+
else
|
63
|
+
configuration[:for_storage]
|
64
|
+
end
|
67
65
|
end
|
68
66
|
|
69
|
-
def
|
70
|
-
|
67
|
+
def token(query)
|
68
|
+
token_instance = if query.options[:token]
|
69
|
+
query.options[:token]
|
70
|
+
else
|
71
|
+
configuration[:token]
|
72
|
+
end
|
73
|
+
|
74
|
+
if !valid_token_configured?(token_instance) && configuration.api_key
|
75
|
+
token_instance = create_and_save_token!(query)
|
76
|
+
end
|
77
|
+
|
78
|
+
token_instance.to_s unless token_instance.nil?
|
71
79
|
end
|
72
80
|
|
73
|
-
def
|
74
|
-
|
81
|
+
def valid_token_configured?(token_instance)
|
82
|
+
!token_instance.nil? && token_instance.active?
|
75
83
|
end
|
76
84
|
|
77
|
-
def
|
78
|
-
|
85
|
+
def create_and_save_token!(query)
|
86
|
+
token_instance = create_token
|
87
|
+
|
88
|
+
if query.options[:token]
|
89
|
+
query.options[:token] = token_instance
|
90
|
+
else
|
91
|
+
Geocoder.merge_into_lookup_config(:esri, token: token_instance)
|
92
|
+
end
|
93
|
+
|
94
|
+
token_instance
|
79
95
|
end
|
80
96
|
|
81
|
-
def
|
82
|
-
Geocoder.
|
97
|
+
def create_token
|
98
|
+
Geocoder::EsriToken.generate_token(*configuration.api_key)
|
83
99
|
end
|
84
100
|
end
|
85
101
|
end
|
@@ -7,10 +7,10 @@ module Geocoder::Lookup
|
|
7
7
|
def name
|
8
8
|
"FreeGeoIP"
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def supported_protocols
|
12
12
|
if configuration[:host]
|
13
|
-
[:
|
13
|
+
[:https]
|
14
14
|
else
|
15
15
|
# use https for default host
|
16
16
|
[:https]
|
@@ -23,13 +23,17 @@ module Geocoder::Lookup
|
|
23
23
|
|
24
24
|
private # ---------------------------------------------------------------
|
25
25
|
|
26
|
+
def cache_key(query)
|
27
|
+
query_url(query)
|
28
|
+
end
|
29
|
+
|
26
30
|
def parse_raw_data(raw_data)
|
27
31
|
raw_data.match(/^<html><title>404/) ? nil : super(raw_data)
|
28
32
|
end
|
29
33
|
|
30
34
|
def results(query)
|
31
|
-
# don't look up a loopback address, just return the stored result
|
32
|
-
return [reserved_result(query.text)] if query.
|
35
|
+
# don't look up a loopback or private address, just return the stored result
|
36
|
+
return [reserved_result(query.text)] if query.internal_ip_address?
|
33
37
|
# note: Freegeoip.net returns plain text "Not Found" on bad request
|
34
38
|
(doc = fetch_data(query)) ? [doc] : []
|
35
39
|
end
|
@@ -40,8 +44,8 @@ module Geocoder::Lookup
|
|
40
44
|
"city" => "",
|
41
45
|
"region_code" => "",
|
42
46
|
"region_name" => "",
|
43
|
-
"
|
44
|
-
"
|
47
|
+
"metro_code" => "",
|
48
|
+
"zip_code" => "",
|
45
49
|
"latitude" => "0",
|
46
50
|
"longitude" => "0",
|
47
51
|
"country_name" => "Reserved",
|
@@ -50,7 +54,7 @@ module Geocoder::Lookup
|
|
50
54
|
end
|
51
55
|
|
52
56
|
def host
|
53
|
-
configuration[:host] || "freegeoip.
|
57
|
+
configuration[:host] || "freegeoip.app"
|
54
58
|
end
|
55
59
|
end
|
56
60
|
end
|