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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +32 -0
- data/Gemfile +1 -5
- data/README.dev.md +1 -1
- data/README.md +82 -8
- data/lib/maxmind/geoip2.rb +1 -0
- data/lib/maxmind/geoip2/client.rb +333 -0
- data/lib/maxmind/geoip2/errors.rb +37 -3
- data/lib/maxmind/geoip2/model/abstract.rb +19 -15
- data/lib/maxmind/geoip2/model/anonymous_ip.rb +62 -50
- data/lib/maxmind/geoip2/model/asn.rb +33 -29
- data/lib/maxmind/geoip2/model/city.rb +59 -55
- data/lib/maxmind/geoip2/model/connection_type.rb +27 -23
- data/lib/maxmind/geoip2/model/country.rb +64 -53
- data/lib/maxmind/geoip2/model/domain.rb +27 -23
- data/lib/maxmind/geoip2/model/enterprise.rb +13 -9
- data/lib/maxmind/geoip2/model/insights.rb +18 -0
- data/lib/maxmind/geoip2/model/isp.rb +45 -41
- data/lib/maxmind/geoip2/reader.rb +260 -233
- data/lib/maxmind/geoip2/record/abstract.rb +17 -13
- data/lib/maxmind/geoip2/record/city.rb +33 -29
- data/lib/maxmind/geoip2/record/continent.rb +32 -28
- data/lib/maxmind/geoip2/record/country.rb +47 -43
- data/lib/maxmind/geoip2/record/location.rb +64 -60
- data/lib/maxmind/geoip2/record/maxmind.rb +21 -0
- data/lib/maxmind/geoip2/record/place.rb +22 -18
- data/lib/maxmind/geoip2/record/postal.rb +26 -22
- data/lib/maxmind/geoip2/record/represented_country.rb +20 -16
- data/lib/maxmind/geoip2/record/subdivision.rb +42 -38
- data/lib/maxmind/geoip2/record/traits.rb +204 -191
- data/maxmind-geoip2.gemspec +11 -3
- data/test/data/bad-data/maxminddb-python/bad-unicode-in-map-key.mmdb +0 -0
- data/test/data/source-data/GeoIP2-Anonymous-IP-Test.json +1 -0
- data/test/data/source-data/GeoIP2-ISP-Test.json +3 -1
- data/test/data/source-data/GeoIP2-Precision-Enterprise-Test.json +87 -0
- data/test/data/test-data/GeoIP2-Anonymous-IP-Test.mmdb +0 -0
- data/test/data/test-data/GeoIP2-City-Test-Broken-Double-Format.mmdb +0 -0
- data/test/data/test-data/GeoIP2-City-Test-Invalid-Node-Count.mmdb +0 -0
- data/test/data/test-data/GeoIP2-City-Test.mmdb +0 -0
- data/test/data/test-data/GeoIP2-Connection-Type-Test.mmdb +0 -0
- data/test/data/test-data/GeoIP2-Country-Test.mmdb +0 -0
- data/test/data/test-data/GeoIP2-DensityIncome-Test.mmdb +0 -0
- data/test/data/test-data/GeoIP2-Domain-Test.mmdb +0 -0
- data/test/data/test-data/GeoIP2-Enterprise-Test.mmdb +0 -0
- data/test/data/test-data/GeoIP2-ISP-Test.mmdb +0 -0
- data/test/data/test-data/GeoIP2-Precision-Enterprise-Test.mmdb +0 -0
- data/test/data/test-data/GeoIP2-Static-IP-Score-Test.mmdb +0 -0
- data/test/data/test-data/GeoIP2-User-Count-Test.mmdb +0 -0
- data/test/data/test-data/GeoLite2-ASN-Test.mmdb +0 -0
- data/test/data/test-data/MaxMind-DB-no-ipv4-search-tree.mmdb +0 -0
- data/test/data/test-data/MaxMind-DB-string-value-entries.mmdb +0 -0
- data/test/data/test-data/MaxMind-DB-test-broken-pointers-24.mmdb +0 -0
- data/test/data/test-data/MaxMind-DB-test-broken-search-tree-24.mmdb +0 -0
- data/test/data/test-data/MaxMind-DB-test-decoder.mmdb +0 -0
- data/test/data/test-data/MaxMind-DB-test-ipv4-24.mmdb +0 -0
- data/test/data/test-data/MaxMind-DB-test-ipv4-28.mmdb +0 -0
- data/test/data/test-data/MaxMind-DB-test-ipv4-32.mmdb +0 -0
- data/test/data/test-data/MaxMind-DB-test-ipv6-24.mmdb +0 -0
- data/test/data/test-data/MaxMind-DB-test-ipv6-28.mmdb +0 -0
- data/test/data/test-data/MaxMind-DB-test-ipv6-32.mmdb +0 -0
- data/test/data/test-data/MaxMind-DB-test-metadata-pointers.mmdb +0 -0
- data/test/data/test-data/MaxMind-DB-test-mixed-24.mmdb +0 -0
- data/test/data/test-data/MaxMind-DB-test-mixed-28.mmdb +0 -0
- data/test/data/test-data/MaxMind-DB-test-mixed-32.mmdb +0 -0
- data/test/data/test-data/MaxMind-DB-test-nested.mmdb +0 -0
- data/test/data/test-data/MaxMind-DB-test-pointer-decoder.mmdb +0 -0
- data/test/data/test-data/write-test-data.pl +68 -18
- data/test/test_client.rb +426 -0
- data/test/test_model_country.rb +16 -0
- data/test/test_reader.rb +59 -0
- metadata +113 -10
- data/Gemfile.lock +0 -38
@@ -1,22 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module MaxMind
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
12
|
+
protected
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
14
|
+
def get(key)
|
15
|
+
if @record.nil? || !@record.key?(key)
|
16
|
+
return false if key.start_with?('is_')
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
+
return nil
|
19
|
+
end
|
18
20
|
|
19
|
-
|
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
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'maxmind/geoip2/record/abstract'
|
4
|
+
|
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
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -2,27 +2,31 @@
|
|
2
2
|
|
3
3
|
require 'maxmind/geoip2/record/abstract'
|
4
4
|
|
5
|
-
module MaxMind
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
module MaxMind
|
6
|
+
module GeoIP2
|
7
|
+
module Record
|
8
|
+
# Location data common to different location types.
|
9
|
+
class Place < Abstract
|
10
|
+
# @!visibility private
|
11
|
+
def initialize(record, locales)
|
12
|
+
super(record)
|
13
|
+
@locales = locales
|
14
|
+
end
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
# The first available localized name in order of preference.
|
17
|
+
#
|
18
|
+
# @return [String, nil]
|
19
|
+
def name
|
20
|
+
n = names
|
21
|
+
return nil if n.nil?
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
|
23
|
+
@locales.each do |locale|
|
24
|
+
return n[locale] if n.key?(locale)
|
25
|
+
end
|
24
26
|
|
25
|
-
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
end
|
26
30
|
end
|
27
31
|
end
|
28
32
|
end
|