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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc08ca579c909a36f517e55af8c15dbc8b3e7bf6
4
- data.tar.gz: 5eb0d6c9e2e211110857db7fb3be22e4d22fb1f3
3
+ metadata.gz: 251fe2d5eeff7fd2bec5c9645a1c29158aa06475
4
+ data.tar.gz: 4546e8b4eb59c63d5988b8be4666515c31b482d4
5
5
  SHA512:
6
- metadata.gz: 5d1b4079773f7ec8b22c2687a9e10ca2861eba4f8bb48a9512a1ee0b016af10b5deee0e20c4ccb88d489d7eb5009fcdd203441a1106ddc6b2d867ff2d37c31bc
7
- data.tar.gz: 1f3157cf23f35c5b8a221631dcc8fd5c717c92167013c1bfe67b2cc945d16eac5bd985c39669d45c233ed0573c5756bb3bfaaee96e7abb2f6574b074c86b099d
6
+ metadata.gz: fef7271ed467a49d229b06ca462ce365dc781a92bfa10507da721d54193083a8c0440dc0e4c70bf66d547f185f37b15191fac7594e8f3a7c76c6f906ea958e95
7
+ data.tar.gz: 6d1d3e869708adf6a6221f7fe535a7ca4478bafb49b54c0c8a88ff8139e3147b7b305a878e69c1247769f55618cb840e68ce9a52ad55b2761cbaed6e3b978547
data/README.md CHANGED
@@ -62,6 +62,9 @@ end
62
62
  ```
63
63
 
64
64
  ### Usage
65
+ # If you want to make sure on application
66
+ # bootup that everything works, call this method:
67
+ Locality::IP.check!
65
68
 
66
69
  ```ruby
67
70
  lookup = Locality::IP.new '198.51.100.55'
@@ -61,7 +61,7 @@ module Locality
61
61
  result << Pathname.new('/mnt').join('databases', appendix)
62
62
  result << Pathname.new(Dir.pwd).join('db', appendix)
63
63
  result << additional
64
- result.compact
64
+ result.compact.uniq
65
65
  end
66
66
 
67
67
  end
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 raw_ip
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locality
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - bukowskis