maxmind-geoip2 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/README.md +4 -6
  4. data/lib/maxmind/geoip2/client.rb +1 -1
  5. data/lib/maxmind/geoip2/errors.rb +17 -8
  6. data/lib/maxmind/geoip2/model/city.rb +1 -1
  7. data/lib/maxmind/geoip2/model/enterprise.rb +1 -1
  8. data/lib/maxmind/geoip2/model/insights.rb +1 -1
  9. data/lib/maxmind/geoip2/model/isp.rb +16 -0
  10. data/lib/maxmind/geoip2/reader.rb +1 -2
  11. data/lib/maxmind/geoip2/record/traits.rb +23 -3
  12. data/maxmind-geoip2.gemspec +2 -1
  13. data/test/data/MaxMind-DB-spec.md +15 -11
  14. data/test/data/source-data/GeoIP2-City-Test.json +81 -48
  15. data/test/data/source-data/GeoIP2-Connection-Type-Test.json +20 -0
  16. data/test/data/source-data/GeoIP2-Country-Test.json +46 -58
  17. data/test/data/source-data/GeoIP2-Enterprise-Test.json +61 -3
  18. data/test/data/source-data/GeoIP2-ISP-Test.json +10 -0
  19. data/test/data/source-data/GeoIP2-Precision-Enterprise-Test.json +61 -4
  20. data/test/data/source-data/GeoLite2-ASN-Test.json +4091 -8
  21. data/test/data/source-data/GeoLite2-City-Test.json +12804 -0
  22. data/test/data/source-data/GeoLite2-Country-Test.json +11280 -0
  23. data/test/data/test-data/GeoIP2-Anonymous-IP-Test.mmdb +0 -0
  24. data/test/data/test-data/GeoIP2-City-Test-Broken-Double-Format.mmdb +0 -0
  25. data/test/data/test-data/GeoIP2-City-Test-Invalid-Node-Count.mmdb +0 -0
  26. data/test/data/test-data/GeoIP2-City-Test.mmdb +0 -0
  27. data/test/data/test-data/GeoIP2-Connection-Type-Test.mmdb +0 -0
  28. data/test/data/test-data/GeoIP2-Country-Test.mmdb +0 -0
  29. data/test/data/test-data/GeoIP2-DensityIncome-Test.mmdb +0 -0
  30. data/test/data/test-data/GeoIP2-Domain-Test.mmdb +0 -0
  31. data/test/data/test-data/GeoIP2-Enterprise-Test.mmdb +0 -0
  32. data/test/data/test-data/GeoIP2-ISP-Test.mmdb +0 -0
  33. data/test/data/test-data/GeoIP2-Precision-Enterprise-Test.mmdb +0 -0
  34. data/test/data/test-data/GeoIP2-Static-IP-Score-Test.mmdb +0 -0
  35. data/test/data/test-data/GeoIP2-User-Count-Test.mmdb +0 -0
  36. data/test/data/test-data/GeoLite2-ASN-Test.mmdb +0 -0
  37. data/test/data/test-data/GeoLite2-City-Test.mmdb +0 -0
  38. data/test/data/test-data/GeoLite2-Country-Test.mmdb +0 -0
  39. data/test/data/test-data/MaxMind-DB-no-ipv4-search-tree.mmdb +0 -0
  40. data/test/data/test-data/MaxMind-DB-string-value-entries.mmdb +0 -0
  41. data/test/data/test-data/MaxMind-DB-test-broken-pointers-24.mmdb +0 -0
  42. data/test/data/test-data/MaxMind-DB-test-broken-search-tree-24.mmdb +0 -0
  43. data/test/data/test-data/MaxMind-DB-test-decoder.mmdb +0 -0
  44. data/test/data/test-data/MaxMind-DB-test-ipv4-24.mmdb +0 -0
  45. data/test/data/test-data/MaxMind-DB-test-ipv4-28.mmdb +0 -0
  46. data/test/data/test-data/MaxMind-DB-test-ipv4-32.mmdb +0 -0
  47. data/test/data/test-data/MaxMind-DB-test-ipv6-24.mmdb +0 -0
  48. data/test/data/test-data/MaxMind-DB-test-ipv6-28.mmdb +0 -0
  49. data/test/data/test-data/MaxMind-DB-test-ipv6-32.mmdb +0 -0
  50. data/test/data/test-data/MaxMind-DB-test-metadata-pointers.mmdb +0 -0
  51. data/test/data/test-data/MaxMind-DB-test-mixed-24.mmdb +0 -0
  52. data/test/data/test-data/MaxMind-DB-test-mixed-28.mmdb +0 -0
  53. data/test/data/test-data/MaxMind-DB-test-mixed-32.mmdb +0 -0
  54. data/test/data/test-data/MaxMind-DB-test-nested.mmdb +0 -0
  55. data/test/data/test-data/MaxMind-DB-test-pointer-decoder.mmdb +0 -0
  56. data/test/data/test-data/README.md +3 -3
  57. data/test/data/test-data/write-test-data.pl +9 -5
  58. data/test/test_reader.rb +18 -2
  59. metadata +8 -4
  60. data/test/data/MaxMind-DB-test-metadata-pointers.mmdb +0 -0
@@ -10,17 +10,17 @@ pointers to map keys and values, as well as to the whole map.
10
10
 
11
11
  There are several ways to figure out what IP addresses are actually in the
12
12
  test databases. You can take a look at the
13
- [source-data directory](https://github.com/maxmind/MaxMind-DB/tree/master/source-data)
13
+ [source-data directory](https://github.com/maxmind/MaxMind-DB/tree/main/source-data)
14
14
  in this repository. This directory contains JSON files which are used to
15
15
  generate many (but not all) of the database files.
16
16
 
17
17
  You can also use the
18
- [mmdb-dump-database script](https://github.com/maxmind/MaxMind-DB-Reader-perl/blob/master/eg/mmdb-dump-database)
18
+ [mmdb-dump-database script](https://github.com/maxmind/MaxMind-DB-Reader-perl/blob/main/eg/mmdb-dump-database)
19
19
  in the
20
20
  [MaxMind-DB-Reader-perl repository](https://github.com/maxmind/MaxMind-DB-Reader-perl).
21
21
 
22
22
  Some databases are intentionally broken and cannot be dumped. You can look at
23
23
  the
24
- [script which generates these databases](https://github.com/maxmind/MaxMind-DB/blob/master/test-data/write-test-data.pl)
24
+ [script which generates these databases](https://github.com/maxmind/MaxMind-DB/blob/main/test-data/write-test-data.pl)
25
25
  to see what IP addresses they include, which will be necessary for those
26
26
  databases which cannot be dumped because they contain intentional errors.
@@ -19,7 +19,7 @@ use Test::MaxMind::DB::Common::Util qw( standard_test_metadata );
19
19
  my $Dir = dirname( abs_path($0) );
20
20
 
21
21
  sub main {
22
- my @sizes = ( 24, 28, 32 );
22
+ my @sizes = ( 24, 28, 32 );
23
23
  my @ipv4_range = ( '1.1.1.1', '1.1.1.32' );
24
24
 
25
25
  my @ipv4_subnets = Net::Works::Network->range_as_subnets(@ipv4_range);
@@ -243,7 +243,7 @@ sub write_test_db {
243
243
  ::4.5.6.7/128
244
244
  abcd::/64
245
245
  1000::1234:0000/112
246
- );
246
+ );
247
247
 
248
248
  for my $subnet (@subnets) {
249
249
  $writer->insert_network(
@@ -379,7 +379,7 @@ sub write_test_db {
379
379
  ::4.5.6.7/128
380
380
  abcd::/64
381
381
  1000::1234:0000/112
382
- );
382
+ );
383
383
 
384
384
  for my $subnet (@subnets) {
385
385
  $writer->insert_network(
@@ -411,6 +411,8 @@ sub write_geoip2_dbs {
411
411
  ['GeoIP2-Static-IP-Score'],
412
412
  ['GeoIP2-User-Count'],
413
413
  ['GeoLite2-ASN'],
414
+ ['GeoLite2-City'],
415
+ ['GeoLite2-Country'],
414
416
  );
415
417
  }
416
418
 
@@ -485,6 +487,8 @@ sub _universal_map_key_type_callback {
485
487
  location => 'map',
486
488
  longitude => 'double',
487
489
  metro_code => 'uint16',
490
+ mobile_country_code => 'utf8_string',
491
+ mobile_network_code => 'utf8_string',
488
492
  names => 'map',
489
493
  organization => 'utf8_string',
490
494
  population_density => 'uint32',
@@ -655,7 +659,7 @@ sub write_test_serialization_data {
655
659
  $serializer->store_data( map => { long_key => 'long_value1' } );
656
660
  $serializer->store_data( map => { long_key2 => 'long_value2' } );
657
661
 
658
- open my $fh, '>', 'maps-with-pointers.raw';
662
+ open my $fh, '>', "$Dir/maps-with-pointers.raw";
659
663
  print {$fh} ${ $serializer->buffer() }
660
664
  or die "Cannot write to maps-with-pointers.raw: $!";
661
665
  close $fh;
@@ -681,7 +685,7 @@ sub write_db_with_metadata_pointers {
681
685
 
682
686
  _populate_all_networks( $writer, {} );
683
687
 
684
- open my $fh, '>', 'MaxMind-DB-test-metadata-pointers.mmdb';
688
+ open my $fh, '>', "$Dir/MaxMind-DB-test-metadata-pointers.mmdb";
685
689
 
686
690
  $writer->write_tree($fh);
687
691
 
data/test/test_reader.rb CHANGED
@@ -150,7 +150,7 @@ class ReaderTest < Minitest::Test
150
150
  assert_equal('Europe', record.continent.name)
151
151
 
152
152
  assert_equal(2_635_167, record.country.geoname_id)
153
- assert_equal(true, record.country.in_european_union?)
153
+ assert_equal(false, record.country.in_european_union?)
154
154
  assert_equal('GB', record.country.iso_code)
155
155
  assert_equal(
156
156
  {
@@ -266,6 +266,14 @@ class ReaderTest < Minitest::Test
266
266
  assert_equal(ip_address, record.traits.ip_address)
267
267
  assert_equal('74.209.16.0/20', record.traits.network)
268
268
 
269
+ # This IP has MCC/MNC data.
270
+
271
+ ip_address = '149.101.100.0'
272
+ record = reader.enterprise(ip_address)
273
+
274
+ assert_equal('310', record.traits.mobile_country_code)
275
+ assert_equal('004', record.traits.mobile_network_code)
276
+
269
277
  reader.close
270
278
  end
271
279
 
@@ -283,6 +291,14 @@ class ReaderTest < Minitest::Test
283
291
  assert_equal(ip, record.ip_address)
284
292
  assert_equal('1.128.0.0/11', record.network)
285
293
 
294
+ # This IP has MCC/MNC data.
295
+
296
+ ip_address = '149.101.100.0'
297
+ record = reader.isp(ip_address)
298
+
299
+ assert_equal('310', record.mobile_country_code)
300
+ assert_equal('004', record.mobile_network_code)
301
+
286
302
  reader.close
287
303
  end
288
304
 
@@ -416,7 +432,7 @@ class ReaderTest < Minitest::Test
416
432
  "test/data/test-data/GeoIP2-#{t['file']}-Test.mmdb",
417
433
  )
418
434
  record = reader.send(t['method'], '81.2.69.160')
419
- assert_equal(true, record.country.in_european_union?)
435
+ assert_equal(false, record.country.in_european_union?)
420
436
  assert_equal(false, record.registered_country.in_european_union?)
421
437
  reader.close
422
438
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maxmind-geoip2
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Storey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-14 00:00:00.000000000 Z
11
+ date: 2021-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: connection_pool
@@ -170,7 +170,6 @@ files:
170
170
  - maxmind-geoip2.gemspec
171
171
  - test/data/LICENSE
172
172
  - test/data/MaxMind-DB-spec.md
173
- - test/data/MaxMind-DB-test-metadata-pointers.mmdb
174
173
  - test/data/README.md
175
174
  - test/data/bad-data/README.md
176
175
  - test/data/bad-data/libmaxminddb/libmaxminddb-offset-integer-overflow.mmdb
@@ -195,6 +194,8 @@ files:
195
194
  - test/data/source-data/GeoIP2-Static-IP-Score-Test.json
196
195
  - test/data/source-data/GeoIP2-User-Count-Test.json
197
196
  - test/data/source-data/GeoLite2-ASN-Test.json
197
+ - test/data/source-data/GeoLite2-City-Test.json
198
+ - test/data/source-data/GeoLite2-Country-Test.json
198
199
  - test/data/source-data/README
199
200
  - test/data/test-data/GeoIP2-Anonymous-IP-Test.mmdb
200
201
  - test/data/test-data/GeoIP2-City-Test-Broken-Double-Format.mmdb
@@ -210,6 +211,8 @@ files:
210
211
  - test/data/test-data/GeoIP2-Static-IP-Score-Test.mmdb
211
212
  - test/data/test-data/GeoIP2-User-Count-Test.mmdb
212
213
  - test/data/test-data/GeoLite2-ASN-Test.mmdb
214
+ - test/data/test-data/GeoLite2-City-Test.mmdb
215
+ - test/data/test-data/GeoLite2-Country-Test.mmdb
213
216
  - test/data/test-data/MaxMind-DB-no-ipv4-search-tree.mmdb
214
217
  - test/data/test-data/MaxMind-DB-string-value-entries.mmdb
215
218
  - test/data/test-data/MaxMind-DB-test-broken-pointers-24.mmdb
@@ -244,6 +247,7 @@ metadata:
244
247
  changelog_uri: https://github.com/maxmind/GeoIP2-ruby/blob/main/CHANGELOG.md
245
248
  documentation_uri: https://www.rubydoc.info/gems/maxmind-geoip2
246
249
  homepage_uri: https://github.com/maxmind/GeoIP2-ruby
250
+ rubygems_mfa_required: 'true'
247
251
  source_code_uri: https://github.com/maxmind/GeoIP2-ruby
248
252
  post_install_message:
249
253
  rdoc_options: []
@@ -260,7 +264,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
260
264
  - !ruby/object:Gem::Version
261
265
  version: '0'
262
266
  requirements: []
263
- rubygems_version: 3.2.15
267
+ rubygems_version: 3.2.22
264
268
  signing_key:
265
269
  specification_version: 4
266
270
  summary: A gem for interacting with the GeoIP2 webservices and databases.