maxmind-geoip2 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +7 -0
  3. data/Gemfile.lock +5 -3
  4. data/README.md +69 -0
  5. data/lib/maxmind/geoip2.rb +0 -13
  6. data/lib/maxmind/geoip2/model/abstract.rb +27 -0
  7. data/lib/maxmind/geoip2/model/anonymous_ip.rb +63 -0
  8. data/lib/maxmind/geoip2/model/asn.rb +39 -0
  9. data/lib/maxmind/geoip2/model/city.rb +28 -13
  10. data/lib/maxmind/geoip2/model/connection_type.rb +32 -0
  11. data/lib/maxmind/geoip2/model/country.rb +17 -9
  12. data/lib/maxmind/geoip2/model/domain.rb +32 -0
  13. data/lib/maxmind/geoip2/model/enterprise.rb +1 -1
  14. data/lib/maxmind/geoip2/model/isp.rb +53 -0
  15. data/lib/maxmind/geoip2/reader.rb +176 -59
  16. data/lib/maxmind/geoip2/record/abstract.rb +2 -1
  17. data/lib/maxmind/geoip2/record/city.rb +11 -6
  18. data/lib/maxmind/geoip2/record/continent.rb +11 -6
  19. data/lib/maxmind/geoip2/record/country.rb +17 -8
  20. data/lib/maxmind/geoip2/record/location.rb +18 -8
  21. data/lib/maxmind/geoip2/record/place.rb +5 -3
  22. data/lib/maxmind/geoip2/record/postal.rb +6 -2
  23. data/lib/maxmind/geoip2/record/represented_country.rb +4 -2
  24. data/lib/maxmind/geoip2/record/subdivision.rb +14 -10
  25. data/lib/maxmind/geoip2/record/traits.rb +52 -21
  26. data/maxmind-geoip2.gemspec +3 -1
  27. data/test/data/LICENSE +4 -0
  28. data/test/data/MaxMind-DB-spec.md +570 -0
  29. data/test/data/MaxMind-DB-test-metadata-pointers.mmdb +0 -0
  30. data/test/data/README.md +4 -0
  31. data/test/data/bad-data/README.md +7 -0
  32. data/test/data/bad-data/libmaxminddb/libmaxminddb-offset-integer-overflow.mmdb +0 -0
  33. data/test/data/bad-data/maxminddb-golang/cyclic-data-structure.mmdb +0 -0
  34. data/test/data/bad-data/maxminddb-golang/invalid-bytes-length.mmdb +1 -0
  35. data/test/data/bad-data/maxminddb-golang/invalid-data-record-offset.mmdb +0 -0
  36. data/test/data/bad-data/maxminddb-golang/invalid-map-key-length.mmdb +0 -0
  37. data/test/data/bad-data/maxminddb-golang/invalid-string-length.mmdb +1 -0
  38. data/test/data/bad-data/maxminddb-golang/metadata-is-an-uint128.mmdb +1 -0
  39. data/test/data/bad-data/maxminddb-golang/unexpected-bytes.mmdb +0 -0
  40. data/test/data/perltidyrc +12 -0
  41. data/test/data/source-data/GeoIP2-Anonymous-IP-Test.json +48 -0
  42. data/test/data/source-data/GeoIP2-City-Test.json +12852 -0
  43. data/test/data/source-data/GeoIP2-Connection-Type-Test.json +102 -0
  44. data/test/data/source-data/GeoIP2-Country-Test.json +15916 -0
  45. data/test/data/source-data/GeoIP2-DensityIncome-Test.json +14 -0
  46. data/test/data/source-data/GeoIP2-Domain-Test.json +452 -0
  47. data/test/data/source-data/GeoIP2-Enterprise-Test.json +687 -0
  48. data/test/data/source-data/GeoIP2-ISP-Test.json +12593 -0
  49. data/test/data/source-data/GeoIP2-Precision-Enterprise-Test.json +2061 -0
  50. data/test/data/source-data/GeoIP2-Static-IP-Score-Test.json +2132 -0
  51. data/test/data/source-data/GeoIP2-User-Count-Test.json +2837 -0
  52. data/test/data/source-data/GeoLite2-ASN-Test.json +37 -0
  53. data/test/data/source-data/README +15 -0
  54. data/test/data/test-data/GeoIP2-Anonymous-IP-Test.mmdb +0 -0
  55. data/test/data/test-data/GeoIP2-City-Test-Broken-Double-Format.mmdb +0 -0
  56. data/test/data/test-data/GeoIP2-City-Test-Invalid-Node-Count.mmdb +0 -0
  57. data/test/data/test-data/GeoIP2-City-Test.mmdb +0 -0
  58. data/test/data/test-data/GeoIP2-Connection-Type-Test.mmdb +0 -0
  59. data/test/data/test-data/GeoIP2-Country-Test.mmdb +0 -0
  60. data/test/data/test-data/GeoIP2-DensityIncome-Test.mmdb +0 -0
  61. data/test/data/test-data/GeoIP2-Domain-Test.mmdb +0 -0
  62. data/test/data/test-data/GeoIP2-Enterprise-Test.mmdb +0 -0
  63. data/test/data/test-data/GeoIP2-ISP-Test.mmdb +0 -0
  64. data/test/data/test-data/GeoIP2-Precision-Enterprise-Test.mmdb +0 -0
  65. data/test/data/test-data/GeoIP2-Static-IP-Score-Test.mmdb +0 -0
  66. data/test/data/test-data/GeoIP2-User-Count-Test.mmdb +0 -0
  67. data/test/data/test-data/GeoLite2-ASN-Test.mmdb +0 -0
  68. data/test/data/test-data/MaxMind-DB-no-ipv4-search-tree.mmdb +0 -0
  69. data/test/data/test-data/MaxMind-DB-string-value-entries.mmdb +0 -0
  70. data/test/data/test-data/MaxMind-DB-test-broken-pointers-24.mmdb +0 -0
  71. data/test/data/test-data/MaxMind-DB-test-broken-search-tree-24.mmdb +0 -0
  72. data/test/data/test-data/MaxMind-DB-test-decoder.mmdb +0 -0
  73. data/test/data/test-data/MaxMind-DB-test-ipv4-24.mmdb +0 -0
  74. data/test/data/test-data/MaxMind-DB-test-ipv4-28.mmdb +0 -0
  75. data/test/data/test-data/MaxMind-DB-test-ipv4-32.mmdb +0 -0
  76. data/test/data/test-data/MaxMind-DB-test-ipv6-24.mmdb +0 -0
  77. data/test/data/test-data/MaxMind-DB-test-ipv6-28.mmdb +0 -0
  78. data/test/data/test-data/MaxMind-DB-test-ipv6-32.mmdb +0 -0
  79. data/test/data/test-data/MaxMind-DB-test-metadata-pointers.mmdb +0 -0
  80. data/test/data/test-data/MaxMind-DB-test-mixed-24.mmdb +0 -0
  81. data/test/data/test-data/MaxMind-DB-test-mixed-28.mmdb +0 -0
  82. data/test/data/test-data/MaxMind-DB-test-mixed-32.mmdb +0 -0
  83. data/test/data/test-data/MaxMind-DB-test-nested.mmdb +0 -0
  84. data/test/data/test-data/README.md +26 -0
  85. data/test/data/test-data/maps-with-pointers.raw +0 -0
  86. data/test/data/test-data/write-test-data.pl +641 -0
  87. data/test/data/tidyall.ini +5 -0
  88. data/test/test_model_country.rb +1 -1
  89. data/test/test_model_names.rb +1 -1
  90. data/test/test_reader.rb +79 -1
  91. metadata +85 -4
@@ -0,0 +1,5 @@
1
+ [PerlTidy]
2
+ select = **/*.{pl,pm,t}
3
+
4
+ [JSON]
5
+ select = **/*.json
@@ -3,7 +3,7 @@
3
3
  require 'maxmind/geoip2'
4
4
  require 'minitest/autorun'
5
5
 
6
- class CountryModelTest < Minitest::Test # :nodoc:
6
+ class CountryModelTest < Minitest::Test
7
7
  RAW = {
8
8
  'continent' => {
9
9
  'code' => 'NA',
@@ -3,7 +3,7 @@
3
3
  require 'maxmind/geoip2'
4
4
  require 'minitest/autorun'
5
5
 
6
- class ModelNameTest < Minitest::Test # :nodoc:
6
+ class ModelNameTest < Minitest::Test
7
7
  RAW = {
8
8
  'continent' => {
9
9
  'code' => 'NA',
@@ -4,7 +4,40 @@ require 'ipaddr'
4
4
  require 'maxmind/geoip2'
5
5
  require 'minitest/autorun'
6
6
 
7
- class ReaderTest < Minitest::Test # :nodoc:
7
+ class ReaderTest < Minitest::Test
8
+ def test_anonymous_ip
9
+ reader = MaxMind::GeoIP2::Reader.new(
10
+ 'test/data/test-data/GeoIP2-Anonymous-IP-Test.mmdb',
11
+ )
12
+ ip = '1.2.0.1'
13
+ record = reader.anonymous_ip(ip)
14
+
15
+ assert_equal(true, record.anonymous?)
16
+ assert_equal(true, record.anonymous_vpn?)
17
+ assert_equal(false, record.hosting_provider?)
18
+ assert_equal(false, record.public_proxy?)
19
+ assert_equal(false, record.tor_exit_node?)
20
+ assert_equal(ip, record.ip_address)
21
+ assert_equal('1.2.0.0/16', record.network)
22
+
23
+ reader.close
24
+ end
25
+
26
+ def test_asn
27
+ reader = MaxMind::GeoIP2::Reader.new(
28
+ 'test/data/test-data/GeoLite2-ASN-Test.mmdb',
29
+ )
30
+ ip = '1.128.0.1'
31
+ record = reader.asn(ip)
32
+
33
+ assert_equal(1221, record.autonomous_system_number)
34
+ assert_equal('Telstra Pty Ltd', record.autonomous_system_organization)
35
+ assert_equal(ip, record.ip_address)
36
+ assert_equal('1.128.0.0/11', record.network)
37
+
38
+ reader.close
39
+ end
40
+
8
41
  def test_city
9
42
  reader = MaxMind::GeoIP2::Reader.new(
10
43
  'test/data/test-data/GeoIP2-City-Test.mmdb',
@@ -65,6 +98,20 @@ class ReaderTest < Minitest::Test # :nodoc:
65
98
  reader.close
66
99
  end
67
100
 
101
+ def test_connection_type
102
+ reader = MaxMind::GeoIP2::Reader.new(
103
+ 'test/data/test-data/GeoIP2-Connection-Type-Test.mmdb',
104
+ )
105
+ ip = '1.0.1.1'
106
+ record = reader.connection_type(ip)
107
+
108
+ assert_equal('Cable/DSL', record.connection_type)
109
+ assert_equal(ip, record.ip_address)
110
+ assert_equal('1.0.1.0/24', record.network)
111
+
112
+ reader.close
113
+ end
114
+
68
115
  def test_country
69
116
  reader = MaxMind::GeoIP2::Reader.new(
70
117
  'test/data/test-data/GeoIP2-Country-Test.mmdb',
@@ -162,6 +209,20 @@ class ReaderTest < Minitest::Test # :nodoc:
162
209
  reader.close
163
210
  end
164
211
 
212
+ def test_domain
213
+ reader = MaxMind::GeoIP2::Reader.new(
214
+ 'test/data/test-data/GeoIP2-Domain-Test.mmdb',
215
+ )
216
+ ip = '1.2.0.1'
217
+ record = reader.domain(ip)
218
+
219
+ assert_equal('maxmind.com', record.domain)
220
+ assert_equal(ip, record.ip_address)
221
+ assert_equal('1.2.0.0/16', record.network)
222
+
223
+ reader.close
224
+ end
225
+
165
226
  def test_enterprise
166
227
  reader = MaxMind::GeoIP2::Reader.new(
167
228
  'test/data/test-data/GeoIP2-Enterprise-Test.mmdb',
@@ -194,6 +255,23 @@ class ReaderTest < Minitest::Test # :nodoc:
194
255
  reader.close
195
256
  end
196
257
 
258
+ def test_isp
259
+ reader = MaxMind::GeoIP2::Reader.new(
260
+ 'test/data/test-data/GeoIP2-ISP-Test.mmdb',
261
+ )
262
+ ip = '1.128.1.1'
263
+ record = reader.isp(ip)
264
+
265
+ assert_equal(1221, record.autonomous_system_number)
266
+ assert_equal('Telstra Pty Ltd', record.autonomous_system_organization)
267
+ assert_equal('Telstra Internet', record.isp)
268
+ assert_equal('Telstra Internet', record.organization)
269
+ assert_equal(ip, record.ip_address)
270
+ assert_equal('1.128.0.0/11', record.network)
271
+
272
+ reader.close
273
+ end
274
+
197
275
  def test_no_traits
198
276
  reader = MaxMind::GeoIP2::Reader.new(
199
277
  'test/data/test-data/GeoIP2-Enterprise-Test.mmdb',
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maxmind-geoip2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.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: 2020-01-09 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2020-02-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: maxmind-db
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
13
27
  description: A gem for interacting with the GeoIP2 webservices and databases. MaxMind
14
28
  provides geolocation data as downloadable databases as well as through a webservice.
15
29
  email: support@maxmind.com
@@ -27,9 +41,15 @@ files:
27
41
  - Rakefile
28
42
  - lib/maxmind/geoip2.rb
29
43
  - lib/maxmind/geoip2/errors.rb
44
+ - lib/maxmind/geoip2/model/abstract.rb
45
+ - lib/maxmind/geoip2/model/anonymous_ip.rb
46
+ - lib/maxmind/geoip2/model/asn.rb
30
47
  - lib/maxmind/geoip2/model/city.rb
48
+ - lib/maxmind/geoip2/model/connection_type.rb
31
49
  - lib/maxmind/geoip2/model/country.rb
50
+ - lib/maxmind/geoip2/model/domain.rb
32
51
  - lib/maxmind/geoip2/model/enterprise.rb
52
+ - lib/maxmind/geoip2/model/isp.rb
33
53
  - lib/maxmind/geoip2/reader.rb
34
54
  - lib/maxmind/geoip2/record/abstract.rb
35
55
  - lib/maxmind/geoip2/record/city.rb
@@ -42,6 +62,67 @@ files:
42
62
  - lib/maxmind/geoip2/record/subdivision.rb
43
63
  - lib/maxmind/geoip2/record/traits.rb
44
64
  - maxmind-geoip2.gemspec
65
+ - test/data/LICENSE
66
+ - test/data/MaxMind-DB-spec.md
67
+ - test/data/MaxMind-DB-test-metadata-pointers.mmdb
68
+ - test/data/README.md
69
+ - test/data/bad-data/README.md
70
+ - test/data/bad-data/libmaxminddb/libmaxminddb-offset-integer-overflow.mmdb
71
+ - test/data/bad-data/maxminddb-golang/cyclic-data-structure.mmdb
72
+ - test/data/bad-data/maxminddb-golang/invalid-bytes-length.mmdb
73
+ - test/data/bad-data/maxminddb-golang/invalid-data-record-offset.mmdb
74
+ - test/data/bad-data/maxminddb-golang/invalid-map-key-length.mmdb
75
+ - test/data/bad-data/maxminddb-golang/invalid-string-length.mmdb
76
+ - test/data/bad-data/maxminddb-golang/metadata-is-an-uint128.mmdb
77
+ - test/data/bad-data/maxminddb-golang/unexpected-bytes.mmdb
78
+ - test/data/perltidyrc
79
+ - test/data/source-data/GeoIP2-Anonymous-IP-Test.json
80
+ - test/data/source-data/GeoIP2-City-Test.json
81
+ - test/data/source-data/GeoIP2-Connection-Type-Test.json
82
+ - test/data/source-data/GeoIP2-Country-Test.json
83
+ - test/data/source-data/GeoIP2-DensityIncome-Test.json
84
+ - test/data/source-data/GeoIP2-Domain-Test.json
85
+ - test/data/source-data/GeoIP2-Enterprise-Test.json
86
+ - test/data/source-data/GeoIP2-ISP-Test.json
87
+ - test/data/source-data/GeoIP2-Precision-Enterprise-Test.json
88
+ - test/data/source-data/GeoIP2-Static-IP-Score-Test.json
89
+ - test/data/source-data/GeoIP2-User-Count-Test.json
90
+ - test/data/source-data/GeoLite2-ASN-Test.json
91
+ - test/data/source-data/README
92
+ - test/data/test-data/GeoIP2-Anonymous-IP-Test.mmdb
93
+ - test/data/test-data/GeoIP2-City-Test-Broken-Double-Format.mmdb
94
+ - test/data/test-data/GeoIP2-City-Test-Invalid-Node-Count.mmdb
95
+ - test/data/test-data/GeoIP2-City-Test.mmdb
96
+ - test/data/test-data/GeoIP2-Connection-Type-Test.mmdb
97
+ - test/data/test-data/GeoIP2-Country-Test.mmdb
98
+ - test/data/test-data/GeoIP2-DensityIncome-Test.mmdb
99
+ - test/data/test-data/GeoIP2-Domain-Test.mmdb
100
+ - test/data/test-data/GeoIP2-Enterprise-Test.mmdb
101
+ - test/data/test-data/GeoIP2-ISP-Test.mmdb
102
+ - test/data/test-data/GeoIP2-Precision-Enterprise-Test.mmdb
103
+ - test/data/test-data/GeoIP2-Static-IP-Score-Test.mmdb
104
+ - test/data/test-data/GeoIP2-User-Count-Test.mmdb
105
+ - test/data/test-data/GeoLite2-ASN-Test.mmdb
106
+ - test/data/test-data/MaxMind-DB-no-ipv4-search-tree.mmdb
107
+ - test/data/test-data/MaxMind-DB-string-value-entries.mmdb
108
+ - test/data/test-data/MaxMind-DB-test-broken-pointers-24.mmdb
109
+ - test/data/test-data/MaxMind-DB-test-broken-search-tree-24.mmdb
110
+ - test/data/test-data/MaxMind-DB-test-decoder.mmdb
111
+ - test/data/test-data/MaxMind-DB-test-ipv4-24.mmdb
112
+ - test/data/test-data/MaxMind-DB-test-ipv4-28.mmdb
113
+ - test/data/test-data/MaxMind-DB-test-ipv4-32.mmdb
114
+ - test/data/test-data/MaxMind-DB-test-ipv6-24.mmdb
115
+ - test/data/test-data/MaxMind-DB-test-ipv6-28.mmdb
116
+ - test/data/test-data/MaxMind-DB-test-ipv6-32.mmdb
117
+ - test/data/test-data/MaxMind-DB-test-metadata-pointers.mmdb
118
+ - test/data/test-data/MaxMind-DB-test-mixed-24.mmdb
119
+ - test/data/test-data/MaxMind-DB-test-mixed-28.mmdb
120
+ - test/data/test-data/MaxMind-DB-test-mixed-32.mmdb
121
+ - test/data/test-data/MaxMind-DB-test-nested.mmdb
122
+ - test/data/test-data/README.md
123
+ - test/data/test-data/maps-with-pointers.raw
124
+ - test/data/test-data/write-test-data.pl
125
+ - test/data/tidyall.ini
45
126
  - test/test_model_country.rb
46
127
  - test/test_model_names.rb
47
128
  - test/test_reader.rb
@@ -71,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
152
  version: '0'
72
153
  requirements: []
73
154
  rubyforge_project:
74
- rubygems_version: 2.5.2.1
155
+ rubygems_version: 2.7.6
75
156
  signing_key:
76
157
  specification_version: 4
77
158
  summary: A gem for interacting with the GeoIP2 webservices and databases.