maxmind-geoip2 0.1.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +32 -0
  3. data/Gemfile +1 -5
  4. data/README.dev.md +1 -1
  5. data/README.md +82 -8
  6. data/lib/maxmind/geoip2.rb +1 -0
  7. data/lib/maxmind/geoip2/client.rb +333 -0
  8. data/lib/maxmind/geoip2/errors.rb +37 -3
  9. data/lib/maxmind/geoip2/model/abstract.rb +19 -15
  10. data/lib/maxmind/geoip2/model/anonymous_ip.rb +62 -50
  11. data/lib/maxmind/geoip2/model/asn.rb +33 -29
  12. data/lib/maxmind/geoip2/model/city.rb +59 -55
  13. data/lib/maxmind/geoip2/model/connection_type.rb +27 -23
  14. data/lib/maxmind/geoip2/model/country.rb +64 -53
  15. data/lib/maxmind/geoip2/model/domain.rb +27 -23
  16. data/lib/maxmind/geoip2/model/enterprise.rb +13 -9
  17. data/lib/maxmind/geoip2/model/insights.rb +18 -0
  18. data/lib/maxmind/geoip2/model/isp.rb +45 -41
  19. data/lib/maxmind/geoip2/reader.rb +260 -233
  20. data/lib/maxmind/geoip2/record/abstract.rb +17 -13
  21. data/lib/maxmind/geoip2/record/city.rb +33 -29
  22. data/lib/maxmind/geoip2/record/continent.rb +32 -28
  23. data/lib/maxmind/geoip2/record/country.rb +47 -43
  24. data/lib/maxmind/geoip2/record/location.rb +64 -60
  25. data/lib/maxmind/geoip2/record/maxmind.rb +21 -0
  26. data/lib/maxmind/geoip2/record/place.rb +22 -18
  27. data/lib/maxmind/geoip2/record/postal.rb +26 -22
  28. data/lib/maxmind/geoip2/record/represented_country.rb +20 -16
  29. data/lib/maxmind/geoip2/record/subdivision.rb +42 -38
  30. data/lib/maxmind/geoip2/record/traits.rb +204 -191
  31. data/maxmind-geoip2.gemspec +11 -3
  32. data/test/data/bad-data/maxminddb-python/bad-unicode-in-map-key.mmdb +0 -0
  33. data/test/data/source-data/GeoIP2-Anonymous-IP-Test.json +1 -0
  34. data/test/data/source-data/GeoIP2-ISP-Test.json +3 -1
  35. data/test/data/source-data/GeoIP2-Precision-Enterprise-Test.json +87 -0
  36. data/test/data/test-data/GeoIP2-Anonymous-IP-Test.mmdb +0 -0
  37. data/test/data/test-data/GeoIP2-City-Test-Broken-Double-Format.mmdb +0 -0
  38. data/test/data/test-data/GeoIP2-City-Test-Invalid-Node-Count.mmdb +0 -0
  39. data/test/data/test-data/GeoIP2-City-Test.mmdb +0 -0
  40. data/test/data/test-data/GeoIP2-Connection-Type-Test.mmdb +0 -0
  41. data/test/data/test-data/GeoIP2-Country-Test.mmdb +0 -0
  42. data/test/data/test-data/GeoIP2-DensityIncome-Test.mmdb +0 -0
  43. data/test/data/test-data/GeoIP2-Domain-Test.mmdb +0 -0
  44. data/test/data/test-data/GeoIP2-Enterprise-Test.mmdb +0 -0
  45. data/test/data/test-data/GeoIP2-ISP-Test.mmdb +0 -0
  46. data/test/data/test-data/GeoIP2-Precision-Enterprise-Test.mmdb +0 -0
  47. data/test/data/test-data/GeoIP2-Static-IP-Score-Test.mmdb +0 -0
  48. data/test/data/test-data/GeoIP2-User-Count-Test.mmdb +0 -0
  49. data/test/data/test-data/GeoLite2-ASN-Test.mmdb +0 -0
  50. data/test/data/test-data/MaxMind-DB-no-ipv4-search-tree.mmdb +0 -0
  51. data/test/data/test-data/MaxMind-DB-string-value-entries.mmdb +0 -0
  52. data/test/data/test-data/MaxMind-DB-test-broken-pointers-24.mmdb +0 -0
  53. data/test/data/test-data/MaxMind-DB-test-broken-search-tree-24.mmdb +0 -0
  54. data/test/data/test-data/MaxMind-DB-test-decoder.mmdb +0 -0
  55. data/test/data/test-data/MaxMind-DB-test-ipv4-24.mmdb +0 -0
  56. data/test/data/test-data/MaxMind-DB-test-ipv4-28.mmdb +0 -0
  57. data/test/data/test-data/MaxMind-DB-test-ipv4-32.mmdb +0 -0
  58. data/test/data/test-data/MaxMind-DB-test-ipv6-24.mmdb +0 -0
  59. data/test/data/test-data/MaxMind-DB-test-ipv6-28.mmdb +0 -0
  60. data/test/data/test-data/MaxMind-DB-test-ipv6-32.mmdb +0 -0
  61. data/test/data/test-data/MaxMind-DB-test-metadata-pointers.mmdb +0 -0
  62. data/test/data/test-data/MaxMind-DB-test-mixed-24.mmdb +0 -0
  63. data/test/data/test-data/MaxMind-DB-test-mixed-28.mmdb +0 -0
  64. data/test/data/test-data/MaxMind-DB-test-mixed-32.mmdb +0 -0
  65. data/test/data/test-data/MaxMind-DB-test-nested.mmdb +0 -0
  66. data/test/data/test-data/MaxMind-DB-test-pointer-decoder.mmdb +0 -0
  67. data/test/data/test-data/write-test-data.pl +68 -18
  68. data/test/test_client.rb +426 -0
  69. data/test/test_model_country.rb +16 -0
  70. data/test/test_reader.rb +59 -0
  71. metadata +113 -10
  72. data/Gemfile.lock +0 -38
@@ -77,4 +77,20 @@ class CountryModelTest < Minitest::Test
77
77
  model = MaxMind::GeoIP2::Model::Country.new(RAW, ['en'])
78
78
  assert_raises(NoMethodError) { model.traits.unknown }
79
79
  end
80
+
81
+ # This can happen if we're being created from a not fully populated response
82
+ # when used by minFraud. It shouldn't ever happen from GeoIP2 though.
83
+ def test_no_traits
84
+ model = MaxMind::GeoIP2::Model::Country.new(
85
+ {
86
+ 'continent' => {
87
+ 'code' => 'NA',
88
+ 'geoname_id' => 42,
89
+ 'names' => { 'en' => 'North America' },
90
+ },
91
+ },
92
+ ['en'],
93
+ )
94
+ assert_equal(42, model.continent.geoname_id)
95
+ end
80
96
  end
data/test/test_reader.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'ipaddr'
4
+ require 'maxmind/db'
4
5
  require 'maxmind/geoip2'
5
6
  require 'minitest/autorun'
6
7
 
@@ -16,6 +17,7 @@ class ReaderTest < Minitest::Test
16
17
  assert_equal(true, record.anonymous_vpn?)
17
18
  assert_equal(false, record.hosting_provider?)
18
19
  assert_equal(false, record.public_proxy?)
20
+ assert_equal(false, record.residential_proxy?)
19
21
  assert_equal(false, record.tor_exit_node?)
20
22
  assert_equal(ip, record.ip_address)
21
23
  assert_equal('1.2.0.0/16', record.network)
@@ -23,6 +25,18 @@ class ReaderTest < Minitest::Test
23
25
  reader.close
24
26
  end
25
27
 
28
+ def test_anonymous_ip_residential_proxy
29
+ reader = MaxMind::GeoIP2::Reader.new(
30
+ 'test/data/test-data/GeoIP2-Anonymous-IP-Test.mmdb',
31
+ )
32
+ ip = '81.2.69.1'
33
+ record = reader.anonymous_ip(ip)
34
+
35
+ assert_equal(true, record.residential_proxy?)
36
+
37
+ reader.close
38
+ end
39
+
26
40
  def test_asn
27
41
  reader = MaxMind::GeoIP2::Reader.new(
28
42
  'test/data/test-data/GeoLite2-ASN-Test.mmdb',
@@ -456,4 +470,49 @@ class ReaderTest < Minitest::Test
456
470
  assert_equal('GeoIP2-City', reader.metadata.database_type)
457
471
  reader.close
458
472
  end
473
+
474
+ def test_constructor_with_minimum_keyword_arguments
475
+ reader = MaxMind::GeoIP2::Reader.new(
476
+ database: 'test/data/test-data/GeoIP2-Country-Test.mmdb',
477
+ )
478
+ record = reader.country('81.2.69.160')
479
+ assert_equal('United Kingdom', record.country.name)
480
+ reader.close
481
+ end
482
+
483
+ def test_constructor_with_all_keyword_arguments
484
+ reader = MaxMind::GeoIP2::Reader.new(
485
+ database: 'test/data/test-data/GeoIP2-Country-Test.mmdb',
486
+ locales: %w[ru],
487
+ mode: MaxMind::DB::MODE_MEMORY,
488
+ )
489
+ record = reader.country('81.2.69.160')
490
+ assert_equal('Великобритания', record.country.name)
491
+ reader.close
492
+ end
493
+
494
+ def test_constructor_missing_database
495
+ error = assert_raises(ArgumentError) do
496
+ MaxMind::GeoIP2::Reader.new
497
+ end
498
+ assert_equal('Invalid database parameter', error.message)
499
+
500
+ error = assert_raises(ArgumentError) do
501
+ MaxMind::GeoIP2::Reader.new(
502
+ locales: %w[ru],
503
+ )
504
+ end
505
+ assert_equal('Invalid database parameter', error.message)
506
+ end
507
+
508
+ def test_old_constructor_parameters
509
+ reader = MaxMind::GeoIP2::Reader.new(
510
+ 'test/data/test-data/GeoIP2-Country-Test.mmdb',
511
+ %w[ru],
512
+ mode: MaxMind::DB::MODE_MEMORY,
513
+ )
514
+ record = reader.country('81.2.69.160')
515
+ assert_equal('Великобритания', record.country.name)
516
+ reader.close
517
+ end
459
518
  end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maxmind-geoip2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Storey
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-20 00:00:00.000000000 Z
11
+ date: 2021-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: connection_pool
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: http
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.3'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.3'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: maxmind-db
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -24,6 +52,76 @@ dependencies:
24
52
  - - "~>"
25
53
  - !ruby/object:Gem::Version
26
54
  version: '1.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-performance
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
27
125
  description: A gem for interacting with the GeoIP2 webservices and databases. MaxMind
28
126
  provides geolocation data as downloadable databases as well as through a webservice.
29
127
  email: support@maxmind.com
@@ -33,13 +131,13 @@ extra_rdoc_files: []
33
131
  files:
34
132
  - CHANGELOG.md
35
133
  - Gemfile
36
- - Gemfile.lock
37
134
  - LICENSE-APACHE
38
135
  - LICENSE-MIT
39
136
  - README.dev.md
40
137
  - README.md
41
138
  - Rakefile
42
139
  - lib/maxmind/geoip2.rb
140
+ - lib/maxmind/geoip2/client.rb
43
141
  - lib/maxmind/geoip2/errors.rb
44
142
  - lib/maxmind/geoip2/model/abstract.rb
45
143
  - lib/maxmind/geoip2/model/anonymous_ip.rb
@@ -49,6 +147,7 @@ files:
49
147
  - lib/maxmind/geoip2/model/country.rb
50
148
  - lib/maxmind/geoip2/model/domain.rb
51
149
  - lib/maxmind/geoip2/model/enterprise.rb
150
+ - lib/maxmind/geoip2/model/insights.rb
52
151
  - lib/maxmind/geoip2/model/isp.rb
53
152
  - lib/maxmind/geoip2/reader.rb
54
153
  - lib/maxmind/geoip2/record/abstract.rb
@@ -56,6 +155,7 @@ files:
56
155
  - lib/maxmind/geoip2/record/continent.rb
57
156
  - lib/maxmind/geoip2/record/country.rb
58
157
  - lib/maxmind/geoip2/record/location.rb
158
+ - lib/maxmind/geoip2/record/maxmind.rb
59
159
  - lib/maxmind/geoip2/record/place.rb
60
160
  - lib/maxmind/geoip2/record/postal.rb
61
161
  - lib/maxmind/geoip2/record/represented_country.rb
@@ -75,6 +175,7 @@ files:
75
175
  - test/data/bad-data/maxminddb-golang/invalid-string-length.mmdb
76
176
  - test/data/bad-data/maxminddb-golang/metadata-is-an-uint128.mmdb
77
177
  - test/data/bad-data/maxminddb-golang/unexpected-bytes.mmdb
178
+ - test/data/bad-data/maxminddb-python/bad-unicode-in-map-key.mmdb
78
179
  - test/data/perltidyrc
79
180
  - test/data/source-data/GeoIP2-Anonymous-IP-Test.json
80
181
  - test/data/source-data/GeoIP2-City-Test.json
@@ -119,10 +220,12 @@ files:
119
220
  - test/data/test-data/MaxMind-DB-test-mixed-28.mmdb
120
221
  - test/data/test-data/MaxMind-DB-test-mixed-32.mmdb
121
222
  - test/data/test-data/MaxMind-DB-test-nested.mmdb
223
+ - test/data/test-data/MaxMind-DB-test-pointer-decoder.mmdb
122
224
  - test/data/test-data/README.md
123
225
  - test/data/test-data/maps-with-pointers.raw
124
226
  - test/data/test-data/write-test-data.pl
125
227
  - test/data/tidyall.ini
228
+ - test/test_client.rb
126
229
  - test/test_model_country.rb
127
230
  - test/test_model_names.rb
128
231
  - test/test_reader.rb
@@ -132,11 +235,11 @@ licenses:
132
235
  - MIT
133
236
  metadata:
134
237
  bug_tracker_uri: https://github.com/maxmind/GeoIP2-ruby/issues
135
- changelog_uri: https://github.com/maxmind/GeoIP2-ruby/blob/master/CHANGELOG.md
136
- documentation_uri: https://github.com/maxmind/GeoIP2-ruby
238
+ changelog_uri: https://github.com/maxmind/GeoIP2-ruby/blob/main/CHANGELOG.md
239
+ documentation_uri: https://www.rubydoc.info/gems/maxmind-geoip2
137
240
  homepage_uri: https://github.com/maxmind/GeoIP2-ruby
138
241
  source_code_uri: https://github.com/maxmind/GeoIP2-ruby
139
- post_install_message:
242
+ post_install_message:
140
243
  rdoc_options: []
141
244
  require_paths:
142
245
  - lib
@@ -151,9 +254,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
254
  - !ruby/object:Gem::Version
152
255
  version: '0'
153
256
  requirements: []
154
- rubyforge_project:
155
- rubygems_version: 2.7.6
156
- signing_key:
257
+ rubyforge_project:
258
+ rubygems_version: 2.7.6.2
259
+ signing_key:
157
260
  specification_version: 4
158
261
  summary: A gem for interacting with the GeoIP2 webservices and databases.
159
262
  test_files: []
data/Gemfile.lock DELETED
@@ -1,38 +0,0 @@
1
- GEM
2
- remote: https://rubygems.org/
3
- specs:
4
- ast (2.4.0)
5
- jaro_winkler (1.5.4)
6
- maxmind-db (1.1.0)
7
- minitest (5.14.0)
8
- parallel (1.19.1)
9
- parser (2.7.0.2)
10
- ast (~> 2.4.0)
11
- rainbow (3.0.0)
12
- rake (13.0.1)
13
- rexml (3.2.4)
14
- rubocop (0.80.0)
15
- jaro_winkler (~> 1.5.1)
16
- parallel (~> 1.10)
17
- parser (>= 2.7.0.1)
18
- rainbow (>= 2.2.2, < 4.0)
19
- rexml
20
- ruby-progressbar (~> 1.7)
21
- unicode-display_width (>= 1.4.0, < 1.7)
22
- rubocop-performance (1.5.2)
23
- rubocop (>= 0.71.0)
24
- ruby-progressbar (1.10.1)
25
- unicode-display_width (1.6.1)
26
-
27
- PLATFORMS
28
- ruby
29
-
30
- DEPENDENCIES
31
- maxmind-db
32
- minitest
33
- rake
34
- rubocop
35
- rubocop-performance
36
-
37
- BUNDLED WITH
38
- 2.1.4