mini-safe-gem 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 +319 -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/mini-safe-gem.gemspec +12 -0
- metadata +214 -0
|
@@ -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
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
require 'geocoder/lookups/base'
|
|
2
|
+
require "geocoder/results/pc_miler"
|
|
3
|
+
require 'cgi' unless defined?(CGI) && defined?(CGI.escape)
|
|
4
|
+
|
|
5
|
+
module Geocoder::Lookup
|
|
6
|
+
class PcMiler < Base
|
|
7
|
+
|
|
8
|
+
# https://developer.trimblemaps.com/restful-apis/location/single-search/single-search-api/#test-the-api-now
|
|
9
|
+
def valid_region_codes
|
|
10
|
+
# AF: Africa
|
|
11
|
+
# AS: Asia
|
|
12
|
+
# EU: Europe
|
|
13
|
+
# ME: Middle East
|
|
14
|
+
# MX: Mexico
|
|
15
|
+
# NA: North America
|
|
16
|
+
# OC: Oceania
|
|
17
|
+
# SA: South America
|
|
18
|
+
%w[AF AS EU ME MX NA OC SA]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def name
|
|
22
|
+
"PCMiler"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private # ---------------------------------------------------------------
|
|
26
|
+
|
|
27
|
+
def base_query_url(query)
|
|
28
|
+
region_code = region(query)
|
|
29
|
+
if !valid_region_codes.include?(region_code)
|
|
30
|
+
raise "region_code '#{region_code}' is invalid. use one of #{valid_region_codes}." \
|
|
31
|
+
"https://developer.trimblemaps.com/restful-apis/location/single-search/single-search-api/#test-the-api-now"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
"#{protocol}://singlesearch.alk.com/#{region_code}/api/search?"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def results(query)
|
|
38
|
+
return [] unless data = fetch_data(query)
|
|
39
|
+
if data['Locations']
|
|
40
|
+
add_metadata_to_locations!(data)
|
|
41
|
+
data['Locations']
|
|
42
|
+
else
|
|
43
|
+
[]
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def add_metadata_to_locations!(data)
|
|
48
|
+
confidence = data['QueryConfidence']
|
|
49
|
+
data['Locations'].each do |location|
|
|
50
|
+
location['QueryConfidence'] = confidence
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def query_url_params(query)
|
|
55
|
+
if query.reverse_geocode?
|
|
56
|
+
lat,lon = query.coordinates
|
|
57
|
+
formatted_query = "#{CGI.escape(lat)},#{CGI.escape(lon)}"
|
|
58
|
+
else
|
|
59
|
+
formatted_query = query.text.to_s
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
{
|
|
63
|
+
authToken: configuration.api_key,
|
|
64
|
+
query: formatted_query,
|
|
65
|
+
# to add additional metadata to response such as QueryConfidence
|
|
66
|
+
include: 'Meta'
|
|
67
|
+
}.merge(super(query))
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def region(query)
|
|
71
|
+
query.options[:region] || query.options['region'] || configuration[:region] || "NA"
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def check_response_for_errors!(response)
|
|
75
|
+
if response.code.to_i == 403
|
|
76
|
+
raise_error(Geocoder::RequestDenied) ||
|
|
77
|
+
Geocoder.log(:warn, "Geocoding API error: 403 API key does not exist")
|
|
78
|
+
else
|
|
79
|
+
super(response)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def supported_protocols
|
|
84
|
+
[:https]
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require 'geocoder/lookups/base'
|
|
2
|
+
require "geocoder/results/pdok_nl"
|
|
3
|
+
|
|
4
|
+
module Geocoder::Lookup
|
|
5
|
+
class PdokNl < Base
|
|
6
|
+
|
|
7
|
+
def name
|
|
8
|
+
'pdok NL'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def supported_protocols
|
|
12
|
+
[:https]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private # ---------------------------------------------------------------
|
|
16
|
+
|
|
17
|
+
def cache_key(query)
|
|
18
|
+
base_query_url(query) + hash_to_query(query_url_params(query))
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def base_query_url(query)
|
|
22
|
+
"#{protocol}://api.pdok.nl/bzk/locatieserver/search/v3_1/free?"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def valid_response?(response)
|
|
26
|
+
json = parse_json(response.body)
|
|
27
|
+
super(response) if json
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def results(query)
|
|
31
|
+
return [] unless doc = fetch_data(query)
|
|
32
|
+
return doc['response']['docs']
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def query_url_params(query)
|
|
36
|
+
{
|
|
37
|
+
fl: '*',
|
|
38
|
+
q: query.text,
|
|
39
|
+
wt: 'json'
|
|
40
|
+
}.merge(super)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
require 'geocoder/lookups/base'
|
|
2
|
+
require 'geocoder/results/pelias'
|
|
3
|
+
|
|
4
|
+
module Geocoder::Lookup
|
|
5
|
+
class Pelias < Base
|
|
6
|
+
def name
|
|
7
|
+
'Pelias'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def endpoint
|
|
11
|
+
configuration[:endpoint] || 'localhost'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def required_api_key_parts
|
|
15
|
+
['search-XXXX']
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private # ----------------------------------------------------------------
|
|
19
|
+
|
|
20
|
+
def base_query_url(query)
|
|
21
|
+
query_type = query.reverse_geocode? ? 'reverse' : 'search'
|
|
22
|
+
"#{protocol}://#{endpoint}/v1/#{query_type}?"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def query_url_params(query)
|
|
26
|
+
params = {
|
|
27
|
+
api_key: configuration.api_key
|
|
28
|
+
}.merge(super)
|
|
29
|
+
|
|
30
|
+
if query.reverse_geocode?
|
|
31
|
+
lat, lon = query.coordinates
|
|
32
|
+
params[:'point.lat'] = lat
|
|
33
|
+
params[:'point.lon'] = lon
|
|
34
|
+
else
|
|
35
|
+
params[:text] = query.text
|
|
36
|
+
end
|
|
37
|
+
params
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def results(query)
|
|
41
|
+
return [] unless doc = fetch_data(query)
|
|
42
|
+
|
|
43
|
+
# not all responses include a meta
|
|
44
|
+
if doc['meta']
|
|
45
|
+
error = doc.fetch('results', {}).fetch('error', {})
|
|
46
|
+
message = error.fetch('type', 'Unknown Error') + ': ' + error.fetch('message', 'No message')
|
|
47
|
+
log_message = 'Pelias Geocoding API error - ' + message
|
|
48
|
+
case doc['meta']['status_code']
|
|
49
|
+
when '200'
|
|
50
|
+
# nothing to see here
|
|
51
|
+
when '403'
|
|
52
|
+
raise_error(Geocoder::RequestDenied, message) || Geocoder.log(:warn, log_message)
|
|
53
|
+
when '429'
|
|
54
|
+
raise_error(Geocoder::OverQueryLimitError, message) || Geocoder.log(:warn, log_message)
|
|
55
|
+
else
|
|
56
|
+
raise_error(Geocoder::Error, message) || Geocoder.log(:warn, log_message)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
doc['features'] || []
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
require 'geocoder/lookups/base'
|
|
2
|
+
require 'geocoder/results/photon'
|
|
3
|
+
|
|
4
|
+
module Geocoder::Lookup
|
|
5
|
+
class Photon < Base
|
|
6
|
+
def name
|
|
7
|
+
'Photon'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
private # ---------------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
def supported_protocols
|
|
13
|
+
[:http, :https]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def base_query_url(query)
|
|
17
|
+
host = configuration[:host] || 'photon.komoot.io'
|
|
18
|
+
method = query.reverse_geocode? ? 'reverse' : 'api'
|
|
19
|
+
"#{protocol}://#{host}/#{method}?"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def results(query)
|
|
23
|
+
return [] unless (doc = fetch_data(query))
|
|
24
|
+
return [] unless doc['type'] == 'FeatureCollection'
|
|
25
|
+
return [] unless doc['features'] || doc['features'].present?
|
|
26
|
+
|
|
27
|
+
doc['features']
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def query_url_params(query)
|
|
31
|
+
lang = query.language || configuration.language
|
|
32
|
+
params = { lang: lang, limit: query.options[:limit] }
|
|
33
|
+
|
|
34
|
+
if query.reverse_geocode?
|
|
35
|
+
params.merge!(query_url_params_reverse(query))
|
|
36
|
+
else
|
|
37
|
+
params.merge!(query_url_params_coordinates(query))
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
params.merge!(super)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def query_url_params_coordinates(query)
|
|
44
|
+
params = { q: query.sanitized_text }
|
|
45
|
+
|
|
46
|
+
if (bias = query.options[:bias])
|
|
47
|
+
params.merge!(lat: bias[:latitude], lon: bias[:longitude], location_bias_scale: bias[:scale])
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
if (filter = query_url_params_coordinates_filter(query))
|
|
51
|
+
params.merge!(filter)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
params
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def query_url_params_coordinates_filter(query)
|
|
58
|
+
filter = query.options[:filter]
|
|
59
|
+
return unless filter
|
|
60
|
+
|
|
61
|
+
bbox = filter[:bbox]
|
|
62
|
+
{
|
|
63
|
+
bbox: bbox.is_a?(Array) ? bbox.join(',') : bbox,
|
|
64
|
+
osm_tag: filter[:osm_tag]
|
|
65
|
+
}
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def query_url_params_reverse(query)
|
|
69
|
+
params = { lat: query.coordinates[0], lon: query.coordinates[1], radius: query.options[:radius] }
|
|
70
|
+
|
|
71
|
+
if (dsort = query.options[:distance_sort])
|
|
72
|
+
params[:distance_sort] = dsort ? 'true' : 'false'
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
if (filter = query_url_params_reverse_filter(query))
|
|
76
|
+
params.merge!(filter)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
params
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def query_url_params_reverse_filter(query)
|
|
83
|
+
filter = query.options[:filter]
|
|
84
|
+
return unless filter
|
|
85
|
+
|
|
86
|
+
{ query_string_filter: filter[:string] }
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require "geocoder/lookups/nominatim"
|
|
2
|
+
require "geocoder/results/pickpoint"
|
|
3
|
+
|
|
4
|
+
module Geocoder::Lookup
|
|
5
|
+
class Pickpoint < Nominatim
|
|
6
|
+
def name
|
|
7
|
+
"Pickpoint"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def supported_protocols
|
|
11
|
+
[:https]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def required_api_key_parts
|
|
15
|
+
["api_key"]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private # ----------------------------------------------------------------
|
|
19
|
+
|
|
20
|
+
def base_query_url(query)
|
|
21
|
+
method = query.reverse_geocode? ? "reverse" : "forward"
|
|
22
|
+
"#{protocol}://api.pickpoint.io/v1/#{method}?"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def query_url_params(query)
|
|
26
|
+
{
|
|
27
|
+
key: configuration.api_key
|
|
28
|
+
}.merge(super)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def results(query)
|
|
32
|
+
return [] unless doc = fetch_data(query)
|
|
33
|
+
|
|
34
|
+
if !doc.is_a?(Array) && doc['message'] == 'Unauthorized'
|
|
35
|
+
raise_error(Geocoder::InvalidApiKey, 'Unauthorized')
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
doc.is_a?(Array) ? doc : [doc]
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
require 'geocoder/lookups/base'
|
|
2
|
+
require 'geocoder/results/pointpin'
|
|
3
|
+
|
|
4
|
+
module Geocoder::Lookup
|
|
5
|
+
class Pointpin < Base
|
|
6
|
+
|
|
7
|
+
def name
|
|
8
|
+
"Pointpin"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def required_api_key_parts
|
|
12
|
+
["key"]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def query_url(query)
|
|
16
|
+
"#{protocol}://geo.pointp.in/#{configuration.api_key}/json/#{query.sanitized_text}"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private # ----------------------------------------------------------------
|
|
20
|
+
|
|
21
|
+
def cache_key(query)
|
|
22
|
+
"#{protocol}://geo.pointp.in/json/#{query.sanitized_text}"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def results(query)
|
|
26
|
+
# don't look up a loopback or private address, just return the stored result
|
|
27
|
+
return [] if query.internal_ip_address?
|
|
28
|
+
doc = fetch_data(query)
|
|
29
|
+
if doc and doc.is_a?(Hash)
|
|
30
|
+
if !data_contains_error?(doc)
|
|
31
|
+
return [doc]
|
|
32
|
+
elsif doc['error']
|
|
33
|
+
case doc['error']
|
|
34
|
+
when "Invalid IP address"
|
|
35
|
+
raise_error(Geocoder::InvalidRequest) || Geocoder.log(:warn, "Invalid Pointpin request.")
|
|
36
|
+
when "Invalid API key"
|
|
37
|
+
raise_error(Geocoder::InvalidApiKey) || Geocoder.log(:warn, "Invalid Pointpin API key.")
|
|
38
|
+
when "Address not found"
|
|
39
|
+
Geocoder.log(:warn, "Address not found.")
|
|
40
|
+
end
|
|
41
|
+
else
|
|
42
|
+
raise_error(Geocoder::Error) || Geocoder.log(:warn, "Pointpin server error")
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
return []
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def data_contains_error?(parsed_data)
|
|
50
|
+
parsed_data.keys.include?('error')
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# TODO: replace this hash with what's actually returned by Pointpin
|
|
54
|
+
def reserved_result(ip)
|
|
55
|
+
{
|
|
56
|
+
"ip" => ip,
|
|
57
|
+
"city" => "",
|
|
58
|
+
"region_code" => "",
|
|
59
|
+
"region_name" => "",
|
|
60
|
+
"metrocode" => "",
|
|
61
|
+
"zipcode" => "",
|
|
62
|
+
"latitude" => "0",
|
|
63
|
+
"longitude" => "0",
|
|
64
|
+
"country_name" => "Reserved",
|
|
65
|
+
"country_code" => "RD"
|
|
66
|
+
}
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
require 'geocoder/lookups/base'
|
|
2
|
+
require 'geocoder/results/postcode_anywhere_uk'
|
|
3
|
+
|
|
4
|
+
module Geocoder::Lookup
|
|
5
|
+
class PostcodeAnywhereUk < Base
|
|
6
|
+
# API documentation: http://www.postcodeanywhere.co.uk/Support/WebService/Geocoding/UK/Geocode/2/
|
|
7
|
+
DAILY_LIMIT_EXEEDED_ERROR_CODES = ['8', '17'] # api docs say these two codes are the same error
|
|
8
|
+
INVALID_API_KEY_ERROR_CODE = '2'
|
|
9
|
+
|
|
10
|
+
def name
|
|
11
|
+
'PostcodeAnywhereUk'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def required_api_key_parts
|
|
15
|
+
%w(key)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private # ----------------------------------------------------------------
|
|
19
|
+
|
|
20
|
+
def base_query_url(query)
|
|
21
|
+
"#{protocol}://services.postcodeanywhere.co.uk/Geocoding/UK/Geocode/v2.00/json.ws?"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def results(query)
|
|
25
|
+
response = fetch_data(query)
|
|
26
|
+
return [] if response.nil? || !response.is_a?(Array) || response.empty?
|
|
27
|
+
|
|
28
|
+
raise_exception_for_response(response[0]) if response[0]['Error']
|
|
29
|
+
response
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def raise_exception_for_response(response)
|
|
33
|
+
case response['Error']
|
|
34
|
+
when *DAILY_LIMIT_EXEEDED_ERROR_CODES
|
|
35
|
+
raise_error(Geocoder::OverQueryLimitError, response['Cause']) || Geocoder.log(:warn, response['Cause'])
|
|
36
|
+
when INVALID_API_KEY_ERROR_CODE
|
|
37
|
+
raise_error(Geocoder::InvalidApiKey, response['Cause']) || Geocoder.log(:warn, response['Cause'])
|
|
38
|
+
else # anything else just raise general error with the api cause
|
|
39
|
+
raise_error(Geocoder::Error, response['Cause']) || Geocoder.log(:warn, response['Cause'])
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def query_url_params(query)
|
|
44
|
+
{
|
|
45
|
+
:location => query.sanitized_text,
|
|
46
|
+
:key => configuration.api_key
|
|
47
|
+
}.merge(super)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require 'geocoder/lookups/base'
|
|
2
|
+
require 'geocoder/results/postcodes_io'
|
|
3
|
+
|
|
4
|
+
module Geocoder::Lookup
|
|
5
|
+
class PostcodesIo < Base
|
|
6
|
+
def name
|
|
7
|
+
'Postcodes.io'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def query_url(query)
|
|
11
|
+
"#{protocol}://api.postcodes.io/postcodes/#{query.sanitized_text.gsub(/\s/, '')}"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def supported_protocols
|
|
15
|
+
[:https]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private # ----------------------------------------------------------------
|
|
19
|
+
|
|
20
|
+
def cache_key(query)
|
|
21
|
+
query_url(query)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def results(query)
|
|
25
|
+
response = fetch_data(query)
|
|
26
|
+
return [] if response.nil? || response['status'] != 200 || response.empty?
|
|
27
|
+
|
|
28
|
+
[response['result']]
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
require 'geocoder/lookups/base'
|
|
2
|
+
require 'geocoder/results/smarty_streets'
|
|
3
|
+
|
|
4
|
+
module Geocoder::Lookup
|
|
5
|
+
class SmartyStreets < Base
|
|
6
|
+
def name
|
|
7
|
+
"SmartyStreets"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def required_api_key_parts
|
|
11
|
+
%w(auth-id auth-token)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# required by API as of 26 March 2015
|
|
15
|
+
def supported_protocols
|
|
16
|
+
[:https]
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private # ---------------------------------------------------------------
|
|
20
|
+
|
|
21
|
+
def base_query_url(query)
|
|
22
|
+
if international?(query)
|
|
23
|
+
"#{protocol}://international-street.api.smartystreets.com/verify?"
|
|
24
|
+
elsif zipcode_only?(query)
|
|
25
|
+
"#{protocol}://us-zipcode.api.smartystreets.com/lookup?"
|
|
26
|
+
else
|
|
27
|
+
"#{protocol}://us-street.api.smartystreets.com/street-address?"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def zipcode_only?(query)
|
|
32
|
+
!query.text.is_a?(Array) and query.to_s.strip =~ /\A\d{5}(-\d{4})?\Z/
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def international?(query)
|
|
36
|
+
!query.options[:country].nil?
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def query_url_params(query)
|
|
40
|
+
params = {}
|
|
41
|
+
if international?(query)
|
|
42
|
+
params[:freeform] = query.sanitized_text
|
|
43
|
+
params[:country] = query.options[:country]
|
|
44
|
+
params[:geocode] = true
|
|
45
|
+
elsif zipcode_only?(query)
|
|
46
|
+
params[:zipcode] = query.sanitized_text
|
|
47
|
+
else
|
|
48
|
+
params[:street] = query.sanitized_text
|
|
49
|
+
end
|
|
50
|
+
if configuration.api_key.is_a?(Array)
|
|
51
|
+
params[:"auth-id"] = configuration.api_key[0]
|
|
52
|
+
params[:"auth-token"] = configuration.api_key[1]
|
|
53
|
+
else
|
|
54
|
+
params[:"auth-token"] = configuration.api_key
|
|
55
|
+
end
|
|
56
|
+
params.merge(super)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def results(query)
|
|
60
|
+
doc = fetch_data(query) || []
|
|
61
|
+
if doc.is_a?(Hash) and doc.key?('status') # implies there's an error
|
|
62
|
+
return []
|
|
63
|
+
else
|
|
64
|
+
return doc
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
require 'geocoder/lookups/base'
|
|
2
|
+
require 'geocoder/results/telize'
|
|
3
|
+
|
|
4
|
+
module Geocoder::Lookup
|
|
5
|
+
class Telize < Base
|
|
6
|
+
|
|
7
|
+
def name
|
|
8
|
+
"Telize"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def required_api_key_parts
|
|
12
|
+
configuration[:host] ? [] : ["key"]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def query_url(query)
|
|
16
|
+
if configuration[:host]
|
|
17
|
+
"#{protocol}://#{configuration[:host]}/location/#{query.sanitized_text}"
|
|
18
|
+
else
|
|
19
|
+
"#{protocol}://telize-v1.p.rapidapi.com/location/#{query.sanitized_text}?rapidapi-key=#{api_key}"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def supported_protocols
|
|
24
|
+
[].tap do |array|
|
|
25
|
+
array << :https
|
|
26
|
+
array << :http if configuration[:host]
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private # ---------------------------------------------------------------
|
|
31
|
+
|
|
32
|
+
def cache_key(query)
|
|
33
|
+
query_url(query)[/(.*)\?.*/, 1]
|
|
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
|
+
if (doc = fetch_data(query)).nil? or doc['code'] == 401 or empty_result?(doc)
|
|
40
|
+
[]
|
|
41
|
+
else
|
|
42
|
+
[doc]
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def empty_result?(doc)
|
|
47
|
+
!doc.is_a?(Hash) or doc.keys == ["ip"]
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def reserved_result(ip)
|
|
51
|
+
{
|
|
52
|
+
"ip" => ip,
|
|
53
|
+
"latitude" => 0,
|
|
54
|
+
"longitude" => 0,
|
|
55
|
+
"city" => "",
|
|
56
|
+
"timezone" => "",
|
|
57
|
+
"asn" => 0,
|
|
58
|
+
"region" => "",
|
|
59
|
+
"offset" => 0,
|
|
60
|
+
"organization" => "",
|
|
61
|
+
"country_code" => "",
|
|
62
|
+
"country_code3" => "",
|
|
63
|
+
"postal_code" => "",
|
|
64
|
+
"continent_code" => "",
|
|
65
|
+
"country" => "",
|
|
66
|
+
"region_code" => ""
|
|
67
|
+
}
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def api_key
|
|
71
|
+
configuration.api_key
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
end
|
|
75
|
+
end
|