locality 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/locality/configuration.rb +1 -1
- data/lib/locality/ip.rb +29 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 251fe2d5eeff7fd2bec5c9645a1c29158aa06475
|
4
|
+
data.tar.gz: 4546e8b4eb59c63d5988b8be4666515c31b482d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fef7271ed467a49d229b06ca462ce365dc781a92bfa10507da721d54193083a8c0440dc0e4c70bf66d547f185f37b15191fac7594e8f3a7c76c6f906ea958e95
|
7
|
+
data.tar.gz: 6d1d3e869708adf6a6221f7fe535a7ca4478bafb49b54c0c8a88ff8139e3147b7b305a878e69c1247769f55618cb840e68ce9a52ad55b2761cbaed6e3b978547
|
data/README.md
CHANGED
data/lib/locality/ip.rb
CHANGED
@@ -13,6 +13,15 @@ module Locality
|
|
13
13
|
@raw_ip = raw_ip
|
14
14
|
end
|
15
15
|
|
16
|
+
def self.check!
|
17
|
+
if Locality.config.maxmind_geoip2_path.blank?
|
18
|
+
fail download_message
|
19
|
+
end
|
20
|
+
|
21
|
+
# Just checking to see if it causes any trouble notiications, but not depending on it
|
22
|
+
new('8.8.8.8').country_name
|
23
|
+
end
|
24
|
+
|
16
25
|
def to_hash
|
17
26
|
{
|
18
27
|
ip: ip.to_s,
|
@@ -25,7 +34,7 @@ module Locality
|
|
25
34
|
end
|
26
35
|
|
27
36
|
def ip
|
28
|
-
@ip ||= ::IPAddr.new
|
37
|
+
@ip ||= ::IPAddr.new(raw_ip)
|
29
38
|
rescue => exception
|
30
39
|
nil
|
31
40
|
end
|
@@ -92,5 +101,24 @@ module Locality
|
|
92
101
|
Geocoder.configure ip_lookup: :geoip2, units: :km, geoip2: { cache: Hash.new, lib: 'hive_geoip2', file: ::Locality.config.maxmind_geoip2_path }
|
93
102
|
end
|
94
103
|
|
104
|
+
def self.download_message
|
105
|
+
<<END
|
106
|
+
|
107
|
+
|
108
|
+
Please download this file:
|
109
|
+
|
110
|
+
http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz
|
111
|
+
|
112
|
+
And put it into one of the following locations
|
113
|
+
|
114
|
+
#{Locality.config.maxmind_geoip2_paths.join("\n ")}
|
115
|
+
|
116
|
+
You can use the following command to do so:
|
117
|
+
|
118
|
+
curl http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz -o #{Locality.config.maxmind_geoip2_paths.first} && gunzip #{Locality.config.maxmind_geoip2_paths.first}
|
119
|
+
|
120
|
+
END
|
121
|
+
end
|
122
|
+
|
95
123
|
end
|
96
124
|
end
|