content_signals 0.1.4 → 0.1.5
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 +4 -4
- data/lib/content_signals/geoip/maxmind_provider.rb +12 -14
- data/lib/content_signals/version.rb +1 -1
- data/lib/content_signals.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 35df4a80a6aacc298e40b69ec62335ed016d03475c3e8f8fbd3cd7efd9d88fb1
|
|
4
|
+
data.tar.gz: acf38b6753b48cedf6fe1a6d3bb2cc591885f5d3f07382c90aa44d0502f39127
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4937fd93a8e8364754d50ad66e2e5c13053e52afdb92def717c2b0405bebb10a0cfc40146a277701e4e55577c490634e82b10f0d492b1b322cf63823e3239197
|
|
7
|
+
data.tar.gz: deefaaa37a9ade9e2e0398445fee0a082c7cc2be0fa00383c58d45882543c69e5d519b1569b5915cc87c787d3dfc69e31f650b190c6d0c49af733a3f3fcba295
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module ContentSignals
|
|
4
4
|
module Geoip
|
|
5
5
|
# Offline geolocation using a local MaxMind GeoLite2-City .mmdb file.
|
|
6
|
-
# Requires the
|
|
6
|
+
# Requires the maxmind-geoip2 gem.
|
|
7
7
|
# Download/update the database: bundle exec rake stejar:geoip:update
|
|
8
8
|
class MaxmindProvider < BaseProvider
|
|
9
9
|
def self.locate(ip_address)
|
|
@@ -12,29 +12,27 @@ module ContentSignals
|
|
|
12
12
|
db_path = ContentSignals.configuration.maxmind_db_path
|
|
13
13
|
return nil unless db_path && File.exist?(db_path.to_s)
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return nil unless result&.found?
|
|
15
|
+
reader = @reader ||= MaxMind::GeoIP2::Reader.new(database: db_path.to_s)
|
|
16
|
+
record = reader.city(ip_address)
|
|
18
17
|
|
|
19
18
|
{
|
|
20
|
-
country_code:
|
|
21
|
-
country_name:
|
|
22
|
-
city:
|
|
23
|
-
region:
|
|
24
|
-
latitude:
|
|
25
|
-
longitude:
|
|
19
|
+
country_code: record.country.iso_code,
|
|
20
|
+
country_name: record.country.name,
|
|
21
|
+
city: record.city.name,
|
|
22
|
+
region: record.subdivisions.most_specific&.name,
|
|
23
|
+
latitude: record.location.latitude,
|
|
24
|
+
longitude: record.location.longitude
|
|
26
25
|
}
|
|
27
|
-
rescue
|
|
28
|
-
Rails.logger.error "MaxMind lookup error: #{e.message}"
|
|
26
|
+
rescue MaxMind::GeoIP2::AddressNotFoundError
|
|
29
27
|
nil
|
|
30
28
|
rescue => e
|
|
31
29
|
Rails.logger.error "MaxMind geolocation error: #{e.message}"
|
|
32
30
|
nil
|
|
33
31
|
end
|
|
34
32
|
|
|
35
|
-
# Reset cached
|
|
33
|
+
# Reset cached reader handle (call after db file is updated)
|
|
36
34
|
def self.reset!
|
|
37
|
-
@
|
|
35
|
+
@reader = nil
|
|
38
36
|
end
|
|
39
37
|
end
|
|
40
38
|
end
|
data/lib/content_signals.rb
CHANGED
|
@@ -11,9 +11,9 @@ rescue LoadError
|
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
begin
|
|
14
|
-
require "
|
|
14
|
+
require "maxmind/geoip2"
|
|
15
15
|
rescue LoadError
|
|
16
|
-
#
|
|
16
|
+
# maxmind-geoip2 gem not installed - MaxmindProvider will be disabled
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
require "net/http"
|