ultra-fast-mod 0.0.1
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 +7 -0
- data/geocoder-1.8.6/CHANGELOG.md +669 -0
- data/geocoder-1.8.6/LICENSE +20 -0
- data/geocoder-1.8.6/README.md +827 -0
- data/geocoder-1.8.6/bin/console +13 -0
- data/geocoder-1.8.6/bin/geocode +5 -0
- data/geocoder-1.8.6/examples/app_defined_lookup_services.rb +22 -0
- data/geocoder-1.8.6/examples/cache_bypass.rb +48 -0
- data/geocoder-1.8.6/examples/reverse_geocode_job.rb +40 -0
- data/geocoder-1.8.6/lib/easting_northing.rb +171 -0
- data/geocoder-1.8.6/lib/generators/geocoder/config/config_generator.rb +14 -0
- data/geocoder-1.8.6/lib/generators/geocoder/config/templates/initializer.rb +27 -0
- data/geocoder-1.8.6/lib/generators/geocoder/maxmind/geolite_city_generator.rb +30 -0
- data/geocoder-1.8.6/lib/generators/geocoder/maxmind/geolite_country_generator.rb +30 -0
- data/geocoder-1.8.6/lib/generators/geocoder/maxmind/templates/migration/geolite_city.rb +30 -0
- data/geocoder-1.8.6/lib/generators/geocoder/maxmind/templates/migration/geolite_country.rb +17 -0
- data/geocoder-1.8.6/lib/generators/geocoder/migration_version.rb +15 -0
- data/geocoder-1.8.6/lib/geocoder/cache.rb +77 -0
- data/geocoder-1.8.6/lib/geocoder/cache_stores/base.rb +40 -0
- data/geocoder-1.8.6/lib/geocoder/cache_stores/generic.rb +35 -0
- data/geocoder-1.8.6/lib/geocoder/cache_stores/redis.rb +34 -0
- data/geocoder-1.8.6/lib/geocoder/calculations.rb +420 -0
- data/geocoder-1.8.6/lib/geocoder/cli.rb +121 -0
- data/geocoder-1.8.6/lib/geocoder/configuration.rb +151 -0
- data/geocoder-1.8.6/lib/geocoder/configuration_hash.rb +11 -0
- data/geocoder-1.8.6/lib/geocoder/esri_token.rb +38 -0
- data/geocoder-1.8.6/lib/geocoder/exceptions.rb +40 -0
- data/geocoder-1.8.6/lib/geocoder/ip_address.rb +36 -0
- data/geocoder-1.8.6/lib/geocoder/kernel_logger.rb +25 -0
- data/geocoder-1.8.6/lib/geocoder/logger.rb +47 -0
- data/geocoder-1.8.6/lib/geocoder/lookup.rb +155 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/abstract_api.rb +46 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/amap.rb +63 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/amazon_location_service.rb +58 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/azure.rb +56 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/baidu.rb +63 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/baidu_ip.rb +30 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ban_data_gouv_fr.rb +143 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/base.rb +351 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/bing.rb +82 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/db_ip_com.rb +52 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/esri.rb +114 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/freegeoip.rb +62 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/geoapify.rb +78 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/geocoder_ca.rb +53 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/geocodio.rb +42 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/geoip2.rb +49 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/geoportail_lu.rb +65 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/google.rb +100 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/google_places_details.rb +64 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/google_places_search.rb +75 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/google_premier.rb +61 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/here.rb +73 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ip2location.rb +71 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ip2location_io.rb +62 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ip2location_lite.rb +40 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ipapi_com.rb +82 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ipbase.rb +49 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ipdata_co.rb +62 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ipgeolocation.rb +51 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ipinfo_io.rb +44 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ipinfo_io_lite.rb +42 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ipqualityscore.rb +50 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ipregistry.rb +68 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/ipstack.rb +63 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/latlon.rb +58 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/location_iq.rb +54 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/mapbox.rb +60 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/mapquest.rb +58 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/maxmind.rb +90 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/maxmind_geoip2.rb +70 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/maxmind_local.rb +71 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/melissa_street.rb +41 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/nationaal_georegister_nl.rb +38 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/nominatim.rb +64 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/opencagedata.rb +65 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/osmnames.rb +57 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/pc_miler.rb +87 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/pdok_nl.rb +43 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/pelias.rb +63 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/photon.rb +89 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/pickpoint.rb +41 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/pointpin.rb +69 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/postcode_anywhere_uk.rb +50 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/postcodes_io.rb +31 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/smarty_streets.rb +68 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/telize.rb +75 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/tencent.rb +59 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/test.rb +49 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/twogis.rb +58 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/uk_ordnance_survey_names.rb +59 -0
- data/geocoder-1.8.6/lib/geocoder/lookups/yandex.rb +61 -0
- data/geocoder-1.8.6/lib/geocoder/models/active_record.rb +51 -0
- data/geocoder-1.8.6/lib/geocoder/models/base.rb +39 -0
- data/geocoder-1.8.6/lib/geocoder/models/mongo_base.rb +62 -0
- data/geocoder-1.8.6/lib/geocoder/models/mongo_mapper.rb +26 -0
- data/geocoder-1.8.6/lib/geocoder/models/mongoid.rb +32 -0
- data/geocoder-1.8.6/lib/geocoder/query.rb +125 -0
- data/geocoder-1.8.6/lib/geocoder/railtie.rb +26 -0
- data/geocoder-1.8.6/lib/geocoder/request.rb +114 -0
- data/geocoder-1.8.6/lib/geocoder/results/abstract_api.rb +146 -0
- data/geocoder-1.8.6/lib/geocoder/results/amap.rb +87 -0
- data/geocoder-1.8.6/lib/geocoder/results/amazon_location_service.rb +62 -0
- data/geocoder-1.8.6/lib/geocoder/results/azure.rb +65 -0
- data/geocoder-1.8.6/lib/geocoder/results/baidu.rb +75 -0
- data/geocoder-1.8.6/lib/geocoder/results/baidu_ip.rb +62 -0
- data/geocoder-1.8.6/lib/geocoder/results/ban_data_gouv_fr.rb +282 -0
- data/geocoder-1.8.6/lib/geocoder/results/base.rb +79 -0
- data/geocoder-1.8.6/lib/geocoder/results/bing.rb +52 -0
- data/geocoder-1.8.6/lib/geocoder/results/db_ip_com.rb +58 -0
- data/geocoder-1.8.6/lib/geocoder/results/esri.rb +78 -0
- data/geocoder-1.8.6/lib/geocoder/results/freegeoip.rb +40 -0
- data/geocoder-1.8.6/lib/geocoder/results/geoapify.rb +179 -0
- data/geocoder-1.8.6/lib/geocoder/results/geocoder_ca.rb +60 -0
- data/geocoder-1.8.6/lib/geocoder/results/geocodio.rb +78 -0
- data/geocoder-1.8.6/lib/geocoder/results/geoip2.rb +76 -0
- data/geocoder-1.8.6/lib/geocoder/results/geoportail_lu.rb +71 -0
- data/geocoder-1.8.6/lib/geocoder/results/google.rb +150 -0
- data/geocoder-1.8.6/lib/geocoder/results/google_places_details.rb +39 -0
- data/geocoder-1.8.6/lib/geocoder/results/google_places_search.rb +52 -0
- data/geocoder-1.8.6/lib/geocoder/results/google_premier.rb +6 -0
- data/geocoder-1.8.6/lib/geocoder/results/here.rb +77 -0
- data/geocoder-1.8.6/lib/geocoder/results/ip2location.rb +22 -0
- data/geocoder-1.8.6/lib/geocoder/results/ip2location_io.rb +21 -0
- data/geocoder-1.8.6/lib/geocoder/results/ip2location_lite.rb +47 -0
- data/geocoder-1.8.6/lib/geocoder/results/ipapi_com.rb +45 -0
- data/geocoder-1.8.6/lib/geocoder/results/ipbase.rb +40 -0
- data/geocoder-1.8.6/lib/geocoder/results/ipdata_co.rb +40 -0
- data/geocoder-1.8.6/lib/geocoder/results/ipgeolocation.rb +59 -0
- data/geocoder-1.8.6/lib/geocoder/results/ipinfo_io.rb +48 -0
- data/geocoder-1.8.6/lib/geocoder/results/ipinfo_io_lite.rb +16 -0
- data/geocoder-1.8.6/lib/geocoder/results/ipqualityscore.rb +54 -0
- data/geocoder-1.8.6/lib/geocoder/results/ipregistry.rb +304 -0
- data/geocoder-1.8.6/lib/geocoder/results/ipstack.rb +60 -0
- data/geocoder-1.8.6/lib/geocoder/results/latlon.rb +71 -0
- data/geocoder-1.8.6/lib/geocoder/results/location_iq.rb +6 -0
- data/geocoder-1.8.6/lib/geocoder/results/mapbox.rb +80 -0
- data/geocoder-1.8.6/lib/geocoder/results/mapquest.rb +48 -0
- data/geocoder-1.8.6/lib/geocoder/results/maxmind.rb +130 -0
- data/geocoder-1.8.6/lib/geocoder/results/maxmind_geoip2.rb +9 -0
- data/geocoder-1.8.6/lib/geocoder/results/maxmind_local.rb +44 -0
- data/geocoder-1.8.6/lib/geocoder/results/melissa_street.rb +46 -0
- data/geocoder-1.8.6/lib/geocoder/results/nationaal_georegister_nl.rb +62 -0
- data/geocoder-1.8.6/lib/geocoder/results/nominatim.rb +121 -0
- data/geocoder-1.8.6/lib/geocoder/results/opencagedata.rb +100 -0
- data/geocoder-1.8.6/lib/geocoder/results/osmnames.rb +56 -0
- data/geocoder-1.8.6/lib/geocoder/results/pc_miler.rb +98 -0
- data/geocoder-1.8.6/lib/geocoder/results/pdok_nl.rb +62 -0
- data/geocoder-1.8.6/lib/geocoder/results/pelias.rb +58 -0
- data/geocoder-1.8.6/lib/geocoder/results/photon.rb +119 -0
- data/geocoder-1.8.6/lib/geocoder/results/pickpoint.rb +6 -0
- data/geocoder-1.8.6/lib/geocoder/results/pointpin.rb +40 -0
- data/geocoder-1.8.6/lib/geocoder/results/postcode_anywhere_uk.rb +42 -0
- data/geocoder-1.8.6/lib/geocoder/results/postcodes_io.rb +40 -0
- data/geocoder-1.8.6/lib/geocoder/results/smarty_streets.rb +142 -0
- data/geocoder-1.8.6/lib/geocoder/results/telize.rb +40 -0
- data/geocoder-1.8.6/lib/geocoder/results/tencent.rb +72 -0
- data/geocoder-1.8.6/lib/geocoder/results/test.rb +33 -0
- data/geocoder-1.8.6/lib/geocoder/results/twogis.rb +76 -0
- data/geocoder-1.8.6/lib/geocoder/results/uk_ordnance_survey_names.rb +59 -0
- data/geocoder-1.8.6/lib/geocoder/results/yandex.rb +292 -0
- data/geocoder-1.8.6/lib/geocoder/sql.rb +110 -0
- data/geocoder-1.8.6/lib/geocoder/stores/active_record.rb +329 -0
- data/geocoder-1.8.6/lib/geocoder/stores/base.rb +115 -0
- data/geocoder-1.8.6/lib/geocoder/stores/mongo_base.rb +58 -0
- data/geocoder-1.8.6/lib/geocoder/stores/mongo_mapper.rb +13 -0
- data/geocoder-1.8.6/lib/geocoder/stores/mongoid.rb +13 -0
- data/geocoder-1.8.6/lib/geocoder/util.rb +29 -0
- data/geocoder-1.8.6/lib/geocoder/version.rb +3 -0
- data/geocoder-1.8.6/lib/geocoder.rb +48 -0
- data/geocoder-1.8.6/lib/maxmind_database.rb +109 -0
- data/geocoder-1.8.6/lib/tasks/geocoder.rake +54 -0
- data/geocoder-1.8.6/lib/tasks/maxmind.rake +73 -0
- data/ultra-fast-mod.gemspec +12 -0
- metadata +214 -0
|
@@ -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
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
require 'geocoder/lookups/base'
|
|
2
|
+
require 'geocoder/results/ipstack'
|
|
3
|
+
|
|
4
|
+
module Geocoder::Lookup
|
|
5
|
+
class Ipstack < Base
|
|
6
|
+
|
|
7
|
+
ERROR_CODES = {
|
|
8
|
+
404 => Geocoder::InvalidRequest,
|
|
9
|
+
101 => Geocoder::InvalidApiKey,
|
|
10
|
+
102 => Geocoder::Error,
|
|
11
|
+
103 => Geocoder::InvalidRequest,
|
|
12
|
+
104 => Geocoder::OverQueryLimitError,
|
|
13
|
+
105 => Geocoder::RequestDenied,
|
|
14
|
+
301 => Geocoder::InvalidRequest,
|
|
15
|
+
302 => Geocoder::InvalidRequest,
|
|
16
|
+
303 => Geocoder::RequestDenied,
|
|
17
|
+
}
|
|
18
|
+
ERROR_CODES.default = Geocoder::Error
|
|
19
|
+
|
|
20
|
+
def name
|
|
21
|
+
"Ipstack"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private # ----------------------------------------------------------------
|
|
25
|
+
|
|
26
|
+
def base_query_url(query)
|
|
27
|
+
"#{protocol}://#{host}/#{query.sanitized_text}?"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def query_url_params(query)
|
|
31
|
+
{
|
|
32
|
+
access_key: configuration.api_key
|
|
33
|
+
}.merge(super)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def results(query)
|
|
37
|
+
# don't look up a loopback or private address, just return the stored result
|
|
38
|
+
return [reserved_result(query.text)] if query.internal_ip_address?
|
|
39
|
+
|
|
40
|
+
return [] unless doc = fetch_data(query)
|
|
41
|
+
|
|
42
|
+
if error = doc['error']
|
|
43
|
+
code = error['code']
|
|
44
|
+
msg = error['info']
|
|
45
|
+
raise_error(ERROR_CODES[code], msg ) || Geocoder.log(:warn, "Ipstack Geocoding API error: #{msg}")
|
|
46
|
+
return []
|
|
47
|
+
end
|
|
48
|
+
[doc]
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def reserved_result(ip)
|
|
52
|
+
{
|
|
53
|
+
"ip" => ip,
|
|
54
|
+
"country_name" => "Reserved",
|
|
55
|
+
"country_code" => "RD"
|
|
56
|
+
}
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def host
|
|
60
|
+
configuration[:host] || "api.ipstack.com"
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require 'geocoder/lookups/base'
|
|
2
|
+
require 'geocoder/results/latlon'
|
|
3
|
+
|
|
4
|
+
module Geocoder::Lookup
|
|
5
|
+
class Latlon < Base
|
|
6
|
+
|
|
7
|
+
def name
|
|
8
|
+
"LatLon.io"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def required_api_key_parts
|
|
12
|
+
["api_key"]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private # ---------------------------------------------------------------
|
|
16
|
+
|
|
17
|
+
def base_query_url(query)
|
|
18
|
+
"#{protocol}://latlon.io/api/v1/#{'reverse_' if query.reverse_geocode?}geocode?"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def results(query)
|
|
22
|
+
return [] unless doc = fetch_data(query)
|
|
23
|
+
if doc['error'].nil?
|
|
24
|
+
[doc]
|
|
25
|
+
# The API returned a 404 response, which indicates no results found
|
|
26
|
+
elsif doc['error']['type'] == 'api_error'
|
|
27
|
+
[]
|
|
28
|
+
elsif doc['error']['type'] == 'authentication_error'
|
|
29
|
+
raise_error(Geocoder::InvalidApiKey) ||
|
|
30
|
+
Geocoder.log(:warn, "LatLon.io service error: invalid API key.")
|
|
31
|
+
else
|
|
32
|
+
[]
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def supported_protocols
|
|
37
|
+
[:https]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
private # ---------------------------------------------------------------
|
|
41
|
+
|
|
42
|
+
def query_url_params(query)
|
|
43
|
+
if query.reverse_geocode?
|
|
44
|
+
{
|
|
45
|
+
:token => configuration.api_key,
|
|
46
|
+
:lat => query.coordinates[0],
|
|
47
|
+
:lon => query.coordinates[1]
|
|
48
|
+
}.merge(super)
|
|
49
|
+
else
|
|
50
|
+
{
|
|
51
|
+
:token => configuration.api_key,
|
|
52
|
+
:address => query.sanitized_text
|
|
53
|
+
}.merge(super)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require 'geocoder/lookups/nominatim'
|
|
2
|
+
require "geocoder/results/location_iq"
|
|
3
|
+
|
|
4
|
+
module Geocoder::Lookup
|
|
5
|
+
class LocationIq < Nominatim
|
|
6
|
+
def name
|
|
7
|
+
"LocationIq"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def required_api_key_parts
|
|
11
|
+
["api_key"]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def supported_protocols
|
|
15
|
+
[:https]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private # ----------------------------------------------------------------
|
|
19
|
+
|
|
20
|
+
def base_query_url(query)
|
|
21
|
+
method = query.reverse_geocode? ? "reverse" : "search"
|
|
22
|
+
"#{protocol}://#{configured_host}/v1/#{method}.php?"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def query_url_params(query)
|
|
26
|
+
{
|
|
27
|
+
key: configuration.api_key
|
|
28
|
+
}.merge(super)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def configured_host
|
|
32
|
+
configuration[:host] || "us1.locationiq.com"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def results(query)
|
|
36
|
+
return [] unless doc = fetch_data(query)
|
|
37
|
+
|
|
38
|
+
if !doc.is_a?(Array)
|
|
39
|
+
case doc['error']
|
|
40
|
+
when "Invalid key"
|
|
41
|
+
raise_error(Geocoder::InvalidApiKey, doc['error'])
|
|
42
|
+
when "Key not active - Please write to contact@unwiredlabs.com"
|
|
43
|
+
raise_error(Geocoder::RequestDenied, doc['error'])
|
|
44
|
+
when "Rate Limited"
|
|
45
|
+
raise_error(Geocoder::OverQueryLimitError, doc['error'])
|
|
46
|
+
when "Unknown error - Please try again after some time"
|
|
47
|
+
raise_error(Geocoder::InvalidRequest, doc['error'])
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
doc.is_a?(Array) ? doc : [doc]
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require 'geocoder/lookups/base'
|
|
2
|
+
require "geocoder/results/mapbox"
|
|
3
|
+
|
|
4
|
+
module Geocoder::Lookup
|
|
5
|
+
class Mapbox < Base
|
|
6
|
+
|
|
7
|
+
def name
|
|
8
|
+
"Mapbox"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
private # ---------------------------------------------------------------
|
|
12
|
+
|
|
13
|
+
def base_query_url(query)
|
|
14
|
+
"#{protocol}://api.mapbox.com/geocoding/v5/#{dataset}/#{mapbox_search_term(query)}.json?"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def results(query)
|
|
18
|
+
return [] unless data = fetch_data(query)
|
|
19
|
+
if data['features']
|
|
20
|
+
sort_relevant_feature(data['features'])
|
|
21
|
+
elsif data['message'] =~ /Invalid\sToken/
|
|
22
|
+
raise_error(Geocoder::InvalidApiKey, data['message'])
|
|
23
|
+
[]
|
|
24
|
+
else
|
|
25
|
+
[]
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def query_url_params(query)
|
|
30
|
+
{access_token: configuration.api_key}.merge(super(query))
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def mapbox_search_term(query)
|
|
34
|
+
require 'erb' unless defined?(ERB) && defined?(ERB::Util.url_encode)
|
|
35
|
+
if query.reverse_geocode?
|
|
36
|
+
lat,lon = query.coordinates
|
|
37
|
+
"#{ERB::Util.url_encode lon},#{ERB::Util.url_encode lat}"
|
|
38
|
+
else
|
|
39
|
+
# truncate at first semicolon so Mapbox doesn't go into batch mode
|
|
40
|
+
# (see Github issue #1299)
|
|
41
|
+
ERB::Util.url_encode query.text.to_s.split(';').first.to_s
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def dataset
|
|
46
|
+
configuration[:dataset] || "mapbox.places"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def supported_protocols
|
|
50
|
+
[:https]
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def sort_relevant_feature(features)
|
|
54
|
+
# Sort by descending relevance; Favor original order for equal relevance (eg occurs for reverse geocoding)
|
|
55
|
+
features.sort_by do |feature|
|
|
56
|
+
[feature["relevance"],-features.index(feature)]
|
|
57
|
+
end.reverse
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require 'cgi'
|
|
2
|
+
require 'geocoder/lookups/base'
|
|
3
|
+
require "geocoder/results/mapquest"
|
|
4
|
+
|
|
5
|
+
module Geocoder::Lookup
|
|
6
|
+
class Mapquest < Base
|
|
7
|
+
|
|
8
|
+
def name
|
|
9
|
+
"Mapquest"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def required_api_key_parts
|
|
13
|
+
["key"]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private # ---------------------------------------------------------------
|
|
17
|
+
|
|
18
|
+
def base_query_url(query)
|
|
19
|
+
domain = configuration[:open] ? "open" : "www"
|
|
20
|
+
"#{protocol}://#{domain}.mapquestapi.com/geocoding/v1/#{search_type(query)}?"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def search_type(query)
|
|
24
|
+
query.reverse_geocode? ? "reverse" : "address"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def query_url_params(query)
|
|
28
|
+
params = { :location => query.sanitized_text }
|
|
29
|
+
if key = configuration.api_key
|
|
30
|
+
params[:key] = CGI.unescape(key)
|
|
31
|
+
end
|
|
32
|
+
params.merge(super)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# http://www.mapquestapi.com/geocoding/status_codes.html
|
|
36
|
+
# http://open.mapquestapi.com/geocoding/status_codes.html
|
|
37
|
+
def results(query)
|
|
38
|
+
return [] unless doc = fetch_data(query)
|
|
39
|
+
return doc["results"][0]['locations'] if doc['info']['statuscode'] == 0 # A successful geocode call
|
|
40
|
+
|
|
41
|
+
messages = doc['info']['messages'].join
|
|
42
|
+
|
|
43
|
+
case doc['info']['statuscode']
|
|
44
|
+
when 400 # Error with input
|
|
45
|
+
raise_error(Geocoder::InvalidRequest, messages) ||
|
|
46
|
+
Geocoder.log(:warn, "Mapquest Geocoding API error: #{messages}")
|
|
47
|
+
when 403 # Key related error
|
|
48
|
+
raise_error(Geocoder::InvalidApiKey, messages) ||
|
|
49
|
+
Geocoder.log(:warn, "Mapquest Geocoding API error: #{messages}")
|
|
50
|
+
when 500 # Unknown error
|
|
51
|
+
raise_error(Geocoder::Error, messages) ||
|
|
52
|
+
Geocoder.log(:warn, "Mapquest Geocoding API error: #{messages}")
|
|
53
|
+
end
|
|
54
|
+
[]
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
require 'geocoder/lookups/base'
|
|
2
|
+
require 'geocoder/results/maxmind'
|
|
3
|
+
require 'csv'
|
|
4
|
+
|
|
5
|
+
module Geocoder::Lookup
|
|
6
|
+
class Maxmind < Base
|
|
7
|
+
|
|
8
|
+
def name
|
|
9
|
+
"MaxMind"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
private # ---------------------------------------------------------------
|
|
13
|
+
|
|
14
|
+
def base_query_url(query)
|
|
15
|
+
"#{protocol}://geoip.maxmind.com/#{service_code}?"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
##
|
|
19
|
+
# Return the name of the configured service, or raise an exception.
|
|
20
|
+
#
|
|
21
|
+
def configured_service!
|
|
22
|
+
if s = configuration[:service] and services.keys.include?(s)
|
|
23
|
+
return s
|
|
24
|
+
else
|
|
25
|
+
raise(
|
|
26
|
+
Geocoder::ConfigurationError,
|
|
27
|
+
"When using MaxMind you MUST specify a service name: " +
|
|
28
|
+
"Geocoder.configure(:maxmind => {:service => ...}), " +
|
|
29
|
+
"where '...' is one of: #{services.keys.inspect}"
|
|
30
|
+
)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def service_code
|
|
35
|
+
services[configured_service!]
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def service_response_fields_count
|
|
39
|
+
Geocoder::Result::Maxmind.field_names[configured_service!].size
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def data_contains_error?(parsed_data)
|
|
43
|
+
# if all fields given then there is an error
|
|
44
|
+
parsed_data.size == service_response_fields_count and !parsed_data.last.nil?
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
##
|
|
48
|
+
# Service names mapped to code used in URL.
|
|
49
|
+
#
|
|
50
|
+
def services
|
|
51
|
+
{
|
|
52
|
+
:country => "a",
|
|
53
|
+
:city => "b",
|
|
54
|
+
:city_isp_org => "f",
|
|
55
|
+
:omni => "e"
|
|
56
|
+
}
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def results(query)
|
|
60
|
+
# don't look up a loopback or private address, just return the stored result
|
|
61
|
+
return [reserved_result] if query.internal_ip_address?
|
|
62
|
+
doc = fetch_data(query)
|
|
63
|
+
if doc and doc.is_a?(Array)
|
|
64
|
+
if !data_contains_error?(doc)
|
|
65
|
+
return [doc]
|
|
66
|
+
elsif doc.last == "INVALID_LICENSE_KEY"
|
|
67
|
+
raise_error(Geocoder::InvalidApiKey) || Geocoder.log(:warn, "Invalid MaxMind API key.")
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
return []
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def parse_raw_data(raw_data)
|
|
74
|
+
# Maxmind just returns text/plain as csv format but according to documentation,
|
|
75
|
+
# we get ISO-8859-1 encoded string. We need to convert it.
|
|
76
|
+
CSV.parse_line raw_data.force_encoding("ISO-8859-1").encode("UTF-8")
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def reserved_result
|
|
80
|
+
",,,,0,0,0,0,,,".split(",")
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def query_url_params(query)
|
|
84
|
+
{
|
|
85
|
+
:l => configuration.api_key,
|
|
86
|
+
:i => query.sanitized_text
|
|
87
|
+
}.merge(super)
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
require 'geocoder/lookups/base'
|
|
2
|
+
require 'geocoder/results/maxmind_geoip2'
|
|
3
|
+
|
|
4
|
+
module Geocoder::Lookup
|
|
5
|
+
class MaxmindGeoip2 < Base
|
|
6
|
+
|
|
7
|
+
def name
|
|
8
|
+
"MaxMind GeoIP2"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Maxmind's GeoIP2 Precision Services only supports HTTPS,
|
|
12
|
+
# otherwise a `404 Not Found` HTTP response will be returned
|
|
13
|
+
def supported_protocols
|
|
14
|
+
[:https]
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def query_url(query)
|
|
18
|
+
"#{protocol}://geoip.maxmind.com/geoip/v2.1/#{configured_service!}/#{query.sanitized_text.strip}"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private # ---------------------------------------------------------------
|
|
22
|
+
|
|
23
|
+
def cache_key(query)
|
|
24
|
+
query_url(query)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
##
|
|
28
|
+
# Return the name of the configured service, or raise an exception.
|
|
29
|
+
#
|
|
30
|
+
def configured_service!
|
|
31
|
+
if s = configuration[:service] and services.include?(s) and configuration[:basic_auth][:user] and configuration[:basic_auth][:password]
|
|
32
|
+
return s
|
|
33
|
+
else
|
|
34
|
+
raise(
|
|
35
|
+
Geocoder::ConfigurationError, "When using MaxMind GeoIP2 you must specify a service and credentials: Geocoder.configure(maxmind_geoip2: {service: ..., basic_auth: {user: ..., password: ...}}), where service is one of: #{services.inspect}"
|
|
36
|
+
)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def data_contains_error?(doc)
|
|
41
|
+
(["code", "error"] - doc.keys).empty?
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
##
|
|
45
|
+
# Service names used in URL.
|
|
46
|
+
#
|
|
47
|
+
def services
|
|
48
|
+
[
|
|
49
|
+
:country,
|
|
50
|
+
:city,
|
|
51
|
+
:insights,
|
|
52
|
+
]
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def results(query)
|
|
56
|
+
# don't look up a loopback or private address, just return the stored result
|
|
57
|
+
return [] if query.internal_ip_address?
|
|
58
|
+
|
|
59
|
+
doc = fetch_data(query)
|
|
60
|
+
if doc
|
|
61
|
+
if !data_contains_error?(doc)
|
|
62
|
+
return [doc]
|
|
63
|
+
else
|
|
64
|
+
Geocoder.log(:warn, "MaxMind GeoIP2 Geocoding API error: #{doc['code']} (#{doc['error']}).")
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
return []
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
require 'ipaddr'
|
|
2
|
+
require 'geocoder/lookups/base'
|
|
3
|
+
require 'geocoder/results/maxmind_local'
|
|
4
|
+
|
|
5
|
+
module Geocoder::Lookup
|
|
6
|
+
class MaxmindLocal < Base
|
|
7
|
+
|
|
8
|
+
def initialize
|
|
9
|
+
if !configuration[:file].nil?
|
|
10
|
+
begin
|
|
11
|
+
gem = RUBY_PLATFORM == 'java' ? 'jgeoip' : 'geoip'
|
|
12
|
+
require gem
|
|
13
|
+
rescue LoadError
|
|
14
|
+
raise "Could not load geoip dependency. To use MaxMind Local lookup you must add the #{gem} gem to your Gemfile or have it installed in your system."
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
super
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def name
|
|
21
|
+
"MaxMind Local"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def required_api_key_parts
|
|
25
|
+
[]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def results(query)
|
|
31
|
+
if configuration[:file]
|
|
32
|
+
geoip_class = RUBY_PLATFORM == "java" ? JGeoIP : GeoIP
|
|
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
|
|
40
|
+
result.nil? ? [] : [encode_hash(result.to_hash)]
|
|
41
|
+
elsif configuration[:package] == :city
|
|
42
|
+
addr = IPAddr.new(query.text).to_i
|
|
43
|
+
q = "SELECT l.country, l.region, l.city, l.latitude, l.longitude
|
|
44
|
+
FROM maxmind_geolite_city_location l WHERE l.loc_id = (SELECT b.loc_id FROM maxmind_geolite_city_blocks b
|
|
45
|
+
WHERE b.start_ip_num <= #{addr} AND #{addr} <= b.end_ip_num)"
|
|
46
|
+
format_result(q, [:country_name, :region_name, :city_name, :latitude, :longitude])
|
|
47
|
+
elsif configuration[:package] == :country
|
|
48
|
+
addr = IPAddr.new(query.text).to_i
|
|
49
|
+
q = "SELECT country, country_code FROM maxmind_geolite_country
|
|
50
|
+
WHERE start_ip_num <= #{addr} AND #{addr} <= end_ip_num"
|
|
51
|
+
format_result(q, [:country_name, :country_code2])
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def encode_hash(hash, encoding = "UTF-8")
|
|
56
|
+
hash.inject({}) do |h,i|
|
|
57
|
+
h[i[0]] = i[1].is_a?(String) ? i[1].encode(encoding) : i[1]
|
|
58
|
+
h
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def format_result(query, attr_names)
|
|
63
|
+
if r = ActiveRecord::Base.connection.execute(query).first
|
|
64
|
+
r = r.values if r.is_a?(Hash) # some db adapters return Hash, some Array
|
|
65
|
+
[Hash[*attr_names.zip(r).flatten]]
|
|
66
|
+
else
|
|
67
|
+
[]
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -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
|