geocoder 1.5.1 → 1.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +107 -0
- data/LICENSE +1 -1
- data/README.md +364 -243
- data/bin/console +13 -0
- data/examples/app_defined_lookup_services.rb +22 -0
- data/lib/easting_northing.rb +171 -0
- data/lib/generators/geocoder/config/templates/initializer.rb +6 -1
- data/lib/geocoder/cache.rb +16 -33
- data/lib/geocoder/cache_stores/base.rb +40 -0
- data/lib/geocoder/cache_stores/generic.rb +35 -0
- data/lib/geocoder/cache_stores/redis.rb +34 -0
- data/lib/geocoder/configuration.rb +19 -5
- data/lib/geocoder/configuration_hash.rb +4 -4
- data/lib/geocoder/ip_address.rb +11 -1
- data/lib/geocoder/lookup.rb +42 -6
- data/lib/geocoder/lookups/abstract_api.rb +46 -0
- data/lib/geocoder/lookups/amap.rb +2 -2
- data/lib/geocoder/lookups/amazon_location_service.rb +58 -0
- data/lib/geocoder/lookups/azure.rb +56 -0
- data/lib/geocoder/lookups/ban_data_gouv_fr.rb +15 -2
- data/lib/geocoder/lookups/base.rb +4 -1
- data/lib/geocoder/lookups/bing.rb +2 -2
- data/lib/geocoder/lookups/esri.rb +24 -5
- data/lib/geocoder/lookups/freegeoip.rb +12 -10
- data/lib/geocoder/lookups/geoapify.rb +78 -0
- data/lib/geocoder/lookups/geocodio.rb +1 -1
- data/lib/geocoder/lookups/geoip2.rb +4 -0
- data/lib/geocoder/lookups/geoportail_lu.rb +1 -1
- data/lib/geocoder/lookups/google.rb +7 -2
- data/lib/geocoder/lookups/google_places_details.rb +26 -12
- data/lib/geocoder/lookups/google_places_search.rb +44 -2
- data/lib/geocoder/lookups/google_premier.rb +4 -0
- data/lib/geocoder/lookups/here.rb +27 -31
- data/lib/geocoder/lookups/ip2location.rb +10 -14
- data/lib/geocoder/lookups/ip2location_io.rb +62 -0
- data/lib/geocoder/lookups/ip2location_lite.rb +40 -0
- data/lib/geocoder/lookups/ipbase.rb +49 -0
- data/lib/geocoder/lookups/ipdata_co.rb +1 -1
- data/lib/geocoder/lookups/ipgeolocation.rb +51 -0
- data/lib/geocoder/lookups/ipqualityscore.rb +50 -0
- data/lib/geocoder/lookups/ipregistry.rb +68 -0
- data/lib/geocoder/lookups/latlon.rb +1 -2
- data/lib/geocoder/lookups/location_iq.rb +5 -1
- data/lib/geocoder/lookups/mapbox.rb +3 -3
- data/lib/geocoder/lookups/maxmind_local.rb +7 -1
- data/lib/geocoder/lookups/melissa_street.rb +41 -0
- data/lib/geocoder/lookups/nationaal_georegister_nl.rb +38 -0
- data/lib/geocoder/lookups/osmnames.rb +57 -0
- data/lib/geocoder/lookups/pc_miler.rb +85 -0
- data/lib/geocoder/lookups/pdok_nl.rb +43 -0
- data/lib/geocoder/lookups/photon.rb +89 -0
- data/lib/geocoder/lookups/pickpoint.rb +1 -1
- data/lib/geocoder/lookups/smarty_streets.rb +6 -1
- data/lib/geocoder/lookups/telize.rb +1 -1
- data/lib/geocoder/lookups/tencent.rb +9 -9
- data/lib/geocoder/lookups/test.rb +5 -0
- data/lib/geocoder/lookups/twogis.rb +58 -0
- data/lib/geocoder/lookups/uk_ordnance_survey_names.rb +59 -0
- data/lib/geocoder/lookups/yandex.rb +6 -7
- data/lib/geocoder/query.rb +1 -1
- data/lib/geocoder/results/abstract_api.rb +146 -0
- data/lib/geocoder/results/amazon_location_service.rb +62 -0
- data/lib/geocoder/results/azure.rb +65 -0
- data/lib/geocoder/results/baidu.rb +0 -4
- data/lib/geocoder/results/ban_data_gouv_fr.rb +28 -3
- data/lib/geocoder/results/db_ip_com.rb +1 -1
- data/lib/geocoder/results/esri.rb +5 -2
- data/lib/geocoder/results/geoapify.rb +179 -0
- data/lib/geocoder/results/here.rb +20 -22
- data/lib/geocoder/results/ip2location_io.rb +21 -0
- data/lib/geocoder/results/ip2location_lite.rb +47 -0
- data/lib/geocoder/results/ipbase.rb +40 -0
- data/lib/geocoder/results/ipgeolocation.rb +59 -0
- data/lib/geocoder/results/ipqualityscore.rb +54 -0
- data/lib/geocoder/results/ipregistry.rb +304 -0
- data/lib/geocoder/results/mapbox.rb +34 -10
- data/lib/geocoder/results/melissa_street.rb +46 -0
- data/lib/geocoder/results/nationaal_georegister_nl.rb +62 -0
- data/lib/geocoder/results/nominatim.rb +27 -15
- data/lib/geocoder/results/osmnames.rb +56 -0
- data/lib/geocoder/results/pc_miler.rb +98 -0
- data/lib/geocoder/results/pdok_nl.rb +62 -0
- data/lib/geocoder/results/photon.rb +119 -0
- data/lib/geocoder/results/twogis.rb +76 -0
- 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/util.rb +29 -0
- data/lib/geocoder/version.rb +1 -1
- data/lib/maxmind_database.rb +12 -12
- data/lib/tasks/maxmind.rake +1 -1
- metadata +81 -23
- data/examples/autoexpire_cache_dalli.rb +0 -62
- data/examples/autoexpire_cache_redis.rb +0 -28
- data/lib/geocoder/lookups/dstk.rb +0 -22
- data/lib/geocoder/lookups/geocoder_us.rb +0 -51
- data/lib/geocoder/results/dstk.rb +0 -6
- data/lib/geocoder/results/geocoder_us.rb +0 -39
- data/lib/hash_recursive_merge.rb +0 -74
@@ -9,69 +9,65 @@ module Geocoder::Lookup
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def required_api_key_parts
|
12
|
-
[
|
12
|
+
['api_key']
|
13
|
+
end
|
14
|
+
|
15
|
+
def supported_protocols
|
16
|
+
[:https]
|
13
17
|
end
|
14
18
|
|
15
19
|
private # ---------------------------------------------------------------
|
16
20
|
|
17
21
|
def base_query_url(query)
|
18
|
-
|
22
|
+
service = query.reverse_geocode? ? "revgeocode" : "geocode"
|
23
|
+
|
24
|
+
"#{protocol}://#{service}.search.hereapi.com/v1/#{service}?"
|
19
25
|
end
|
20
26
|
|
21
27
|
def results(query)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
return [] if r.nil? || !r.is_a?(Array) || r.empty?
|
26
|
-
return r.first['Result']
|
28
|
+
unless configuration.api_key.is_a?(String)
|
29
|
+
api_key_not_string!
|
30
|
+
return []
|
27
31
|
end
|
28
|
-
[]
|
32
|
+
return [] unless doc = fetch_data(query)
|
33
|
+
return [] if doc["items"].nil?
|
34
|
+
|
35
|
+
doc["items"]
|
29
36
|
end
|
30
37
|
|
31
38
|
def query_url_here_options(query, reverse_geocode)
|
32
39
|
options = {
|
33
|
-
|
34
|
-
|
35
|
-
app_code: api_code,
|
36
|
-
language: (query.language || configuration.language)
|
40
|
+
apiKey: configuration.api_key,
|
41
|
+
lang: (query.language || configuration.language)
|
37
42
|
}
|
38
|
-
if reverse_geocode
|
39
|
-
options[:mode] = :retrieveAddresses
|
40
|
-
return options
|
41
|
-
end
|
43
|
+
return options if reverse_geocode
|
42
44
|
|
43
45
|
unless (country = query.options[:country]).nil?
|
44
|
-
options[:
|
46
|
+
options[:in] = "countryCode:#{country}"
|
45
47
|
end
|
46
48
|
|
47
|
-
unless (mapview = query.options[:bounds]).nil?
|
48
|
-
options[:mapview] = mapview.map{ |point| "%f,%f" % point }.join(';')
|
49
|
-
end
|
50
49
|
options
|
51
50
|
end
|
52
51
|
|
53
52
|
def query_url_params(query)
|
54
53
|
if query.reverse_geocode?
|
55
54
|
super.merge(query_url_here_options(query, true)).merge(
|
56
|
-
|
55
|
+
at: query.sanitized_text
|
57
56
|
)
|
58
57
|
else
|
59
58
|
super.merge(query_url_here_options(query, false)).merge(
|
60
|
-
|
59
|
+
q: query.sanitized_text
|
61
60
|
)
|
62
61
|
end
|
63
62
|
end
|
64
63
|
|
65
|
-
def
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
64
|
+
def api_key_not_string!
|
65
|
+
msg = <<~MSG
|
66
|
+
API key for HERE Geocoding and Search API should be a string.
|
67
|
+
For more info on how to obtain it, please see https://developer.here.com/documentation/identity-access-management/dev_guide/topics/plat-using-apikeys.html
|
68
|
+
MSG
|
70
69
|
|
71
|
-
|
72
|
-
if (a = configuration.api_key)
|
73
|
-
return a.last if a.is_a?(Array)
|
74
|
-
end
|
70
|
+
raise_error(Geocoder::ConfigurationError, msg) || Geocoder.log(:warn, msg)
|
75
71
|
end
|
76
72
|
end
|
77
73
|
end
|
@@ -8,6 +8,10 @@ module Geocoder::Lookup
|
|
8
8
|
"IP2LocationApi"
|
9
9
|
end
|
10
10
|
|
11
|
+
def required_api_key_parts
|
12
|
+
['key']
|
13
|
+
end
|
14
|
+
|
11
15
|
def supported_protocols
|
12
16
|
[:http, :https]
|
13
17
|
end
|
@@ -15,15 +19,15 @@ module Geocoder::Lookup
|
|
15
19
|
private # ----------------------------------------------------------------
|
16
20
|
|
17
21
|
def base_query_url(query)
|
18
|
-
"#{protocol}://api.ip2location.com/?"
|
22
|
+
"#{protocol}://api.ip2location.com/v2/?"
|
19
23
|
end
|
20
24
|
|
21
25
|
def query_url_params(query)
|
22
|
-
|
23
|
-
key: configuration.api_key
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
super.merge(
|
27
|
+
key: configuration.api_key,
|
28
|
+
ip: query.sanitized_text,
|
29
|
+
package: configuration[:package],
|
30
|
+
)
|
27
31
|
end
|
28
32
|
|
29
33
|
def results(query)
|
@@ -63,13 +67,5 @@ module Geocoder::Lookup
|
|
63
67
|
}
|
64
68
|
end
|
65
69
|
|
66
|
-
def query_url_params(query)
|
67
|
-
params = super
|
68
|
-
if configuration.has_key?(:package)
|
69
|
-
params.merge!(package: configuration[:package])
|
70
|
-
end
|
71
|
-
params
|
72
|
-
end
|
73
|
-
|
74
70
|
end
|
75
71
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'geocoder/lookups/base'
|
2
|
+
require 'geocoder/results/ip2location_io'
|
3
|
+
|
4
|
+
module Geocoder::Lookup
|
5
|
+
class Ip2locationIo < Base
|
6
|
+
|
7
|
+
def name
|
8
|
+
"IP2LocationIOApi"
|
9
|
+
end
|
10
|
+
|
11
|
+
def required_api_key_parts
|
12
|
+
['key']
|
13
|
+
end
|
14
|
+
|
15
|
+
def supported_protocols
|
16
|
+
[:http, :https]
|
17
|
+
end
|
18
|
+
|
19
|
+
private # ----------------------------------------------------------------
|
20
|
+
|
21
|
+
def base_query_url(query)
|
22
|
+
"#{protocol}://api.ip2location.io/?"
|
23
|
+
end
|
24
|
+
|
25
|
+
def query_url_params(query)
|
26
|
+
super.merge(
|
27
|
+
key: configuration.api_key,
|
28
|
+
ip: query.sanitized_text,
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
def results(query)
|
33
|
+
# don't look up a loopback or private address, just return the stored result
|
34
|
+
return [reserved_result(query.text)] if query.internal_ip_address?
|
35
|
+
return [] unless doc = fetch_data(query)
|
36
|
+
if doc["response"] == "INVALID ACCOUNT"
|
37
|
+
raise_error(Geocoder::InvalidApiKey) || Geocoder.log(:warn, "INVALID ACCOUNT")
|
38
|
+
return []
|
39
|
+
else
|
40
|
+
return [doc]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def reserved_result(query)
|
45
|
+
{
|
46
|
+
"ip" => "-",
|
47
|
+
"country_code" => "-",
|
48
|
+
"country_name" => "-",
|
49
|
+
"region_name" => "-",
|
50
|
+
"city_name" => "-",
|
51
|
+
"latitude" => null,
|
52
|
+
"longitude" => null,
|
53
|
+
"zip_code" => "-",
|
54
|
+
"time_zone" => "-",
|
55
|
+
"asn" => "-",
|
56
|
+
"as" => "-",
|
57
|
+
"is_proxy" => false
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'geocoder/lookups/base'
|
2
|
+
require 'geocoder/results/ip2location_lite'
|
3
|
+
|
4
|
+
module Geocoder
|
5
|
+
module Lookup
|
6
|
+
class Ip2locationLite < Base
|
7
|
+
attr_reader :gem_name
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
unless configuration[:file].nil?
|
11
|
+
begin
|
12
|
+
@gem_name = 'ip2location_ruby'
|
13
|
+
require @gem_name
|
14
|
+
rescue LoadError
|
15
|
+
raise "Could not load IP2Location DB dependency. To use the IP2LocationLite lookup you must add the #{@gem_name} gem to your Gemfile or have it installed in your system."
|
16
|
+
end
|
17
|
+
end
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
21
|
+
def name
|
22
|
+
'IP2LocationLite'
|
23
|
+
end
|
24
|
+
|
25
|
+
def required_api_key_parts
|
26
|
+
[]
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def results(query)
|
32
|
+
return [] unless configuration[:file]
|
33
|
+
|
34
|
+
i2l = Ip2location.new.open(configuration[:file].to_s)
|
35
|
+
result = i2l.get_all(query.to_s)
|
36
|
+
result.nil? ? [] : [result]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'geocoder/lookups/base'
|
2
|
+
require 'geocoder/results/ipbase'
|
3
|
+
|
4
|
+
module Geocoder::Lookup
|
5
|
+
class Ipbase < Base
|
6
|
+
|
7
|
+
def name
|
8
|
+
"ipbase.com"
|
9
|
+
end
|
10
|
+
|
11
|
+
def supported_protocols
|
12
|
+
[:https]
|
13
|
+
end
|
14
|
+
|
15
|
+
private # ---------------------------------------------------------------
|
16
|
+
|
17
|
+
def base_query_url(query)
|
18
|
+
"https://api.ipbase.com/v2/info?"
|
19
|
+
end
|
20
|
+
|
21
|
+
def query_url_params(query)
|
22
|
+
{
|
23
|
+
:ip => query.sanitized_text,
|
24
|
+
:apikey => configuration.api_key
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def results(query)
|
29
|
+
# don't look up a loopback or private address, just return the stored result
|
30
|
+
return [reserved_result(query.text)] if query.internal_ip_address?
|
31
|
+
doc = fetch_data(query) || {}
|
32
|
+
doc.fetch("data", {})["location"] ? [doc] : []
|
33
|
+
end
|
34
|
+
|
35
|
+
def reserved_result(ip)
|
36
|
+
{
|
37
|
+
"data" => {
|
38
|
+
"ip" => ip,
|
39
|
+
"location" => {
|
40
|
+
"city" => { "name" => "" },
|
41
|
+
"country" => { "alpha2" => "RD", "name" => "Reserved" },
|
42
|
+
"region" => { "alpha2" => "", "name" => "" },
|
43
|
+
"zip" => ""
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'geocoder/lookups/base'
|
2
|
+
require 'geocoder/results/ipgeolocation'
|
3
|
+
|
4
|
+
|
5
|
+
module Geocoder::Lookup
|
6
|
+
class Ipgeolocation < Base
|
7
|
+
|
8
|
+
ERROR_CODES = {
|
9
|
+
400 => Geocoder::RequestDenied, # subscription is paused
|
10
|
+
401 => Geocoder::InvalidApiKey, # missing/invalid API key
|
11
|
+
403 => Geocoder::InvalidRequest, # invalid IP address
|
12
|
+
404 => Geocoder::InvalidRequest, # not found
|
13
|
+
423 => Geocoder::InvalidRequest # bogon/reserved IP address
|
14
|
+
}
|
15
|
+
ERROR_CODES.default = Geocoder::Error
|
16
|
+
|
17
|
+
def name
|
18
|
+
"Ipgeolocation"
|
19
|
+
end
|
20
|
+
|
21
|
+
def supported_protocols
|
22
|
+
[:https]
|
23
|
+
end
|
24
|
+
|
25
|
+
private # ----------------------------------------------------------------
|
26
|
+
|
27
|
+
def base_query_url(query)
|
28
|
+
"#{protocol}://api.ipgeolocation.io/ipgeo?"
|
29
|
+
end
|
30
|
+
def query_url_params(query)
|
31
|
+
{
|
32
|
+
ip: query.sanitized_text,
|
33
|
+
apiKey: configuration.api_key
|
34
|
+
}.merge(super)
|
35
|
+
end
|
36
|
+
|
37
|
+
def results(query)
|
38
|
+
# don't look up a loopback or private address, just return the stored result
|
39
|
+
return [reserved_result(query.text)] if query.internal_ip_address?
|
40
|
+
[fetch_data(query)]
|
41
|
+
end
|
42
|
+
|
43
|
+
def reserved_result(ip)
|
44
|
+
{
|
45
|
+
"ip" => ip,
|
46
|
+
"country_name" => "Reserved",
|
47
|
+
"country_code2" => "RD"
|
48
|
+
}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'geocoder/lookups/base'
|
4
|
+
require 'geocoder/results/ipqualityscore'
|
5
|
+
|
6
|
+
module Geocoder::Lookup
|
7
|
+
class Ipqualityscore < Base
|
8
|
+
|
9
|
+
def name
|
10
|
+
"IPQualityScore"
|
11
|
+
end
|
12
|
+
|
13
|
+
def required_api_key_parts
|
14
|
+
['api_key']
|
15
|
+
end
|
16
|
+
|
17
|
+
private # ---------------------------------------------------------------
|
18
|
+
|
19
|
+
def base_query_url(query)
|
20
|
+
"#{protocol}://ipqualityscore.com/api/json/ip/#{configuration.api_key}/#{query.sanitized_text}?"
|
21
|
+
end
|
22
|
+
|
23
|
+
def valid_response?(response)
|
24
|
+
if (json = parse_json(response.body))
|
25
|
+
success = json['success']
|
26
|
+
end
|
27
|
+
super && success == true
|
28
|
+
end
|
29
|
+
|
30
|
+
def results(query, reverse = false)
|
31
|
+
return [] unless doc = fetch_data(query)
|
32
|
+
|
33
|
+
return [doc] if doc['success']
|
34
|
+
|
35
|
+
case doc['message']
|
36
|
+
when /invalid (.*) key/i
|
37
|
+
raise_error Geocoder::InvalidApiKey ||
|
38
|
+
Geocoder.log(:warn, "#{name} API error: invalid api key.")
|
39
|
+
when /insufficient credits/, /exceeded your request quota/
|
40
|
+
raise_error Geocoder::OverQueryLimitError ||
|
41
|
+
Geocoder.log(:warn, "#{name} API error: query limit exceeded.")
|
42
|
+
when /invalid (.*) address/i
|
43
|
+
raise_error Geocoder::InvalidRequest ||
|
44
|
+
Geocoder.log(:warn, "#{name} API error: invalid request.")
|
45
|
+
end
|
46
|
+
|
47
|
+
[doc]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'geocoder/lookups/base'
|
2
|
+
require 'geocoder/results/ipregistry'
|
3
|
+
|
4
|
+
module Geocoder::Lookup
|
5
|
+
class Ipregistry < Base
|
6
|
+
|
7
|
+
ERROR_CODES = {
|
8
|
+
400 => Geocoder::InvalidRequest,
|
9
|
+
401 => Geocoder::InvalidRequest,
|
10
|
+
402 => Geocoder::OverQueryLimitError,
|
11
|
+
403 => Geocoder::InvalidApiKey,
|
12
|
+
451 => Geocoder::RequestDenied,
|
13
|
+
500 => Geocoder::Error
|
14
|
+
}
|
15
|
+
ERROR_CODES.default = Geocoder::Error
|
16
|
+
|
17
|
+
def name
|
18
|
+
"Ipregistry"
|
19
|
+
end
|
20
|
+
|
21
|
+
def supported_protocols
|
22
|
+
[:https, :http]
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def base_query_url(query)
|
28
|
+
"#{protocol}://#{host}/#{query.sanitized_text}?"
|
29
|
+
end
|
30
|
+
|
31
|
+
def cache_key(query)
|
32
|
+
query_url(query)
|
33
|
+
end
|
34
|
+
|
35
|
+
def host
|
36
|
+
configuration[:host] || "api.ipregistry.co"
|
37
|
+
end
|
38
|
+
|
39
|
+
def query_url_params(query)
|
40
|
+
{
|
41
|
+
key: configuration.api_key
|
42
|
+
}.merge(super)
|
43
|
+
end
|
44
|
+
|
45
|
+
def results(query)
|
46
|
+
# don't look up a loopback or private address, just return the stored result
|
47
|
+
return [reserved_result(query.text)] if query.internal_ip_address?
|
48
|
+
|
49
|
+
return [] unless (doc = fetch_data(query))
|
50
|
+
|
51
|
+
if (error = doc['error'])
|
52
|
+
code = error['code']
|
53
|
+
msg = error['message']
|
54
|
+
raise_error(ERROR_CODES[code], msg ) || Geocoder.log(:warn, "Ipregistry API error: #{msg}")
|
55
|
+
return []
|
56
|
+
end
|
57
|
+
[doc]
|
58
|
+
end
|
59
|
+
|
60
|
+
def reserved_result(ip)
|
61
|
+
{
|
62
|
+
"ip" => ip,
|
63
|
+
"country_name" => "Reserved",
|
64
|
+
"country_code" => "RD"
|
65
|
+
}
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -25,8 +25,7 @@ module Geocoder::Lookup
|
|
25
25
|
# The API returned a 404 response, which indicates no results found
|
26
26
|
elsif doc['error']['type'] == 'api_error'
|
27
27
|
[]
|
28
|
-
elsif
|
29
|
-
doc['error']['type'] == 'authentication_error'
|
28
|
+
elsif doc['error']['type'] == 'authentication_error'
|
30
29
|
raise_error(Geocoder::InvalidApiKey) ||
|
31
30
|
Geocoder.log(:warn, "LatLon.io service error: invalid API key.")
|
32
31
|
else
|
@@ -11,6 +11,10 @@ module Geocoder::Lookup
|
|
11
11
|
["api_key"]
|
12
12
|
end
|
13
13
|
|
14
|
+
def supported_protocols
|
15
|
+
[:https]
|
16
|
+
end
|
17
|
+
|
14
18
|
private # ----------------------------------------------------------------
|
15
19
|
|
16
20
|
def base_query_url(query)
|
@@ -25,7 +29,7 @@ module Geocoder::Lookup
|
|
25
29
|
end
|
26
30
|
|
27
31
|
def configured_host
|
28
|
-
configuration[:host] || "locationiq.
|
32
|
+
configuration[:host] || "us1.locationiq.com"
|
29
33
|
end
|
30
34
|
|
31
35
|
def results(query)
|
@@ -30,14 +30,14 @@ module Geocoder::Lookup
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def mapbox_search_term(query)
|
33
|
-
require '
|
33
|
+
require 'erb' unless defined?(ERB) && defined?(ERB::Util.url_encode)
|
34
34
|
if query.reverse_geocode?
|
35
35
|
lat,lon = query.coordinates
|
36
|
-
"#{
|
36
|
+
"#{ERB::Util.url_encode lon},#{ERB::Util.url_encode lat}"
|
37
37
|
else
|
38
38
|
# truncate at first semicolon so Mapbox doesn't go into batch mode
|
39
39
|
# (see Github issue #1299)
|
40
|
-
|
40
|
+
ERB::Util.url_encode query.text.to_s.split(';').first.to_s
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -30,7 +30,13 @@ module Geocoder::Lookup
|
|
30
30
|
def results(query)
|
31
31
|
if configuration[:file]
|
32
32
|
geoip_class = RUBY_PLATFORM == "java" ? JGeoIP : GeoIP
|
33
|
-
|
33
|
+
geoip_instance = geoip_class.new(configuration[:file])
|
34
|
+
result =
|
35
|
+
if configuration[:package] == :country
|
36
|
+
geoip_instance.country(query.to_s)
|
37
|
+
else
|
38
|
+
geoip_instance.city(query.to_s)
|
39
|
+
end
|
34
40
|
result.nil? ? [] : [encode_hash(result.to_hash)]
|
35
41
|
elsif configuration[:package] == :city
|
36
42
|
addr = IPAddr.new(query.text).to_i
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'geocoder/lookups/base'
|
2
|
+
require "geocoder/results/melissa_street"
|
3
|
+
|
4
|
+
module Geocoder::Lookup
|
5
|
+
class MelissaStreet < Base
|
6
|
+
|
7
|
+
def name
|
8
|
+
"MelissaStreet"
|
9
|
+
end
|
10
|
+
|
11
|
+
def results(query)
|
12
|
+
return [] unless doc = fetch_data(query)
|
13
|
+
|
14
|
+
if doc["TransmissionResults"] == "GE05"
|
15
|
+
raise_error(Geocoder::InvalidApiKey) ||
|
16
|
+
Geocoder.log(:warn, "Melissa service error: invalid API key.")
|
17
|
+
end
|
18
|
+
|
19
|
+
return doc["Records"]
|
20
|
+
end
|
21
|
+
|
22
|
+
private # ---------------------------------------------------------------
|
23
|
+
|
24
|
+
def base_query_url(query)
|
25
|
+
"#{protocol}://address.melissadata.net/v3/WEB/GlobalAddress/doGlobalAddress?"
|
26
|
+
end
|
27
|
+
|
28
|
+
def query_url_params(query)
|
29
|
+
params = {
|
30
|
+
id: configuration.api_key,
|
31
|
+
format: "JSON",
|
32
|
+
a1: query.sanitized_text,
|
33
|
+
loc: query.options[:city],
|
34
|
+
admarea: query.options[:state],
|
35
|
+
postal: query.options[:postal],
|
36
|
+
ctry: query.options[:country]
|
37
|
+
}
|
38
|
+
params.merge(super)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'geocoder/lookups/base'
|
2
|
+
require "geocoder/results/nationaal_georegister_nl"
|
3
|
+
|
4
|
+
module Geocoder::Lookup
|
5
|
+
class NationaalGeoregisterNl < Base
|
6
|
+
|
7
|
+
def name
|
8
|
+
'Nationaal Georegister Nederland'
|
9
|
+
end
|
10
|
+
|
11
|
+
private # ---------------------------------------------------------------
|
12
|
+
|
13
|
+
def cache_key(query)
|
14
|
+
base_query_url(query) + hash_to_query(query_url_params(query))
|
15
|
+
end
|
16
|
+
|
17
|
+
def base_query_url(query)
|
18
|
+
"#{protocol}://geodata.nationaalgeoregister.nl/locatieserver/v3/free?"
|
19
|
+
end
|
20
|
+
|
21
|
+
def valid_response?(response)
|
22
|
+
json = parse_json(response.body)
|
23
|
+
super(response) if json
|
24
|
+
end
|
25
|
+
|
26
|
+
def results(query)
|
27
|
+
return [] unless doc = fetch_data(query)
|
28
|
+
return doc['response']['docs']
|
29
|
+
end
|
30
|
+
|
31
|
+
def query_url_params(query)
|
32
|
+
{
|
33
|
+
fl: '*',
|
34
|
+
q: query.text
|
35
|
+
}.merge(super)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require 'geocoder/lookups/base'
|
3
|
+
require 'geocoder/results/osmnames'
|
4
|
+
|
5
|
+
module Geocoder::Lookup
|
6
|
+
class Osmnames < Base
|
7
|
+
|
8
|
+
def name
|
9
|
+
'OSM Names'
|
10
|
+
end
|
11
|
+
|
12
|
+
def required_api_key_parts
|
13
|
+
configuration[:host] ? [] : ['key']
|
14
|
+
end
|
15
|
+
|
16
|
+
def supported_protocols
|
17
|
+
[:https]
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def base_query_url(query)
|
23
|
+
"#{base_url(query)}/#{params_url(query)}.js?"
|
24
|
+
end
|
25
|
+
|
26
|
+
def base_url(query)
|
27
|
+
host = configuration[:host] || 'geocoder.tilehosting.com'
|
28
|
+
"#{protocol}://#{host}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def params_url(query)
|
32
|
+
method, args = 'q', CGI.escape(query.sanitized_text)
|
33
|
+
method, args = 'r', query.coordinates.join('/') if query.reverse_geocode?
|
34
|
+
"#{country_limited(query)}#{method}/#{args}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def results(query)
|
38
|
+
return [] unless doc = fetch_data(query)
|
39
|
+
if (error = doc['message'])
|
40
|
+
raise_error(Geocoder::InvalidRequest, error) ||
|
41
|
+
Geocoder.log(:warn, "OSMNames Geocoding API error: #{error}")
|
42
|
+
else
|
43
|
+
return doc['results']
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def query_url_params(query)
|
48
|
+
{
|
49
|
+
key: configuration.api_key
|
50
|
+
}.merge(super)
|
51
|
+
end
|
52
|
+
|
53
|
+
def country_limited(query)
|
54
|
+
"#{query.options[:country_code].downcase}/" if query.options[:country_code] && !query.reverse_geocode?
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|