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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d18a288c4e90ba7ebfe5d5e215d8943fbd701fc97ac1e674d215af65e1594b42
4
- data.tar.gz: '048f0b39f39390439d262ee0fe71954fca6c9c1795b4f37943aa212bac7caf68'
3
+ metadata.gz: 35df4a80a6aacc298e40b69ec62335ed016d03475c3e8f8fbd3cd7efd9d88fb1
4
+ data.tar.gz: acf38b6753b48cedf6fe1a6d3bb2cc591885f5d3f07382c90aa44d0502f39127
5
5
  SHA512:
6
- metadata.gz: e1026652e3f2707ca157f141188bccbaf6493e2ea648e1ddee4d132bca17bad20cf2d58cd01288d67713fd95532a647f163c04405caaf6ceed0c6e5cd1802e8d
7
- data.tar.gz: 85ce20acf9f36205215f71eddee8a2361b5af4ac34c63f289fa1c320cacaff8e29aad2da029b06fb2a80fee962e256a05a541bab874cc32f6e93929649a24995
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 maxminddb gem.
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
- db = @db ||= MaxMindDB.new(db_path.to_s)
16
- result = db.lookup(ip_address)
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: result.country.iso_code,
21
- country_name: result.country.name,
22
- city: result.city.name,
23
- region: result.subdivisions.most_specific&.name,
24
- latitude: result.location.latitude,
25
- longitude: result.location.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 MaxMindDB::Error => e
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 DB handle (useful after db file is updated)
33
+ # Reset cached reader handle (call after db file is updated)
36
34
  def self.reset!
37
- @db = nil
35
+ @reader = nil
38
36
  end
39
37
  end
40
38
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ContentSignals
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.5"
5
5
  end
@@ -11,9 +11,9 @@ rescue LoadError
11
11
  end
12
12
 
13
13
  begin
14
- require "maxminddb"
14
+ require "maxmind/geoip2"
15
15
  rescue LoadError
16
- # maxminddb gem not installed - MaxmindProvider will be disabled
16
+ # maxmind-geoip2 gem not installed - MaxmindProvider will be disabled
17
17
  end
18
18
 
19
19
  require "net/http"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: content_signals
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ionuț Munteanu Alexandru