regeoip 0.0.5 → 0.0.6

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
  SHA1:
3
- metadata.gz: 42c391fc1d30f34e2f857747689ca75f8b00b6bb
4
- data.tar.gz: 6535edca0dc1bc8c276685fd611c53221d8e3ea1
3
+ metadata.gz: 6bc6d306e1c1a792694ac124bd99e245b845b7b3
4
+ data.tar.gz: 8fec8b08376b3da6ebfb6eb5c2e48291458afce5
5
5
  SHA512:
6
- metadata.gz: bcedd343030441a904efd6eecb9013705d663eed2d59f303a6ad8496e6932c042193bce5a68d3108e87d3f866b6c107a7edaab1789eacec9a07a5c545c0a3415
7
- data.tar.gz: fca5eab7be00f1f3f7d3078a39bf9ad95f0bd6cc2e6f78da2ca5ebb1f0009f214ae342bc36e91d391db32f68e2e2d7b30ad3423a198021a40ba51ad73fd36bde
6
+ metadata.gz: 14a739b1bac7c2792a99a72cf5dfda28b23fd6ba5908fcb75653ed3918da317de517c0a444594d6ad4c5d282fe5532a7ed3b5bd133b9522af373bbbc5a415d23
7
+ data.tar.gz: b8defdc9d27f5903665b9b06a1dcf2e35a6a0e71b6bd139d2f7f7d8f07081585f8b59e0e3dc4e1de98e639585723cdfd857b4dca344dcfe506b77c1a6a09faeb
@@ -0,0 +1,41 @@
1
+ # Ruby CircleCI 2.0 configuration file
2
+ #
3
+ # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
+ #
5
+ version: 2
6
+ jobs:
7
+ build:
8
+ docker:
9
+ # specify the version you desire here
10
+ - image: circleci/ruby:2.2.8
11
+
12
+ # Specify service dependencies here if necessary
13
+ # CircleCI maintains a library of pre-built images
14
+ # documented at https://circleci.com/docs/2.0/circleci-images/
15
+ # - image: circleci/postgres:9.4
16
+
17
+ working_directory: ~/repo
18
+
19
+ steps:
20
+ - checkout
21
+
22
+ # Download and cache dependencies
23
+ - restore_cache:
24
+ keys:
25
+ - v1-dependencies-{{ checksum "Gemfile.lock" }}
26
+ # fallback to using the latest cache if no exact match is found
27
+ - v1-dependencies-
28
+
29
+ - run:
30
+ name: install dependencies
31
+ command: |
32
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
33
+
34
+ - save_cache:
35
+ paths:
36
+ - ./vendor/bundle
37
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
38
+
39
+ - run:
40
+ name: run tests
41
+ command: bundle exec rspec spec/
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # Regeoip
2
2
 
3
- Regeoip come with GeoIP.dat and GeoIPv6.dat so that it will resolve
4
- either IPv4 or IPv4 to country without a need for a request.
3
+ Regeoip come with GeoLite2-City.mmdb so that it will resolve
4
+ either IPv4 or IPv6 to country and city without a need for a request.
5
5
 
6
- All you need is: `Regeoip.resolve_country_code2(ip)`
6
+ All you need is: `Regeoip.resolve(ip)`
7
7
 
8
8
  ## Installation
9
9
 
@@ -23,13 +23,16 @@ Or install it yourself as:
23
23
 
24
24
  ## Usage
25
25
 
26
+ Get all location data:
27
+ Regeoip.resolve(ip)
28
+
26
29
  Get country data:
27
30
 
28
31
  Regeoip.resolve_country(ip)
29
32
 
30
33
  Get country code:
31
34
 
32
- Regeoip.resolve_country_code2(ip)
35
+ Regeoip.resolve_country_code(ip)
33
36
 
34
37
  ## Development
35
38
 
Binary file
@@ -1,32 +1,32 @@
1
1
  require 'regeoip/version'
2
- require 'geoip'
2
+ require 'maxminddb'
3
3
 
4
4
  module Regeoip
5
5
  def self.resolve_country(ip)
6
- return nil if ip.nil?
7
- if ip.to_s =~ /^[0-9.]+$/
8
- geoipv4.country(ip)
6
+ if (geo_info = resolve(ip))
7
+ geo_info.country
9
8
  else
10
- geoipv6.country(ip.to_s)
9
+ nil
11
10
  end
12
11
  end
13
12
 
14
- def self.resolve_country_code2(ip)
13
+ def self.resolve_country_code(ip)
15
14
  if (country = resolve_country(ip))
16
- country.country_code2
15
+ country.iso_code
17
16
  else
18
17
  nil
19
18
  end
20
19
  end
21
20
 
22
- private
23
-
24
- def self.geoipv4
25
- @geoipv4 ||= GeoIP.new(local_path('GeoIP.dat'))
21
+ def self.resolve(ip)
22
+ return nil if ip.nil?
23
+ max_mind_db.lookup(ip.to_s)
26
24
  end
27
25
 
28
- def self.geoipv6
29
- @geoipv6 ||= GeoIP.new(local_path('GeoIPv6.dat'))
26
+ private
27
+
28
+ def self.max_mind_db
29
+ @max_mind_db ||= MaxMindDB.new(local_path('GeoLite2-City.mmdb'))
30
30
  end
31
31
 
32
32
  def self.local_path(file)
@@ -1,3 +1,3 @@
1
1
  module Regeoip
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "geoip", "~> 1.6.2"
21
+ spec.add_dependency "maxminddb", "~> 0.1.22"
22
22
  spec.add_development_dependency "bundler", "~> 1.12"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
  spec.add_development_dependency "rspec", "~> 3.0"
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: regeoip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phuong Nguyen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-11 00:00:00.000000000 Z
11
+ date: 2019-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: geoip
14
+ name: maxminddb
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.6.2
19
+ version: 0.1.22
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.6.2
26
+ version: 0.1.22
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -74,6 +74,7 @@ executables:
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
+ - ".circleci/config.yml"
77
78
  - ".gitignore"
78
79
  - ".rspec"
79
80
  - ".travis.yml"
@@ -81,8 +82,7 @@ files:
81
82
  - README.md
82
83
  - Rakefile
83
84
  - bin/setup
84
- - lib/GeoIP.dat
85
- - lib/GeoIPv6.dat
85
+ - lib/GeoLite2-City.mmdb
86
86
  - lib/regeoip.rb
87
87
  - lib/regeoip/version.rb
88
88
  - regeoip.gemspec
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  version: '0'
106
106
  requirements: []
107
107
  rubyforge_project:
108
- rubygems_version: 2.2.2
108
+ rubygems_version: 2.4.5.2
109
109
  signing_key:
110
110
  specification_version: 4
111
111
  summary: Resolve ipv4 and ipv6 to country code without need for extra http request
Binary file
Binary file