maxmind-geoip2 1.1.0 → 1.2.0

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.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/README.md +10 -5
  4. data/lib/maxmind/geoip2/client.rb +18 -9
  5. data/lib/maxmind/geoip2/model/city.rb +4 -5
  6. data/lib/maxmind/geoip2/model/connection_type.rb +3 -2
  7. data/lib/maxmind/geoip2/model/enterprise.rb +2 -3
  8. data/lib/maxmind/geoip2/model/insights.rb +3 -5
  9. data/lib/maxmind/geoip2/record/traits.rb +39 -27
  10. data/lib/maxmind/geoip2/version.rb +8 -0
  11. data/maxmind-geoip2.gemspec +7 -2
  12. data/test/data/cmd/write-test-data/main.go +68 -0
  13. data/test/data/go.mod +13 -0
  14. data/test/data/go.sum +16 -0
  15. data/test/data/perltidyrc +6 -0
  16. data/test/data/pkg/writer/decoder.go +178 -0
  17. data/test/data/pkg/writer/geoip2.go +182 -0
  18. data/test/data/pkg/writer/ip.go +39 -0
  19. data/test/data/pkg/writer/maxmind.go +245 -0
  20. data/test/data/pkg/writer/nestedstructures.go +73 -0
  21. data/test/data/pkg/writer/writer.go +58 -0
  22. data/test/data/source-data/GeoIP2-City-Test.json +322 -1
  23. data/test/data/source-data/GeoIP2-Connection-Type-Test.json +15 -10
  24. data/test/data/source-data/GeoIP2-Country-Test.json +99 -0
  25. data/test/data/source-data/GeoIP2-Domain-Test.json +5 -0
  26. data/test/data/source-data/GeoIP2-Enterprise-Test.json +347 -1
  27. data/test/data/source-data/GeoIP2-Precision-Enterprise-Sandbox-Test.json +296 -0
  28. data/test/data/source-data/GeoIP2-Precision-Enterprise-Test.json +412 -2
  29. data/test/data/source-data/GeoIP2-Static-IP-Score-Test.json +15 -0
  30. data/test/data/source-data/GeoIP2-User-Count-Test.json +18 -0
  31. data/test/data/source-data/GeoLite2-City-Test.json +168 -0
  32. data/test/data/source-data/GeoLite2-Country-Test.json +92 -0
  33. data/test/data/test-data/GeoIP2-Anonymous-IP-Test.mmdb +0 -0
  34. data/test/data/test-data/GeoIP2-City-Test-Broken-Double-Format.mmdb +0 -0
  35. data/test/data/test-data/GeoIP2-City-Test-Invalid-Node-Count.mmdb +0 -0
  36. data/test/data/test-data/GeoIP2-City-Test.mmdb +0 -0
  37. data/test/data/test-data/GeoIP2-Connection-Type-Test.mmdb +0 -0
  38. data/test/data/test-data/GeoIP2-Country-Test.mmdb +0 -0
  39. data/test/data/test-data/GeoIP2-DensityIncome-Test.mmdb +0 -0
  40. data/test/data/test-data/GeoIP2-Domain-Test.mmdb +0 -0
  41. data/test/data/test-data/GeoIP2-Enterprise-Test.mmdb +0 -0
  42. data/test/data/test-data/GeoIP2-ISP-Test.mmdb +0 -0
  43. data/test/data/test-data/GeoIP2-Precision-Enterprise-Test.mmdb +0 -0
  44. data/test/data/test-data/GeoIP2-Static-IP-Score-Test.mmdb +0 -0
  45. data/test/data/test-data/GeoIP2-User-Count-Test.mmdb +0 -0
  46. data/test/data/test-data/GeoLite2-ASN-Test.mmdb +0 -0
  47. data/test/data/test-data/GeoLite2-City-Test.mmdb +0 -0
  48. data/test/data/test-data/GeoLite2-Country-Test.mmdb +0 -0
  49. data/test/data/test-data/MaxMind-DB-no-ipv4-search-tree.mmdb +0 -0
  50. data/test/data/test-data/MaxMind-DB-string-value-entries.mmdb +0 -0
  51. data/test/data/test-data/MaxMind-DB-test-broken-pointers-24.mmdb +0 -0
  52. data/test/data/test-data/MaxMind-DB-test-broken-search-tree-24.mmdb +0 -0
  53. data/test/data/test-data/MaxMind-DB-test-decoder.mmdb +0 -0
  54. data/test/data/test-data/MaxMind-DB-test-ipv4-24.mmdb +0 -0
  55. data/test/data/test-data/MaxMind-DB-test-ipv4-28.mmdb +0 -0
  56. data/test/data/test-data/MaxMind-DB-test-ipv4-32.mmdb +0 -0
  57. data/test/data/test-data/MaxMind-DB-test-ipv6-24.mmdb +0 -0
  58. data/test/data/test-data/MaxMind-DB-test-ipv6-28.mmdb +0 -0
  59. data/test/data/test-data/MaxMind-DB-test-ipv6-32.mmdb +0 -0
  60. data/test/data/test-data/MaxMind-DB-test-metadata-pointers.mmdb +0 -0
  61. data/test/data/test-data/MaxMind-DB-test-mixed-24.mmdb +0 -0
  62. data/test/data/test-data/MaxMind-DB-test-mixed-28.mmdb +0 -0
  63. data/test/data/test-data/MaxMind-DB-test-mixed-32.mmdb +0 -0
  64. data/test/data/test-data/MaxMind-DB-test-nested.mmdb +0 -0
  65. data/test/data/test-data/MaxMind-DB-test-pointer-decoder.mmdb +0 -0
  66. data/test/data/test-data/README.md +28 -12
  67. data/test/test_client.rb +18 -2
  68. data/test/test_reader.rb +19 -1
  69. metadata +16 -7
  70. data/test/data/source-data/README +0 -15
  71. data/test/data/test-data/write-test-data.pl +0 -695
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2bdd199c61f9c7116b023d420f1fb0763d05abd7711dd7be0f177113028140ff
4
- data.tar.gz: 00a081df1adc640dff12ef5fb8670ac9714b9edd1ef3fa65049033a1fa9d385b
3
+ metadata.gz: 9c1d04d352a8344e1e8d9c232ab7713bc0b74ddaa1e4a82aec61dbbf37bfd925
4
+ data.tar.gz: 20bcee370b35a4e098b48b36146eb7da9674f6c271ba94744a435addbd9c5e05
5
5
  SHA512:
6
- metadata.gz: 85a980183be16fa99909d42db32d295ff68a8c718cb31384aef78db8fb287a970d148d12c112fbb9c3cde0a84d396a438a9faf7c196b3e2bfadce93695ebf8e4
7
- data.tar.gz: 3ef1e40dd82bbf1acf3ddb14b1d774c246c78219463a00b87bfa46c14af7b623ccdfb9af5046c3a1d0b0b8b18fbe4f575d88d28d9930f3b10913c0035326a611
6
+ metadata.gz: 0331f1fe319379d035bd4f8675f775bbe31f0d3747d2f9a65754523cb6718160237d5a232d54cad7cd00cdcfe5243ff0f8a39276d749948116fc974221eb3d8a
7
+ data.tar.gz: 1d3e2f6c9a5847671b4b86004c7407bacf25cb271674d7dd49c5217b15d20a307ba416ec19a5f04d2050925ee689a97f01ca899f2edcb611bb44c5ee1a13ba35
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.0 (2023-12-04)
4
+
5
+ * `MaxMind::GeoIP2::Client` now validates the IP address before making a
6
+ request to the web service.
7
+ * `MaxMind::GeoIP2::Client` now includes the version of Ruby, the version
8
+ of the HTTP client library, and its own version in the User-Agent header.
9
+ * The `anycast?` method was added to `MaxMind::GeoIP2::Record::Traits`.
10
+ This returns `true` if the IP address belongs to an [anycast
11
+ network](https://en.wikipedia.org/wiki/Anycast). This is available for
12
+ the GeoIP2 Country, City Plus, and Insights web services and the GeoIP2
13
+ Country, City, and Enterprise databases.
14
+
3
15
  ## 1.1.0 (2021-11-18)
4
16
 
5
17
  * Exceptions from this gem now inherit from `MaxMind::GeoIP2::Error`. IP
data/README.md CHANGED
@@ -228,14 +228,19 @@ client = MaxMind::GeoIP2::Client.new(
228
228
  account_id: 42,
229
229
  license_key: 'license_key',
230
230
 
231
- # To use the GeoLite2 web service instead of GeoIP2 Precision, set
231
+ # To use the GeoLite2 web service instead of the GeoIP2 web service, set
232
232
  # the host parameter to "geolite.info":
233
233
  # host: 'geolite.info',
234
+
235
+ # To use the Sandbox GeoIP2 web service instead of the production GeoIP2
236
+ # web service, set the host parameter to "sandbox.maxmind.com":
237
+ # host: 'sandbox.maxmind.com',
234
238
  )
235
239
 
236
240
  # Replace "city" with the method corresponding to the web service that
237
241
  # you are using, e.g., "country", "insights". Please note that Insights
238
- # is only supported by GeoIP2 Precision and not the GeoLite2 web service.
242
+ # is only supported by the GeoIP2 web service and not the GeoLite2 web
243
+ # service.
239
244
  record = client.city('128.101.101.101')
240
245
 
241
246
  puts record.country.iso_code # US
@@ -279,8 +284,8 @@ which can be populated vary between end points. In addition, while an end
279
284
  point may offer a particular piece of data, MaxMind does not always have
280
285
  every piece of data for any given IP address.
281
286
 
282
- See the [GeoIP2 Precision web service
283
- docs](https://dev.maxmind.com/geoip/docs/web-services?lang=en) for details on
287
+ See the [GeoIP2 web service
288
+ documentation](https://dev.maxmind.com/geoip/docs/web-services?lang=en) for details on
284
289
  what data each end point may return.
285
290
 
286
291
  The only piece of data which is always returned is the `ip_address`
@@ -340,7 +345,7 @@ This library uses [Semantic Versioning](https://semver.org/).
340
345
 
341
346
  ## Copyright and License
342
347
 
343
- This software is Copyright (c) 2020-2021 by MaxMind, Inc.
348
+ This software is Copyright (c) 2020-2023 by MaxMind, Inc.
344
349
 
345
350
  This is free software, licensed under the [Apache License, Version
346
351
  2.0](LICENSE-APACHE) or the [MIT License](LICENSE-MIT), at your option.
@@ -4,15 +4,17 @@ require 'connection_pool'
4
4
  require 'http'
5
5
  require 'json'
6
6
  require 'maxmind/geoip2/errors'
7
+ require 'maxmind/geoip2/version'
7
8
  require 'maxmind/geoip2/model/city'
8
9
  require 'maxmind/geoip2/model/country'
9
10
  require 'maxmind/geoip2/model/insights'
11
+ require 'resolv'
10
12
 
11
13
  module MaxMind
12
14
  module GeoIP2
13
15
  # This class provides a client API for all the
14
- # {https://dev.maxmind.com/geoip/docs/web-services?lang=en GeoIP2 Precision web
15
- # services}. The services are Country, City, and Insights. Each service
16
+ # {https://dev.maxmind.com/geoip/docs/web-services?lang=en GeoIP2 web
17
+ # services}. The services are Country, City Plus, and Insights. Each service
16
18
  # returns a different set of data about an IP address, with Country returning
17
19
  # the least data and Insights the most.
18
20
  #
@@ -58,7 +60,7 @@ module MaxMind
58
60
  # rubocop:disable Metrics/CyclomaticComplexity
59
61
  # rubocop:disable Metrics/PerceivedComplexity
60
62
 
61
- # Create a Client that may be used to query a GeoIP2 Precision web service.
63
+ # Create a Client that may be used to query a GeoIP2 web service.
62
64
  #
63
65
  # Once created, the Client is safe to use for lookups from multiple
64
66
  # threads.
@@ -71,8 +73,10 @@ module MaxMind
71
73
  # property from most preferred to least preferred.
72
74
  #
73
75
  # @param host [String] the host to use when querying the web service. Set
74
- # this to "geolite.info" to use the GeoLite2 web service instead of
75
- # GeoIP2 Precision.
76
+ # this to "geolite.info" to use the GeoLite2 web service instead of the
77
+ # GeoIP2 web service. Set this to "sandbox.maxmind.com" to use the
78
+ # Sandbox environment. The sandbox allows you to experiment with the
79
+ # API without affecting your production data.
76
80
  #
77
81
  # @param timeout [Integer] the number of seconds to wait for a request
78
82
  # before timing out. If 0, no timeout is set.
@@ -117,7 +121,7 @@ module MaxMind
117
121
  # rubocop:enable Metrics/CyclomaticComplexity
118
122
  # rubocop:enable Metrics/ParameterLists
119
123
 
120
- # This method calls the City web service.
124
+ # This method calls the City Plus web service.
121
125
  #
122
126
  # @param ip_address [String] IPv4 or IPv6 address as a string. If no
123
127
  # address is provided, the address that the web service is called from is
@@ -193,8 +197,8 @@ module MaxMind
193
197
 
194
198
  # This method calls the Insights web service.
195
199
  #
196
- # Insights is only supported by the GeoIP2 Precision web service. The
197
- # GeoLite2 web service does not support it.
200
+ # Insights is only supported by the GeoIP2 web service. The GeoLite2 web
201
+ # service does not support it.
198
202
  #
199
203
  # @param ip_address [String] IPv4 or IPv6 address as a string. If no
200
204
  # address is provided, the address that the web service is called from is
@@ -234,6 +238,10 @@ module MaxMind
234
238
  private
235
239
 
236
240
  def response_for(endpoint, model_class, ip_address)
241
+ if ip_address != 'me' && ip_address !~ Resolv::AddressRegex
242
+ raise AddressInvalidError, "The value \"#{ip_address}\" is not a valid IP address"
243
+ end
244
+
237
245
  record = get(endpoint, ip_address)
238
246
 
239
247
  model_class.new(record, @locales)
@@ -243,8 +251,9 @@ module MaxMind
243
251
  headers = HTTP.basic_auth(user: @account_id, pass: @license_key)
244
252
  .headers(
245
253
  accept: 'application/json',
246
- user_agent: 'MaxMind-GeoIP2-ruby',
254
+ user_agent: "MaxMind-GeoIP2-ruby/#{VERSION} ruby/#{RUBY_VERSION} http/#{HTTP::VERSION}"
247
255
  )
256
+
248
257
  timeout = @timeout > 0 ? headers.timeout(@timeout) : headers
249
258
 
250
259
  proxy = timeout
@@ -9,12 +9,11 @@ require 'maxmind/geoip2/record/subdivision'
9
9
  module MaxMind
10
10
  module GeoIP2
11
11
  module Model
12
- # Model class for the data returned by the GeoIP2 City web service and
13
- # database. It is also used for GeoLite2 City lookups.
12
+ # Model class for the data returned by the GeoIP2 City Plus web service
13
+ # and the City database. It is also used for GeoLite2 City lookups.
14
14
  #
15
- # The only difference between the City and Insights model classes is which
16
- # fields in each record may be populated. See
17
- # https://dev.maxmind.com/geoip/docs/web-services?lang=en for more details.
15
+ # See https://dev.maxmind.com/geoip/docs/web-services?lang=en for more
16
+ # details.
18
17
  #
19
18
  # See {MaxMind::GeoIP2::Model::Country} for inherited methods.
20
19
  class City < Country
@@ -7,8 +7,9 @@ module MaxMind
7
7
  module Model
8
8
  # Model class for the GeoIP2 Connection Type database.
9
9
  class ConnectionType < Abstract
10
- # The connection type may take the following values: "Dialup", "Cable/DSL",
11
- # "Corporate", "Cellular". Additional values may be added in the future.
10
+ # The connection type may take the following values: "Dialup",
11
+ # "Cable/DSL", "Corporate", "Cellular", and "Satellite". Additional
12
+ # values may be added in the future.
12
13
  #
13
14
  # @return [String, nil]
14
15
  def connection_type
@@ -7,9 +7,8 @@ module MaxMind
7
7
  module Model
8
8
  # Model class for the data returned by GeoIP2 Enterprise database lookups.
9
9
  #
10
- # The only difference between the City and Insights model classes is which
11
- # fields in each record may be populated. See
12
- # https://dev.maxmind.com/geoip/docs/web-services?lang=en for more details.
10
+ # See https://dev.maxmind.com/geoip/docs/web-services?lang=en for more
11
+ # details.
13
12
  #
14
13
  # See {MaxMind::GeoIP2::Model::City} for inherited methods.
15
14
  class Enterprise < City
@@ -5,12 +5,10 @@ require 'maxmind/geoip2/model/city'
5
5
  module MaxMind
6
6
  module GeoIP2
7
7
  module Model
8
- # Model class for the data returned by the GeoIP2 Precision Insights web
9
- # service.
8
+ # Model class for the data returned by the GeoIP2 Insights web service.
10
9
  #
11
- # The only difference between the City and Insights model classes is which
12
- # fields in each record may be populated. See
13
- # https://dev.maxmind.com/geoip/docs/web-services?lang=en for more details.
10
+ # See https://dev.maxmind.com/geoip/docs/web-services?lang=en for more
11
+ # details.
14
12
  class Insights < City
15
13
  end
16
14
  end
@@ -22,8 +22,8 @@ module MaxMind
22
22
 
23
23
  # The autonomous system number associated with the IP address. See
24
24
  # Wikipedia[https://en.wikipedia.org/wiki/Autonomous_system_(Internet)].
25
- # This attribute is only available from the City and Insights web service
26
- # and the GeoIP2 Enterprise database.
25
+ # This attribute is only available from the City Plus and Insights web
26
+ # services and the Enterprise database.
27
27
  #
28
28
  # @return [Integer, nil]
29
29
  def autonomous_system_number
@@ -33,8 +33,8 @@ module MaxMind
33
33
  # The organization associated with the registered autonomous system number
34
34
  # for the IP address. See
35
35
  # Wikipedia[https://en.wikipedia.org/wiki/Autonomous_system_(Internet)].
36
- # This attribute is only available from the City and Insights web service
37
- # and the GeoIP2 Enterprise database.
36
+ # This attribute is only available from the City Plus and Insights web
37
+ # services and the Enterprise database.
38
38
  #
39
39
  # @return [String, nil]
40
40
  def autonomous_system_organization
@@ -42,8 +42,9 @@ module MaxMind
42
42
  end
43
43
 
44
44
  # The connection type may take the following values: "Dialup",
45
- # "Cable/DSL", "Corporate", "Cellular". Additional values may be added in
46
- # the future. This attribute is only available in the GeoIP2 Enterprise
45
+ # "Cable/DSL", "Corporate", "Cellular", and "Satellite". Additional
46
+ # values may be added in the future. This attribute is only available
47
+ # from the City Plus and Insights web services and the Enterprise
47
48
  # database.
48
49
  #
49
50
  # @return [String, nil]
@@ -53,8 +54,8 @@ module MaxMind
53
54
 
54
55
  # The second level domain associated with the IP address. This will be
55
56
  # something like "example.com" or "example.co.uk", not "foo.example.com".
56
- # This attribute is only available from the City and Insights web service
57
- # and the GeoIP2 Enterprise database.
57
+ # This attribute is only available from the City Plus and Insights web
58
+ # services and the Enterprise database.
58
59
  #
59
60
  # @return [String, nil]
60
61
  def domain
@@ -73,7 +74,7 @@ module MaxMind
73
74
  end
74
75
 
75
76
  # This is true if the IP address belongs to any sort of anonymous network.
76
- # This property is only available from GeoIP2 Precision Insights.
77
+ # This property is only available from Insights.
77
78
  #
78
79
  # @return [Boolean]
79
80
  def anonymous?
@@ -83,17 +84,28 @@ module MaxMind
83
84
  # This is true if the IP address is registered to an anonymous VPN
84
85
  # provider. If a VPN provider does not register subnets under names
85
86
  # associated with them, we will likely only flag their IP ranges using the
86
- # hosting_provider? property. This property is only available from GeoIP2
87
- # Precision Insights.
87
+ # hosting_provider? property. This property is only available from Insights.
88
88
  #
89
89
  # @return [Boolean]
90
90
  def anonymous_vpn?
91
91
  get('is_anonymous_vpn')
92
92
  end
93
93
 
94
+ # This is true if the IP address belongs to an
95
+ # {https://en.wikipedia.org/wiki/Anycast anycast network}.
96
+ #
97
+ # This property is only available from the Country, City Plus, and
98
+ # Insights web services and the GeoIP2 Country, City, and Enterprise
99
+ # databases.
100
+ #
101
+ # @return [Boolean]
102
+ def anycast?
103
+ get('is_anycast')
104
+ end
105
+
94
106
  # This is true if the IP address belongs to a hosting or VPN provider (see
95
107
  # description of the anonymous_vpn? property). This property is only
96
- # available from GeoIP2 Precision Insights.
108
+ # available from Insights.
97
109
  #
98
110
  # @return [Boolean]
99
111
  def hosting_provider?
@@ -102,7 +114,7 @@ module MaxMind
102
114
 
103
115
  # This attribute is true if MaxMind believes this IP address to be a
104
116
  # legitimate proxy, such as an internal VPN used by a corporation. This
105
- # attribute is only available in the GeoIP2 Enterprise database.
117
+ # attribute is only available in the Enterprise database.
106
118
  #
107
119
  # @return [Boolean]
108
120
  def legitimate_proxy?
@@ -112,8 +124,8 @@ module MaxMind
112
124
  # The {https://en.wikipedia.org/wiki/Mobile_country_code mobile country
113
125
  # code (MCC)} associated with the IP address and ISP.
114
126
  #
115
- # This attribute is only available from the City and Insights web service
116
- # and the GeoIP2 Enterprise database.
127
+ # This attribute is only available from the City Plus and Insights web
128
+ # services and the Enterprise database.
117
129
  #
118
130
  # @return [String, nil]
119
131
  def mobile_country_code
@@ -123,8 +135,8 @@ module MaxMind
123
135
  # The {https://en.wikipedia.org/wiki/Mobile_country_code mobile network
124
136
  # code (MNC)} associated with the IP address and ISP.
125
137
  #
126
- # This attribute is only available from the City and Insights web service
127
- # and the GeoIP2 Enterprise database.
138
+ # This attribute is only available from the City Plus and Insights web
139
+ # services and the Enterprise database.
128
140
  #
129
141
  # @return [String, nil]
130
142
  def mobile_network_code
@@ -132,7 +144,7 @@ module MaxMind
132
144
  end
133
145
 
134
146
  # This is true if the IP address belongs to a public proxy. This property
135
- # is only available from GeoIP2 Precision Insights.
147
+ # is only available from Insights.
136
148
  #
137
149
  # @return [Boolean]
138
150
  def public_proxy?
@@ -141,7 +153,7 @@ module MaxMind
141
153
 
142
154
  # This is true if the IP address is on a suspected anonymizing network
143
155
  # and belongs to a residential ISP. This property is only available
144
- # from GeoIP2 Precision Insights.
156
+ # from Insights.
145
157
  #
146
158
  # @return [Boolean]
147
159
  def residential_proxy?
@@ -149,7 +161,7 @@ module MaxMind
149
161
  end
150
162
 
151
163
  # This is true if the IP address is a Tor exit node. This property is only
152
- # available from GeoIP2 Precision Insights.
164
+ # available from Insights.
153
165
  #
154
166
  # @return [Boolean]
155
167
  def tor_exit_node?
@@ -157,7 +169,7 @@ module MaxMind
157
169
  end
158
170
 
159
171
  # The name of the ISP associated with the IP address. This attribute is
160
- # only available from the City and Insights web services and the GeoIP2
172
+ # only available from the City Plus and Insights web services and the
161
173
  # Enterprise database.
162
174
  #
163
175
  # @return [String, nil]
@@ -175,8 +187,8 @@ module MaxMind
175
187
  end
176
188
 
177
189
  # The name of the organization associated with the IP address. This
178
- # attribute is only available from the City and Insights web services and
179
- # the GeoIP2 Enterprise database.
190
+ # attribute is only available from the City Plus and Insights web services
191
+ # and the Enterprise database.
180
192
  #
181
193
  # @return [String, nil]
182
194
  def organization
@@ -184,7 +196,7 @@ module MaxMind
184
196
  end
185
197
 
186
198
  # An indicator of how static or dynamic an IP address is. This property is
187
- # only available from GeoIP2 Precision Insights.
199
+ # only available from Insights.
188
200
  #
189
201
  # @return [Float, nil]
190
202
  def static_ip_score
@@ -193,8 +205,7 @@ module MaxMind
193
205
 
194
206
  # The estimated number of users sharing the IP/network during the past 24
195
207
  # hours. For IPv4, the count is for the individual IP. For IPv6, the count
196
- # is for the /64 network. This property is only available from GeoIP2
197
- # Precision Insights.
208
+ # is for the /64 network. This property is only available from Insights.
198
209
  #
199
210
  # @return [Integer, nil]
200
211
  def user_count
@@ -208,6 +219,7 @@ module MaxMind
208
219
  # * cafe
209
220
  # * cellular
210
221
  # * college
222
+ # * consumer_privacy_network
211
223
  # * content_delivery_network
212
224
  # * dialup
213
225
  # * government
@@ -221,7 +233,7 @@ module MaxMind
221
233
  # * traveler
222
234
  #
223
235
  # This attribute is only available from the Insights web service and the
224
- # GeoIP2 Enterprise database.
236
+ # Enterprise database.
225
237
  #
226
238
  # @return [String, nil]
227
239
  def user_type
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MaxMind
4
+ module GeoIP2
5
+ # The Gem version.
6
+ VERSION = '1.2.0'
7
+ end
8
+ end
@@ -1,11 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require 'maxmind/geoip2/version'
7
+
3
8
  Gem::Specification.new do |s|
4
9
  s.authors = ['William Storey']
5
10
  s.files = Dir['**/*']
6
11
  s.name = 'maxmind-geoip2'
7
12
  s.summary = 'A gem for interacting with the GeoIP2 webservices and databases.'
8
- s.version = '1.1.0'
13
+ s.version = MaxMind::GeoIP2::VERSION
9
14
 
10
15
  s.description = 'A gem for interacting with the GeoIP2 webservices and databases. MaxMind provides geolocation data as downloadable databases as well as through a webservice.'
11
16
  s.email = 'support@maxmind.com'
@@ -23,7 +28,7 @@ Gem::Specification.new do |s|
23
28
 
24
29
  s.add_runtime_dependency 'connection_pool', ['~> 2.2']
25
30
  s.add_runtime_dependency 'http', '>= 4.3', '< 6.0'
26
- s.add_runtime_dependency 'maxmind-db', ['~> 1.1']
31
+ s.add_runtime_dependency 'maxmind-db', ['~> 1.2']
27
32
 
28
33
  s.add_development_dependency 'minitest'
29
34
  s.add_development_dependency 'rake'
@@ -0,0 +1,68 @@
1
+ // write-test-data generates test mmdb files.
2
+ package main
3
+
4
+ import (
5
+ "flag"
6
+ "fmt"
7
+ "os"
8
+
9
+ "github.com/maxmind/MaxMind-DB/pkg/writer"
10
+ )
11
+
12
+ func main() {
13
+ source := flag.String("source", "", "Source data directory")
14
+ target := flag.String("target", "", "Destination directory for the generated mmdb files")
15
+
16
+ flag.Parse()
17
+
18
+ w, err := writer.New(*source, *target)
19
+ if err != nil {
20
+ fmt.Printf("creating writer: %+v\n", err)
21
+ os.Exit(1)
22
+ }
23
+
24
+ if err := w.WriteIPv4TestDB(); err != nil {
25
+ fmt.Printf("writing IPv4 test databases: %+v\n", err)
26
+ os.Exit(1)
27
+ }
28
+
29
+ if err := w.WriteIPv6TestDB(); err != nil {
30
+ fmt.Printf("writing IPv6 test databases: %+v\n", err)
31
+ os.Exit(1)
32
+ }
33
+
34
+ if err := w.WriteMixedIPTestDB(); err != nil {
35
+ fmt.Printf("writing IPv6 test databases: %+v\n", err)
36
+ os.Exit(1)
37
+ }
38
+
39
+ if err := w.WriteNoIPv4TestDB(); err != nil {
40
+ fmt.Printf("writing no IPv4 test databases: %+v\n", err)
41
+ os.Exit(1)
42
+ }
43
+
44
+ if err := w.WriteNoMapTestDB(); err != nil {
45
+ fmt.Printf("writing no map test databases: %+v\n", err)
46
+ os.Exit(1)
47
+ }
48
+
49
+ if err := w.WriteMetadataPointersTestDB(); err != nil {
50
+ fmt.Printf("writing metadata pointers test databases: %+v\n", err)
51
+ os.Exit(1)
52
+ }
53
+
54
+ if err := w.WriteDecoderTestDB(); err != nil {
55
+ fmt.Printf("writing decoder test databases: %+v\n", err)
56
+ os.Exit(1)
57
+ }
58
+
59
+ if err := w.WriteDeeplyNestedStructuresTestDB(); err != nil {
60
+ fmt.Printf("writing decoder test databases: %+v\n", err)
61
+ os.Exit(1)
62
+ }
63
+
64
+ if err := w.WriteGeoIP2TestDB(); err != nil {
65
+ fmt.Printf("writing GeoIP2 test databases: %+v\n", err)
66
+ os.Exit(1)
67
+ }
68
+ }
data/test/data/go.mod ADDED
@@ -0,0 +1,13 @@
1
+ module github.com/maxmind/MaxMind-DB
2
+
3
+ go 1.21
4
+
5
+ require (
6
+ github.com/maxmind/mmdbwriter v1.0.0
7
+ go4.org/netipx v0.0.0-20230824141953-6213f710f925
8
+ )
9
+
10
+ require (
11
+ github.com/oschwald/maxminddb-golang v1.12.0 // indirect
12
+ golang.org/x/sys v0.10.0 // indirect
13
+ )
data/test/data/go.sum ADDED
@@ -0,0 +1,16 @@
1
+ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2
+ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3
+ github.com/maxmind/mmdbwriter v1.0.0 h1:bieL4P6yaYaHvbtLSwnKtEvScUKKD6jcKaLiTM3WSMw=
4
+ github.com/maxmind/mmdbwriter v1.0.0/go.mod h1:noBMCUtyN5PUQ4H8ikkOvGSHhzhLok51fON2hcrpKj8=
5
+ github.com/oschwald/maxminddb-golang v1.12.0 h1:9FnTOD0YOhP7DGxGsq4glzpGy5+w7pq50AS6wALUMYs=
6
+ github.com/oschwald/maxminddb-golang v1.12.0/go.mod h1:q0Nob5lTCqyQ8WT6FYgS1L7PXKVVbgiymefNwIjPzgY=
7
+ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
8
+ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
9
+ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
10
+ github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
11
+ go4.org/netipx v0.0.0-20230824141953-6213f710f925 h1:eeQDDVKFkx0g4Hyy8pHgmZaK0EqB4SD6rvKbUdN3ziQ=
12
+ go4.org/netipx v0.0.0-20230824141953-6213f710f925/go.mod h1:PLyyIXexvUFg3Owu6p/WfdlivPbZJsZdgWZlrGope/Y=
13
+ golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
14
+ golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
15
+ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
16
+ gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
data/test/data/perltidyrc CHANGED
@@ -1,6 +1,7 @@
1
1
  --blank-lines-before-packages=0
2
2
  --iterations=2
3
3
  --no-outdent-long-comments
4
+ --weld-nested-containers
4
5
  -b
5
6
  -bar
6
7
  -boc
@@ -10,3 +11,8 @@
10
11
  -nolq
11
12
  -se
12
13
  -wbb="% + - * / x != == >= <= =~ !~ < > | & >= < = **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= x="
14
+ --character-encoding=utf8
15
+ --valign-exclusion-list="q"
16
+ --want-trailing-commas=m
17
+ --add-trailing-commas
18
+ --delete-repeated-commas