maxmind-geoip2 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +6 -0
  3. data/Gemfile.lock +3 -3
  4. data/lib/maxmind/geoip2/client.rb +269 -267
  5. data/lib/maxmind/geoip2/errors.rb +0 -7
  6. data/lib/maxmind/geoip2/model/abstract.rb +19 -15
  7. data/lib/maxmind/geoip2/model/anonymous_ip.rb +54 -50
  8. data/lib/maxmind/geoip2/model/asn.rb +33 -29
  9. data/lib/maxmind/geoip2/model/city.rb +59 -55
  10. data/lib/maxmind/geoip2/model/connection_type.rb +27 -23
  11. data/lib/maxmind/geoip2/model/country.rb +57 -53
  12. data/lib/maxmind/geoip2/model/domain.rb +27 -23
  13. data/lib/maxmind/geoip2/model/enterprise.rb +13 -9
  14. data/lib/maxmind/geoip2/model/insights.rb +12 -8
  15. data/lib/maxmind/geoip2/model/isp.rb +45 -41
  16. data/lib/maxmind/geoip2/reader.rb +242 -240
  17. data/lib/maxmind/geoip2/record/abstract.rb +17 -13
  18. data/lib/maxmind/geoip2/record/city.rb +33 -29
  19. data/lib/maxmind/geoip2/record/continent.rb +32 -28
  20. data/lib/maxmind/geoip2/record/country.rb +47 -43
  21. data/lib/maxmind/geoip2/record/location.rb +64 -60
  22. data/lib/maxmind/geoip2/record/maxmind.rb +14 -10
  23. data/lib/maxmind/geoip2/record/place.rb +22 -18
  24. data/lib/maxmind/geoip2/record/postal.rb +26 -22
  25. data/lib/maxmind/geoip2/record/represented_country.rb +20 -16
  26. data/lib/maxmind/geoip2/record/subdivision.rb +42 -38
  27. data/lib/maxmind/geoip2/record/traits.rb +195 -191
  28. data/maxmind-geoip2.gemspec +1 -1
  29. data/test/data/LICENSE +4 -0
  30. data/test/data/MaxMind-DB-spec.md +570 -0
  31. data/test/data/MaxMind-DB-test-metadata-pointers.mmdb +0 -0
  32. data/test/data/README.md +4 -0
  33. data/test/data/bad-data/README.md +7 -0
  34. data/test/data/bad-data/libmaxminddb/libmaxminddb-offset-integer-overflow.mmdb +0 -0
  35. data/test/data/bad-data/maxminddb-golang/cyclic-data-structure.mmdb +0 -0
  36. data/test/data/bad-data/maxminddb-golang/invalid-bytes-length.mmdb +1 -0
  37. data/test/data/bad-data/maxminddb-golang/invalid-data-record-offset.mmdb +0 -0
  38. data/test/data/bad-data/maxminddb-golang/invalid-map-key-length.mmdb +0 -0
  39. data/test/data/bad-data/maxminddb-golang/invalid-string-length.mmdb +1 -0
  40. data/test/data/bad-data/maxminddb-golang/metadata-is-an-uint128.mmdb +1 -0
  41. data/test/data/bad-data/maxminddb-golang/unexpected-bytes.mmdb +0 -0
  42. data/test/data/perltidyrc +12 -0
  43. data/test/data/source-data/GeoIP2-Anonymous-IP-Test.json +48 -0
  44. data/test/data/source-data/GeoIP2-City-Test.json +12852 -0
  45. data/test/data/source-data/GeoIP2-Connection-Type-Test.json +102 -0
  46. data/test/data/source-data/GeoIP2-Country-Test.json +15916 -0
  47. data/test/data/source-data/GeoIP2-DensityIncome-Test.json +14 -0
  48. data/test/data/source-data/GeoIP2-Domain-Test.json +452 -0
  49. data/test/data/source-data/GeoIP2-Enterprise-Test.json +687 -0
  50. data/test/data/source-data/GeoIP2-ISP-Test.json +12593 -0
  51. data/test/data/source-data/GeoIP2-Precision-Enterprise-Test.json +2061 -0
  52. data/test/data/source-data/GeoIP2-Static-IP-Score-Test.json +2132 -0
  53. data/test/data/source-data/GeoIP2-User-Count-Test.json +2837 -0
  54. data/test/data/source-data/GeoLite2-ASN-Test.json +37 -0
  55. data/test/data/source-data/README +15 -0
  56. data/test/data/test-data/GeoIP2-Anonymous-IP-Test.mmdb +0 -0
  57. data/test/data/test-data/GeoIP2-City-Test-Broken-Double-Format.mmdb +0 -0
  58. data/test/data/test-data/GeoIP2-City-Test-Invalid-Node-Count.mmdb +0 -0
  59. data/test/data/test-data/GeoIP2-City-Test.mmdb +0 -0
  60. data/test/data/test-data/GeoIP2-Connection-Type-Test.mmdb +0 -0
  61. data/test/data/test-data/GeoIP2-Country-Test.mmdb +0 -0
  62. data/test/data/test-data/GeoIP2-DensityIncome-Test.mmdb +0 -0
  63. data/test/data/test-data/GeoIP2-Domain-Test.mmdb +0 -0
  64. data/test/data/test-data/GeoIP2-Enterprise-Test.mmdb +0 -0
  65. data/test/data/test-data/GeoIP2-ISP-Test.mmdb +0 -0
  66. data/test/data/test-data/GeoIP2-Precision-Enterprise-Test.mmdb +0 -0
  67. data/test/data/test-data/GeoIP2-Static-IP-Score-Test.mmdb +0 -0
  68. data/test/data/test-data/GeoIP2-User-Count-Test.mmdb +0 -0
  69. data/test/data/test-data/GeoLite2-ASN-Test.mmdb +0 -0
  70. data/test/data/test-data/MaxMind-DB-no-ipv4-search-tree.mmdb +0 -0
  71. data/test/data/test-data/MaxMind-DB-string-value-entries.mmdb +0 -0
  72. data/test/data/test-data/MaxMind-DB-test-broken-pointers-24.mmdb +0 -0
  73. data/test/data/test-data/MaxMind-DB-test-broken-search-tree-24.mmdb +0 -0
  74. data/test/data/test-data/MaxMind-DB-test-decoder.mmdb +0 -0
  75. data/test/data/test-data/MaxMind-DB-test-ipv4-24.mmdb +0 -0
  76. data/test/data/test-data/MaxMind-DB-test-ipv4-28.mmdb +0 -0
  77. data/test/data/test-data/MaxMind-DB-test-ipv4-32.mmdb +0 -0
  78. data/test/data/test-data/MaxMind-DB-test-ipv6-24.mmdb +0 -0
  79. data/test/data/test-data/MaxMind-DB-test-ipv6-28.mmdb +0 -0
  80. data/test/data/test-data/MaxMind-DB-test-ipv6-32.mmdb +0 -0
  81. data/test/data/test-data/MaxMind-DB-test-metadata-pointers.mmdb +0 -0
  82. data/test/data/test-data/MaxMind-DB-test-mixed-24.mmdb +0 -0
  83. data/test/data/test-data/MaxMind-DB-test-mixed-28.mmdb +0 -0
  84. data/test/data/test-data/MaxMind-DB-test-mixed-32.mmdb +0 -0
  85. data/test/data/test-data/MaxMind-DB-test-nested.mmdb +0 -0
  86. data/test/data/test-data/README.md +26 -0
  87. data/test/data/test-data/maps-with-pointers.raw +0 -0
  88. data/test/data/test-data/write-test-data.pl +641 -0
  89. data/test/data/tidyall.ini +5 -0
  90. metadata +64 -3
@@ -1,22 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module MaxMind::GeoIP2::Record
4
- # @!visibility private
5
- class Abstract
6
- def initialize(record)
7
- @record = record
8
- end
3
+ module MaxMind
4
+ module GeoIP2
5
+ module Record
6
+ # @!visibility private
7
+ class Abstract
8
+ def initialize(record)
9
+ @record = record
10
+ end
9
11
 
10
- protected
12
+ protected
11
13
 
12
- def get(key)
13
- if @record.nil? || !@record.key?(key)
14
- return false if key.start_with?('is_')
14
+ def get(key)
15
+ if @record.nil? || !@record.key?(key)
16
+ return false if key.start_with?('is_')
15
17
 
16
- return nil
17
- end
18
+ return nil
19
+ end
18
20
 
19
- @record[key]
21
+ @record[key]
22
+ end
23
+ end
20
24
  end
21
25
  end
22
26
  end
@@ -2,37 +2,41 @@
2
2
 
3
3
  require 'maxmind/geoip2/record/place'
4
4
 
5
- module MaxMind::GeoIP2::Record
6
- # City-level data associated with an IP address.
7
- #
8
- # This record is returned by all location services and databases besides
9
- # Country.
10
- #
11
- # See {MaxMind::GeoIP2::Record::Place} for inherited methods.
12
- class City < Place
13
- # A value from 0-100 indicating MaxMind's confidence that the city is
14
- # correct. This attribute is only available from the Insights service and
15
- # the GeoIP2 Enterprise database.
16
- #
17
- # @return [Integer, nil]
18
- def confidence
19
- get('confidence')
20
- end
5
+ module MaxMind
6
+ module GeoIP2
7
+ module Record
8
+ # City-level data associated with an IP address.
9
+ #
10
+ # This record is returned by all location services and databases besides
11
+ # Country.
12
+ #
13
+ # See {MaxMind::GeoIP2::Record::Place} for inherited methods.
14
+ class City < Place
15
+ # A value from 0-100 indicating MaxMind's confidence that the city is
16
+ # correct. This attribute is only available from the Insights service and
17
+ # the GeoIP2 Enterprise database.
18
+ #
19
+ # @return [Integer, nil]
20
+ def confidence
21
+ get('confidence')
22
+ end
21
23
 
22
- # The GeoName ID for the city. This attribute is returned by all location
23
- # services and databases.
24
- #
25
- # @return [Integer, nil]
26
- def geoname_id
27
- get('geoname_id')
28
- end
24
+ # The GeoName ID for the city. This attribute is returned by all location
25
+ # services and databases.
26
+ #
27
+ # @return [Integer, nil]
28
+ def geoname_id
29
+ get('geoname_id')
30
+ end
29
31
 
30
- # A Hash where the keys are locale codes and the values are names. This
31
- # attribute is returned by all location services and databases.
32
- #
33
- # @return [Hash<String, String>, nil]
34
- def names
35
- get('names')
32
+ # A Hash where the keys are locale codes and the values are names. This
33
+ # attribute is returned by all location services and databases.
34
+ #
35
+ # @return [Hash<String, String>, nil]
36
+ def names
37
+ get('names')
38
+ end
39
+ end
36
40
  end
37
41
  end
38
42
  end
@@ -2,36 +2,40 @@
2
2
 
3
3
  require 'maxmind/geoip2/record/place'
4
4
 
5
- module MaxMind::GeoIP2::Record
6
- # Contains data for the continent record associated with an IP address.
7
- #
8
- # This record is returned by all location services and databases.
9
- #
10
- # See {MaxMind::GeoIP2::Record::Place} for inherited methods.
11
- class Continent < Place
12
- # A two character continent code like "NA" (North America) or "OC"
13
- # (Oceania). This attribute is returned by all location services and
14
- # databases.
15
- #
16
- # @return [String, nil]
17
- def code
18
- get('code')
19
- end
5
+ module MaxMind
6
+ module GeoIP2
7
+ module Record
8
+ # Contains data for the continent record associated with an IP address.
9
+ #
10
+ # This record is returned by all location services and databases.
11
+ #
12
+ # See {MaxMind::GeoIP2::Record::Place} for inherited methods.
13
+ class Continent < Place
14
+ # A two character continent code like "NA" (North America) or "OC"
15
+ # (Oceania). This attribute is returned by all location services and
16
+ # databases.
17
+ #
18
+ # @return [String, nil]
19
+ def code
20
+ get('code')
21
+ end
20
22
 
21
- # The GeoName ID for the continent. This attribute is returned by all
22
- # location services and databases.
23
- #
24
- # @return [String, nil]
25
- def geoname_id
26
- get('geoname_id')
27
- end
23
+ # The GeoName ID for the continent. This attribute is returned by all
24
+ # location services and databases.
25
+ #
26
+ # @return [String, nil]
27
+ def geoname_id
28
+ get('geoname_id')
29
+ end
28
30
 
29
- # A Hash where the keys are locale codes and the values are names. This
30
- # attribute is returned by all location services and databases.
31
- #
32
- # @return [Hash<String, String>, nil]
33
- def names
34
- get('names')
31
+ # A Hash where the keys are locale codes and the values are names. This
32
+ # attribute is returned by all location services and databases.
33
+ #
34
+ # @return [Hash<String, String>, nil]
35
+ def names
36
+ get('names')
37
+ end
38
+ end
35
39
  end
36
40
  end
37
41
  end
@@ -2,53 +2,57 @@
2
2
 
3
3
  require 'maxmind/geoip2/record/place'
4
4
 
5
- module MaxMind::GeoIP2::Record
6
- # Contains data for the country record associated with an IP address.
7
- #
8
- # This record is returned by all location services and databases.
9
- #
10
- # See {MaxMind::GeoIP2::Record::Place} for inherited methods.
11
- class Country < Place
12
- # A value from 0-100 indicating MaxMind's confidence that the country is
13
- # correct. This attribute is only available from the Insights service and
14
- # the GeoIP2 Enterprise database.
15
- #
16
- # @return [Integer, nil]
17
- def confidence
18
- get('confidence')
19
- end
5
+ module MaxMind
6
+ module GeoIP2
7
+ module Record
8
+ # Contains data for the country record associated with an IP address.
9
+ #
10
+ # This record is returned by all location services and databases.
11
+ #
12
+ # See {MaxMind::GeoIP2::Record::Place} for inherited methods.
13
+ class Country < Place
14
+ # A value from 0-100 indicating MaxMind's confidence that the country is
15
+ # correct. This attribute is only available from the Insights service and
16
+ # the GeoIP2 Enterprise database.
17
+ #
18
+ # @return [Integer, nil]
19
+ def confidence
20
+ get('confidence')
21
+ end
20
22
 
21
- # The GeoName ID for the country. This attribute is returned by all
22
- # location services and databases.
23
- #
24
- # @return [Integer, nil]
25
- def geoname_id
26
- get('geoname_id')
27
- end
23
+ # The GeoName ID for the country. This attribute is returned by all
24
+ # location services and databases.
25
+ #
26
+ # @return [Integer, nil]
27
+ def geoname_id
28
+ get('geoname_id')
29
+ end
28
30
 
29
- # This is true if the country is a member state of the European Union. This
30
- # attribute is returned by all location services and databases.
31
- #
32
- # @return [Boolean]
33
- def in_european_union?
34
- get('is_in_european_union')
35
- end
31
+ # This is true if the country is a member state of the European Union. This
32
+ # attribute is returned by all location services and databases.
33
+ #
34
+ # @return [Boolean]
35
+ def in_european_union?
36
+ get('is_in_european_union')
37
+ end
36
38
 
37
- # The two-character ISO 3166-1 alpha code for the country. See
38
- # https://en.wikipedia.org/wiki/ISO_3166-1. This attribute is returned by
39
- # all location services and databases.
40
- #
41
- # @return [String, nil]
42
- def iso_code
43
- get('iso_code')
44
- end
39
+ # The two-character ISO 3166-1 alpha code for the country. See
40
+ # https://en.wikipedia.org/wiki/ISO_3166-1. This attribute is returned by
41
+ # all location services and databases.
42
+ #
43
+ # @return [String, nil]
44
+ def iso_code
45
+ get('iso_code')
46
+ end
45
47
 
46
- # A Hash where the keys are locale codes and the values are names. This
47
- # attribute is returned by all location services and databases.
48
- #
49
- # @return [Hash<String, String>, nil]
50
- def names
51
- get('names')
48
+ # A Hash where the keys are locale codes and the values are names. This
49
+ # attribute is returned by all location services and databases.
50
+ #
51
+ # @return [Hash<String, String>, nil]
52
+ def names
53
+ get('names')
54
+ end
55
+ end
52
56
  end
53
57
  end
54
58
  end
@@ -2,72 +2,76 @@
2
2
 
3
3
  require 'maxmind/geoip2/record/abstract'
4
4
 
5
- module MaxMind::GeoIP2::Record
6
- # Contains data for the location record associated with an IP address.
7
- #
8
- # This record is returned by all location services and databases besides
9
- # Country.
10
- class Location < Abstract
11
- # The approximate accuracy radius in kilometers around the latitude and
12
- # longitude for the IP address. This is the radius where we have a 67%
13
- # confidence that the device using the IP address resides within the circle
14
- # centered at the latitude and longitude with the provided radius.
15
- #
16
- # @return [Integer, nil]
17
- def accuracy_radius
18
- get('accuracy_radius')
19
- end
5
+ module MaxMind
6
+ module GeoIP2
7
+ module Record
8
+ # Contains data for the location record associated with an IP address.
9
+ #
10
+ # This record is returned by all location services and databases besides
11
+ # Country.
12
+ class Location < Abstract
13
+ # The approximate accuracy radius in kilometers around the latitude and
14
+ # longitude for the IP address. This is the radius where we have a 67%
15
+ # confidence that the device using the IP address resides within the circle
16
+ # centered at the latitude and longitude with the provided radius.
17
+ #
18
+ # @return [Integer, nil]
19
+ def accuracy_radius
20
+ get('accuracy_radius')
21
+ end
20
22
 
21
- # The average income in US dollars associated with the requested IP
22
- # address. This attribute is only available from the Insights service.
23
- #
24
- # @return [Integer, nil]
25
- def average_income
26
- get('average_income')
27
- end
23
+ # The average income in US dollars associated with the requested IP
24
+ # address. This attribute is only available from the Insights service.
25
+ #
26
+ # @return [Integer, nil]
27
+ def average_income
28
+ get('average_income')
29
+ end
28
30
 
29
- # The approximate latitude of the location associated with the IP address.
30
- # This value is not precise and should not be used to identify a particular
31
- # address or household.
32
- #
33
- # @return [Float, nil]
34
- def latitude
35
- get('latitude')
36
- end
31
+ # The approximate latitude of the location associated with the IP address.
32
+ # This value is not precise and should not be used to identify a particular
33
+ # address or household.
34
+ #
35
+ # @return [Float, nil]
36
+ def latitude
37
+ get('latitude')
38
+ end
37
39
 
38
- # The approximate longitude of the location associated with the IP address.
39
- # This value is not precise and should not be used to identify a particular
40
- # address or household.
41
- #
42
- # @return [Float, nil]
43
- def longitude
44
- get('longitude')
45
- end
40
+ # The approximate longitude of the location associated with the IP address.
41
+ # This value is not precise and should not be used to identify a particular
42
+ # address or household.
43
+ #
44
+ # @return [Float, nil]
45
+ def longitude
46
+ get('longitude')
47
+ end
46
48
 
47
- # The metro code of the location if the location is in the US. MaxMind
48
- # returns the same metro codes as the Google AdWords API. See
49
- # https://developers.google.com/adwords/api/docs/appendix/cities-DMAregions.
50
- #
51
- # @return [Integer, nil]
52
- def metro_code
53
- get('metro_code')
54
- end
49
+ # The metro code of the location if the location is in the US. MaxMind
50
+ # returns the same metro codes as the Google AdWords API. See
51
+ # https://developers.google.com/adwords/api/docs/appendix/cities-DMAregions.
52
+ #
53
+ # @return [Integer, nil]
54
+ def metro_code
55
+ get('metro_code')
56
+ end
55
57
 
56
- # The estimated population per square kilometer associated with the IP
57
- # address. This attribute is only available from the Insights service.
58
- #
59
- # @return [Integer, nil]
60
- def population_density
61
- get('population_density')
62
- end
58
+ # The estimated population per square kilometer associated with the IP
59
+ # address. This attribute is only available from the Insights service.
60
+ #
61
+ # @return [Integer, nil]
62
+ def population_density
63
+ get('population_density')
64
+ end
63
65
 
64
- # The time zone associated with location, as specified by the IANA Time
65
- # Zone Database, e.g., "America/New_York". See
66
- # https://www.iana.org/time-zones.
67
- #
68
- # @return [String, nil]
69
- def time_zone
70
- get('time_zone')
66
+ # The time zone associated with location, as specified by the IANA Time
67
+ # Zone Database, e.g., "America/New_York". See
68
+ # https://www.iana.org/time-zones.
69
+ #
70
+ # @return [String, nil]
71
+ def time_zone
72
+ get('time_zone')
73
+ end
74
+ end
71
75
  end
72
76
  end
73
77
  end
@@ -2,16 +2,20 @@
2
2
 
3
3
  require 'maxmind/geoip2/record/abstract'
4
4
 
5
- module MaxMind::GeoIP2::Record
6
- # Contains data about your account.
7
- #
8
- # This record is returned by all location services.
9
- class MaxMind < Abstract
10
- # The number of remaining queries you have for the service you are calling.
11
- #
12
- # @return [Integer, nil]
13
- def queries_remaining
14
- get('queries_remaining')
5
+ module MaxMind
6
+ module GeoIP2
7
+ module Record
8
+ # Contains data about your account.
9
+ #
10
+ # This record is returned by all location services.
11
+ class MaxMind < Abstract
12
+ # The number of remaining queries you have for the service you are calling.
13
+ #
14
+ # @return [Integer, nil]
15
+ def queries_remaining
16
+ get('queries_remaining')
17
+ end
18
+ end
15
19
  end
16
20
  end
17
21
  end