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,63 @@
|
|
|
1
|
+
require 'geocoder/lookups/base'
|
|
2
|
+
require "geocoder/results/amap"
|
|
3
|
+
|
|
4
|
+
module Geocoder::Lookup
|
|
5
|
+
class Amap < Base
|
|
6
|
+
|
|
7
|
+
def name
|
|
8
|
+
"AMap"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def required_api_key_parts
|
|
12
|
+
["key"]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def supported_protocols
|
|
16
|
+
[:http]
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private # ---------------------------------------------------------------
|
|
20
|
+
|
|
21
|
+
def base_query_url(query)
|
|
22
|
+
path = query.reverse_geocode? ? 'regeo' : 'geo'
|
|
23
|
+
"http://restapi.amap.com/v3/geocode/#{path}?"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def results(query, reverse = false)
|
|
27
|
+
return [] unless doc = fetch_data(query)
|
|
28
|
+
case [doc['status'], doc['info']]
|
|
29
|
+
when ['1', 'OK']
|
|
30
|
+
return doc['regeocodes'] unless doc['regeocodes'].blank?
|
|
31
|
+
return [doc['regeocode']] unless doc['regeocode'].blank?
|
|
32
|
+
return doc['geocodes'] unless doc['geocodes'].blank?
|
|
33
|
+
when ['0', 'INVALID_USER_KEY']
|
|
34
|
+
raise_error(Geocoder::InvalidApiKey, "invalid api key") ||
|
|
35
|
+
Geocoder.log(:warn, "#{self.name} Geocoding API error: invalid api key.")
|
|
36
|
+
else
|
|
37
|
+
raise_error(Geocoder::Error, "server error.") ||
|
|
38
|
+
Geocoder.log(:warn, "#{self.name} Geocoding API error: server error - [#{doc['info']}]")
|
|
39
|
+
end
|
|
40
|
+
return []
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def query_url_params(query)
|
|
44
|
+
params = {
|
|
45
|
+
:key => configuration.api_key,
|
|
46
|
+
:output => "json"
|
|
47
|
+
}
|
|
48
|
+
if query.reverse_geocode?
|
|
49
|
+
params[:location] = revert_coordinates(query.text)
|
|
50
|
+
params[:extensions] = "all"
|
|
51
|
+
params[:coordsys] = "gps"
|
|
52
|
+
else
|
|
53
|
+
params[:address] = query.sanitized_text
|
|
54
|
+
end
|
|
55
|
+
params.merge(super)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def revert_coordinates(text)
|
|
59
|
+
[text[1],text[0]].join(",")
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require 'geocoder/lookups/base'
|
|
2
|
+
require 'geocoder/results/amazon_location_service'
|
|
3
|
+
|
|
4
|
+
module Geocoder::Lookup
|
|
5
|
+
class AmazonLocationService < Base
|
|
6
|
+
def results(query)
|
|
7
|
+
params = query.options.dup
|
|
8
|
+
|
|
9
|
+
# index_name is required
|
|
10
|
+
# Aws::ParamValidator raises ArgumentError on missing required keys
|
|
11
|
+
params.merge!(index_name: configuration[:index_name])
|
|
12
|
+
|
|
13
|
+
# Aws::ParamValidator raises ArgumentError on unexpected keys
|
|
14
|
+
params.delete(:lookup)
|
|
15
|
+
|
|
16
|
+
# Inherit language from configuration
|
|
17
|
+
params.merge!(language: configuration[:language])
|
|
18
|
+
|
|
19
|
+
resp = if query.reverse_geocode?
|
|
20
|
+
client.search_place_index_for_position(params.merge(position: query.coordinates.reverse))
|
|
21
|
+
else
|
|
22
|
+
client.search_place_index_for_text(params.merge(text: query.text))
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
resp.results
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def client
|
|
31
|
+
return @client if @client
|
|
32
|
+
require_sdk
|
|
33
|
+
keys = configuration.api_key
|
|
34
|
+
if keys
|
|
35
|
+
@client = Aws::LocationService::Client.new(**{
|
|
36
|
+
region: keys[:region],
|
|
37
|
+
access_key_id: keys[:access_key_id],
|
|
38
|
+
secret_access_key: keys[:secret_access_key]
|
|
39
|
+
}.compact)
|
|
40
|
+
else
|
|
41
|
+
@client = Aws::LocationService::Client.new
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def require_sdk
|
|
46
|
+
begin
|
|
47
|
+
require 'aws-sdk-locationservice'
|
|
48
|
+
rescue LoadError
|
|
49
|
+
raise_error(Geocoder::ConfigurationError) ||
|
|
50
|
+
Geocoder.log(
|
|
51
|
+
:error,
|
|
52
|
+
"Couldn't load the Amazon Location Service SDK. " +
|
|
53
|
+
"Install it with: gem install aws-sdk-locationservice -v '~> 1.4'"
|
|
54
|
+
)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
require 'geocoder/lookups/base'
|
|
2
|
+
require 'geocoder/results/azure'
|
|
3
|
+
|
|
4
|
+
module Geocoder::Lookup
|
|
5
|
+
class Azure < Base
|
|
6
|
+
def name
|
|
7
|
+
'Azure'
|
|
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
|
+
host = 'atlas.microsoft.com/search/address'
|
|
22
|
+
|
|
23
|
+
if query.reverse_geocode?
|
|
24
|
+
"#{protocol}://#{host}/reverse/json?"
|
|
25
|
+
else
|
|
26
|
+
"#{protocol}://#{host}/json?"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def query_url_params(query)
|
|
31
|
+
params = {
|
|
32
|
+
'api-version' => 1.0,
|
|
33
|
+
'language' => query.options[:language] || 'en',
|
|
34
|
+
'limit' => configuration[:limit] || 10,
|
|
35
|
+
'query' => query.sanitized_text,
|
|
36
|
+
'subscription-key' => configuration.api_key
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
params.merge(super)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def results(query)
|
|
43
|
+
return [] unless (doc = fetch_data(query))
|
|
44
|
+
|
|
45
|
+
return doc if doc['error']
|
|
46
|
+
|
|
47
|
+
if doc['results']&.any?
|
|
48
|
+
doc['results']
|
|
49
|
+
elsif doc['addresses']&.any?
|
|
50
|
+
doc['addresses']
|
|
51
|
+
else
|
|
52
|
+
[]
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
require 'geocoder/lookups/base'
|
|
2
|
+
require "geocoder/results/baidu"
|
|
3
|
+
|
|
4
|
+
module Geocoder::Lookup
|
|
5
|
+
class Baidu < Base
|
|
6
|
+
|
|
7
|
+
def name
|
|
8
|
+
"Baidu"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def required_api_key_parts
|
|
12
|
+
["key"]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# HTTP only
|
|
16
|
+
def supported_protocols
|
|
17
|
+
[:http]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private # ---------------------------------------------------------------
|
|
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
|
+
|
|
30
|
+
def results(query, reverse = false)
|
|
31
|
+
return [] unless doc = fetch_data(query)
|
|
32
|
+
case doc['status']
|
|
33
|
+
when 0
|
|
34
|
+
return [doc[content_key]] unless doc[content_key].blank?
|
|
35
|
+
when 1, 3, 4
|
|
36
|
+
raise_error(Geocoder::Error, "server error.") ||
|
|
37
|
+
Geocoder.log(:warn, "#{name} Geocoding API error: server error.")
|
|
38
|
+
when 2
|
|
39
|
+
raise_error(Geocoder::InvalidRequest, "invalid request.") ||
|
|
40
|
+
Geocoder.log(:warn, "#{name} Geocoding API error: invalid request.")
|
|
41
|
+
when 5
|
|
42
|
+
raise_error(Geocoder::InvalidApiKey, "invalid api key") ||
|
|
43
|
+
Geocoder.log(:warn, "#{name} Geocoding API error: invalid api key.")
|
|
44
|
+
when 101, 102, 200..299
|
|
45
|
+
raise_error(Geocoder::RequestDenied, "request denied") ||
|
|
46
|
+
Geocoder.log(:warn, "#{name} Geocoding API error: request denied.")
|
|
47
|
+
when 300..399
|
|
48
|
+
raise_error(Geocoder::OverQueryLimitError, "over query limit.") ||
|
|
49
|
+
Geocoder.log(:warn, "#{name} Geocoding API error: over query limit.")
|
|
50
|
+
end
|
|
51
|
+
return []
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def query_url_params(query)
|
|
55
|
+
{
|
|
56
|
+
(query.reverse_geocode? ? :location : :address) => query.sanitized_text,
|
|
57
|
+
:ak => configuration.api_key,
|
|
58
|
+
:output => "json"
|
|
59
|
+
}.merge(super)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'geocoder/lookups/baidu'
|
|
2
|
+
require 'geocoder/results/baidu_ip'
|
|
3
|
+
|
|
4
|
+
module Geocoder::Lookup
|
|
5
|
+
class BaiduIp < Baidu
|
|
6
|
+
|
|
7
|
+
def name
|
|
8
|
+
"Baidu IP"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
private # ---------------------------------------------------------------
|
|
12
|
+
|
|
13
|
+
def base_query_url(query)
|
|
14
|
+
"#{protocol}://api.map.baidu.com/location/ip?"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def content_key
|
|
18
|
+
'content'
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def query_url_params(query)
|
|
22
|
+
{
|
|
23
|
+
:ip => query.sanitized_text,
|
|
24
|
+
:ak => configuration.api_key,
|
|
25
|
+
:coor => "bd09ll"
|
|
26
|
+
}.merge(super)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'geocoder/lookups/base'
|
|
4
|
+
require 'geocoder/results/ban_data_gouv_fr'
|
|
5
|
+
|
|
6
|
+
module Geocoder::Lookup
|
|
7
|
+
class BanDataGouvFr < Base
|
|
8
|
+
|
|
9
|
+
def name
|
|
10
|
+
"Base Adresse Nationale Française"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def map_link_url(coordinates)
|
|
14
|
+
"https://www.openstreetmap.org/#map=19/#{coordinates.join('/')}"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private # ---------------------------------------------------------------
|
|
18
|
+
|
|
19
|
+
def base_query_url(query)
|
|
20
|
+
method = query.reverse_geocode? ? "reverse" : "search"
|
|
21
|
+
"#{protocol}://data.geopf.fr/geocodage/#{method}/?"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def any_result?(doc)
|
|
25
|
+
doc['features'] and doc['features'].any?
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def results(query)
|
|
29
|
+
if doc = fetch_data(query) and any_result?(doc)
|
|
30
|
+
[doc]
|
|
31
|
+
else
|
|
32
|
+
[]
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
#### PARAMS ####
|
|
37
|
+
|
|
38
|
+
def query_url_params(query)
|
|
39
|
+
query_ban_datagouv_fr_params(query).merge(super)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def query_ban_datagouv_fr_params(query)
|
|
43
|
+
query.reverse_geocode? ? reverse_geocode_ban_fr_params(query) : search_geocode_ban_fr_params(query)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
#### SEARCH GEOCODING PARAMS ####
|
|
47
|
+
#
|
|
48
|
+
# :q => required, full text search param)
|
|
49
|
+
|
|
50
|
+
# :limit => force limit number of results returned by raw API
|
|
51
|
+
# (default = 5) note : only first result is taken
|
|
52
|
+
# in account in geocoder
|
|
53
|
+
#
|
|
54
|
+
# :autocomplete => pass 0 to disable autocomplete treatment of :q
|
|
55
|
+
# (default = 1)
|
|
56
|
+
#
|
|
57
|
+
# :lat => force filter results around specific lat/lon
|
|
58
|
+
#
|
|
59
|
+
# :lon => force filter results around specific lat/lon
|
|
60
|
+
#
|
|
61
|
+
# :type => force filter the returned result type
|
|
62
|
+
# (check results for a list of accepted types)
|
|
63
|
+
#
|
|
64
|
+
# :postcode => force filter results on a specific city post code
|
|
65
|
+
#
|
|
66
|
+
# :citycode => force filter results on a specific city UUID INSEE code
|
|
67
|
+
#
|
|
68
|
+
# For up to date doc (in french only) : https://adresse.data.gouv.fr/api/
|
|
69
|
+
#
|
|
70
|
+
def search_geocode_ban_fr_params(query)
|
|
71
|
+
params = {
|
|
72
|
+
q: query.sanitized_text
|
|
73
|
+
}
|
|
74
|
+
unless (limit = query.options[:limit]).nil? || !limit_param_is_valid?(limit)
|
|
75
|
+
params[:limit] = limit.to_i
|
|
76
|
+
end
|
|
77
|
+
unless (autocomplete = query.options[:autocomplete]).nil? || !autocomplete_param_is_valid?(autocomplete)
|
|
78
|
+
params[:autocomplete] = autocomplete.to_s
|
|
79
|
+
end
|
|
80
|
+
unless (type = query.options[:type]).nil? || !type_param_is_valid?(type)
|
|
81
|
+
params[:type] = type.downcase
|
|
82
|
+
end
|
|
83
|
+
unless (postcode = query.options[:postcode]).nil? || !code_param_is_valid?(postcode)
|
|
84
|
+
params[:postcode] = postcode.to_s
|
|
85
|
+
end
|
|
86
|
+
unless (citycode = query.options[:citycode]).nil? || !code_param_is_valid?(citycode)
|
|
87
|
+
params[:citycode] = citycode.to_s
|
|
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
|
|
95
|
+
params
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
#### REVERSE GEOCODING PARAMS ####
|
|
99
|
+
#
|
|
100
|
+
# :lat => required
|
|
101
|
+
#
|
|
102
|
+
# :lon => required
|
|
103
|
+
#
|
|
104
|
+
# :type => force returned results type
|
|
105
|
+
# (check results for a list of accepted types)
|
|
106
|
+
#
|
|
107
|
+
def reverse_geocode_ban_fr_params(query)
|
|
108
|
+
lat_lon = query.coordinates
|
|
109
|
+
params = {
|
|
110
|
+
lat: lat_lon.first,
|
|
111
|
+
lon: lat_lon.last
|
|
112
|
+
}
|
|
113
|
+
unless (type = query.options[:type]).nil? || !type_param_is_valid?(type)
|
|
114
|
+
params[:type] = type.downcase
|
|
115
|
+
end
|
|
116
|
+
params
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def limit_param_is_valid?(param)
|
|
120
|
+
param.to_i.positive?
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def autocomplete_param_is_valid?(param)
|
|
124
|
+
[0,1].include?(param.to_i)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def type_param_is_valid?(param)
|
|
128
|
+
%w(housenumber street locality municipality).include?(param.downcase)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def code_param_is_valid?(param)
|
|
132
|
+
(1..99999).include?(param.to_i)
|
|
133
|
+
end
|
|
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
|
|
142
|
+
end
|
|
143
|
+
end
|