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,71 @@
|
|
|
1
|
+
require 'geocoder/lookups/base'
|
|
2
|
+
require 'geocoder/results/ip2location'
|
|
3
|
+
|
|
4
|
+
module Geocoder::Lookup
|
|
5
|
+
class Ip2location < Base
|
|
6
|
+
|
|
7
|
+
def name
|
|
8
|
+
"IP2LocationApi"
|
|
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.com/v2/?"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def query_url_params(query)
|
|
26
|
+
super.merge(
|
|
27
|
+
key: configuration.api_key,
|
|
28
|
+
ip: query.sanitized_text,
|
|
29
|
+
package: configuration[:package],
|
|
30
|
+
)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def results(query)
|
|
34
|
+
# don't look up a loopback or private address, just return the stored result
|
|
35
|
+
return [reserved_result(query.text)] if query.internal_ip_address?
|
|
36
|
+
return [] unless doc = fetch_data(query)
|
|
37
|
+
if doc["response"] == "INVALID ACCOUNT"
|
|
38
|
+
raise_error(Geocoder::InvalidApiKey) || Geocoder.log(:warn, "INVALID ACCOUNT")
|
|
39
|
+
return []
|
|
40
|
+
else
|
|
41
|
+
return [doc]
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def reserved_result(query)
|
|
46
|
+
{
|
|
47
|
+
"country_code" => "INVALID IP ADDRESS",
|
|
48
|
+
"country_name" => "INVALID IP ADDRESS",
|
|
49
|
+
"region_name" => "INVALID IP ADDRESS",
|
|
50
|
+
"city_name" => "INVALID IP ADDRESS",
|
|
51
|
+
"latitude" => "INVALID IP ADDRESS",
|
|
52
|
+
"longitude" => "INVALID IP ADDRESS",
|
|
53
|
+
"zip_code" => "INVALID IP ADDRESS",
|
|
54
|
+
"time_zone" => "INVALID IP ADDRESS",
|
|
55
|
+
"isp" => "INVALID IP ADDRESS",
|
|
56
|
+
"domain" => "INVALID IP ADDRESS",
|
|
57
|
+
"net_speed" => "INVALID IP ADDRESS",
|
|
58
|
+
"idd_code" => "INVALID IP ADDRESS",
|
|
59
|
+
"area_code" => "INVALID IP ADDRESS",
|
|
60
|
+
"weather_station_code" => "INVALID IP ADDRESS",
|
|
61
|
+
"weather_station_name" => "INVALID IP ADDRESS",
|
|
62
|
+
"mcc" => "INVALID IP ADDRESS",
|
|
63
|
+
"mnc" => "INVALID IP ADDRESS",
|
|
64
|
+
"mobile_brand" => "INVALID IP ADDRESS",
|
|
65
|
+
"elevation" => "INVALID IP ADDRESS",
|
|
66
|
+
"usage_type" => "INVALID IP ADDRESS"
|
|
67
|
+
}
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
end
|
|
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" => nil,
|
|
52
|
+
"longitude" => nil,
|
|
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,82 @@
|
|
|
1
|
+
require 'geocoder/lookups/base'
|
|
2
|
+
require 'geocoder/results/ipapi_com'
|
|
3
|
+
|
|
4
|
+
module Geocoder::Lookup
|
|
5
|
+
class IpapiCom < Base
|
|
6
|
+
|
|
7
|
+
def name
|
|
8
|
+
"ip-api.com"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def supported_protocols
|
|
12
|
+
if configuration.api_key
|
|
13
|
+
[:http, :https]
|
|
14
|
+
else
|
|
15
|
+
[:http]
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private # ----------------------------------------------------------------
|
|
20
|
+
|
|
21
|
+
def base_query_url(query)
|
|
22
|
+
domain = configuration.api_key ? "pro.ip-api.com" : "ip-api.com"
|
|
23
|
+
url = "#{protocol}://#{domain}/json/#{query.sanitized_text}"
|
|
24
|
+
url << "?" if not url_query_string(query).empty?
|
|
25
|
+
url
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def parse_raw_data(raw_data)
|
|
29
|
+
if raw_data.chomp == "invalid key"
|
|
30
|
+
invalid_key_result
|
|
31
|
+
else
|
|
32
|
+
super(raw_data)
|
|
33
|
+
end
|
|
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 doc["message"] == "invalid key"
|
|
43
|
+
raise_error(Geocoder::InvalidApiKey) || Geocoder.log(:warn, "Invalid API key.")
|
|
44
|
+
return []
|
|
45
|
+
else
|
|
46
|
+
return [doc]
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def reserved_result(query)
|
|
51
|
+
{
|
|
52
|
+
"message" => "reserved range",
|
|
53
|
+
"query" => query,
|
|
54
|
+
"status" => "fail",
|
|
55
|
+
"ip" => query,
|
|
56
|
+
"city" => "",
|
|
57
|
+
"region_code" => "",
|
|
58
|
+
"region_name" => "",
|
|
59
|
+
"metrocode" => "",
|
|
60
|
+
"zipcode" => "",
|
|
61
|
+
"latitude" => "0",
|
|
62
|
+
"longitude" => "0",
|
|
63
|
+
"country_name" => "Reserved",
|
|
64
|
+
"country_code" => "RD"
|
|
65
|
+
}
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def invalid_key_result
|
|
69
|
+
{
|
|
70
|
+
"message" => "invalid key"
|
|
71
|
+
}
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def query_url_params(query)
|
|
75
|
+
params = {}
|
|
76
|
+
params.merge!(fields: configuration[:fields]) if configuration.has_key?(:fields)
|
|
77
|
+
params.merge!(key: configuration.api_key) if configuration.api_key
|
|
78
|
+
params.merge(super)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
end
|
|
82
|
+
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,62 @@
|
|
|
1
|
+
require 'geocoder/lookups/base'
|
|
2
|
+
require 'geocoder/results/ipdata_co'
|
|
3
|
+
|
|
4
|
+
module Geocoder::Lookup
|
|
5
|
+
class IpdataCo < Base
|
|
6
|
+
|
|
7
|
+
def name
|
|
8
|
+
"ipdata.co"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def supported_protocols
|
|
12
|
+
[:https]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def query_url(query)
|
|
16
|
+
# Ipdata.co requires that the API key be sent as a query parameter.
|
|
17
|
+
# It no longer supports API keys sent as headers.
|
|
18
|
+
"#{protocol}://#{host}/#{query.sanitized_text}?api-key=#{configuration.api_key}"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private # ---------------------------------------------------------------
|
|
22
|
+
|
|
23
|
+
def cache_key(query)
|
|
24
|
+
query_url(query)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def results(query)
|
|
28
|
+
# don't look up a loopback or private address, just return the stored result
|
|
29
|
+
return [reserved_result(query.text)] if query.internal_ip_address?
|
|
30
|
+
# note: Ipdata.co returns plain text on bad request
|
|
31
|
+
(doc = fetch_data(query)) ? [doc] : []
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def reserved_result(ip)
|
|
35
|
+
{
|
|
36
|
+
"ip" => ip,
|
|
37
|
+
"city" => "",
|
|
38
|
+
"region_code" => "",
|
|
39
|
+
"region_name" => "",
|
|
40
|
+
"metrocode" => "",
|
|
41
|
+
"zipcode" => "",
|
|
42
|
+
"latitude" => "0",
|
|
43
|
+
"longitude" => "0",
|
|
44
|
+
"country_name" => "Reserved",
|
|
45
|
+
"country_code" => "RD"
|
|
46
|
+
}
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def host
|
|
50
|
+
configuration[:host] || "api.ipdata.co"
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def check_response_for_errors!(response)
|
|
54
|
+
if response.code.to_i == 403
|
|
55
|
+
raise_error(Geocoder::RequestDenied) ||
|
|
56
|
+
Geocoder.log(:warn, "Geocoding API error: 403 API key does not exist")
|
|
57
|
+
else
|
|
58
|
+
super(response)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
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,44 @@
|
|
|
1
|
+
require 'geocoder/lookups/base'
|
|
2
|
+
require 'geocoder/results/ipinfo_io'
|
|
3
|
+
|
|
4
|
+
module Geocoder::Lookup
|
|
5
|
+
class IpinfoIo < Base
|
|
6
|
+
|
|
7
|
+
def name
|
|
8
|
+
"Ipinfo.io"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
private # ---------------------------------------------------------------
|
|
12
|
+
|
|
13
|
+
def base_query_url(query)
|
|
14
|
+
url = "#{protocol}://ipinfo.io/#{query.sanitized_text}/geo"
|
|
15
|
+
url << "?" if configuration.api_key
|
|
16
|
+
url
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def results(query)
|
|
20
|
+
# don't look up a loopback or private address, just return the stored result
|
|
21
|
+
return [reserved_result(query.text)] if query.internal_ip_address?
|
|
22
|
+
|
|
23
|
+
if !(doc = fetch_data(query)).is_a?(Hash) or doc['error']
|
|
24
|
+
[]
|
|
25
|
+
else
|
|
26
|
+
[doc]
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def reserved_result(ip)
|
|
31
|
+
{
|
|
32
|
+
"ip" => ip,
|
|
33
|
+
"bogon" => true
|
|
34
|
+
}
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def query_url_params(query)
|
|
38
|
+
{
|
|
39
|
+
token: configuration.api_key
|
|
40
|
+
}.merge(super)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require 'geocoder/lookups/base'
|
|
2
|
+
require 'geocoder/results/ipinfo_io_lite'
|
|
3
|
+
|
|
4
|
+
module Geocoder::Lookup
|
|
5
|
+
class IpinfoIoLite < Base
|
|
6
|
+
def name
|
|
7
|
+
'Ipinfo.io Lite'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
private # ---------------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
def base_query_url(query)
|
|
13
|
+
url = "#{protocol}://api.ipinfo.io/lite/#{query.sanitized_text}"
|
|
14
|
+
url << '?' if configuration.api_key
|
|
15
|
+
url
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def results(query)
|
|
19
|
+
# don't look up a loopback or private address, just return the stored result
|
|
20
|
+
return [reserved_result(query.text)] if query.internal_ip_address?
|
|
21
|
+
|
|
22
|
+
if !(doc = fetch_data(query)).is_a?(Hash) or doc['error']
|
|
23
|
+
[]
|
|
24
|
+
else
|
|
25
|
+
[doc]
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def reserved_result(ip)
|
|
30
|
+
{
|
|
31
|
+
'ip' => ip,
|
|
32
|
+
'bogon' => true
|
|
33
|
+
}
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def query_url_params(query)
|
|
37
|
+
{
|
|
38
|
+
token: configuration.api_key
|
|
39
|
+
}.merge(super)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
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
|
|
@@ -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
|