minfraud 2.8.0 → 2.10.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +55 -0
- data/LICENSE.txt +1 -1
- data/README.md +15 -10
- data/lib/minfraud/assessments.rb +1 -1
- data/lib/minfraud/components/account.rb +1 -1
- data/lib/minfraud/components/base.rb +3 -0
- data/lib/minfraud/components/billing.rb +1 -1
- data/lib/minfraud/components/credit_card.rb +8 -7
- data/lib/minfraud/components/custom_inputs.rb +1 -1
- data/lib/minfraud/components/device.rb +8 -1
- data/lib/minfraud/components/email.rb +3 -3
- data/lib/minfraud/components/event.rb +23 -6
- data/lib/minfraud/components/order.rb +2 -2
- data/lib/minfraud/components/payment.rb +29 -1
- data/lib/minfraud/components/report/transaction.rb +8 -7
- data/lib/minfraud/components/shipping.rb +1 -1
- data/lib/minfraud/components/shopping_cart.rb +2 -2
- data/lib/minfraud/components/shopping_cart_item.rb +4 -4
- data/lib/minfraud/enum.rb +9 -0
- data/lib/minfraud/http_service/response.rb +4 -2
- data/lib/minfraud/model/abstract.rb +3 -0
- data/lib/minfraud/model/device.rb +1 -1
- data/lib/minfraud/model/email.rb +2 -1
- data/lib/minfraud/model/email_domain.rb +36 -3
- data/lib/minfraud/model/email_domain_visit.rb +46 -0
- data/lib/minfraud/model/factors.rb +1 -1
- data/lib/minfraud/model/geoip2_location.rb +1 -1
- data/lib/minfraud/model/insights.rb +1 -1
- data/lib/minfraud/model/ip_address.rb +1 -1
- data/lib/minfraud/model/reason.rb +1 -1
- data/lib/minfraud/model/risk_score_reason.rb +2 -2
- data/lib/minfraud/model/shipping_address.rb +3 -1
- data/lib/minfraud/model/warning.rb +13 -2
- data/lib/minfraud/report.rb +1 -1
- data/lib/minfraud/validates.rb +142 -5
- data/lib/minfraud/version.rb +1 -1
- data/lib/minfraud.rb +11 -0
- metadata +78 -19
- data/.rspec +0 -2
- data/.rubocop.yml +0 -90
- data/CODE_OF_CONDUCT.md +0 -49
- data/Gemfile +0 -5
- data/README.dev.md +0 -28
- data/Rakefile +0 -12
- data/bin/console +0 -15
- data/bin/setup +0 -8
- data/minfraud.gemspec +0 -38
|
@@ -7,18 +7,20 @@ require 'minfraud/model/insights'
|
|
|
7
7
|
require 'minfraud/model/score'
|
|
8
8
|
|
|
9
9
|
module Minfraud
|
|
10
|
+
# HTTPService contains classes for handling HTTP communication with the
|
|
11
|
+
# minFraud web services.
|
|
10
12
|
module HTTPService
|
|
11
13
|
# Response class for HTTP requests.
|
|
12
14
|
class Response
|
|
13
15
|
# Response HTTP status code.
|
|
14
16
|
#
|
|
15
|
-
# @return [
|
|
17
|
+
# @return [Integer, nil]
|
|
16
18
|
attr_reader :status
|
|
17
19
|
|
|
18
20
|
# Response model.
|
|
19
21
|
#
|
|
20
22
|
# @return [Minfraud::Model::Score, Minfraud::Model::Insights,
|
|
21
|
-
# Minfraud::Model::Factors, nil]
|
|
23
|
+
# Minfraud::Model::Factors, Minfraud::Model::Error, nil]
|
|
22
24
|
attr_reader :body
|
|
23
25
|
|
|
24
26
|
# @param endpoint [Symbol, nil] endpoint name, like :score.
|
|
@@ -8,7 +8,7 @@ module Minfraud
|
|
|
8
8
|
#
|
|
9
9
|
# In order to receive device output from minFraud Insights or minFraud
|
|
10
10
|
# Factors, you must be using the Device Tracking Add-on
|
|
11
|
-
# (https://dev.maxmind.com/minfraud/track-devices
|
|
11
|
+
# (https://dev.maxmind.com/minfraud/track-devices/?lang=en).
|
|
12
12
|
class Device < Abstract
|
|
13
13
|
# This number represents our confidence that the device_id refers to a
|
|
14
14
|
# unique device as opposed to a cluster of similar devices. A confidence
|
data/lib/minfraud/model/email.rb
CHANGED
|
@@ -14,7 +14,8 @@ module Minfraud
|
|
|
14
14
|
|
|
15
15
|
# A date string (e.g. 2017-04-24) to identify the date an email address
|
|
16
16
|
# was first seen by MaxMind. This is expressed using the ISO 8601 date
|
|
17
|
-
# format.
|
|
17
|
+
# format YYYY-MM-DD. The earliest date that may be returned is January
|
|
18
|
+
# 1, 2008.
|
|
18
19
|
#
|
|
19
20
|
# @return [String, nil]
|
|
20
21
|
attr_reader :first_seen
|
|
@@ -1,23 +1,56 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'minfraud/model/abstract'
|
|
4
|
+
require 'minfraud/model/email_domain_visit'
|
|
4
5
|
|
|
5
6
|
module Minfraud
|
|
6
7
|
module Model
|
|
7
8
|
# Model containing information about the email domain.
|
|
8
9
|
class EmailDomain < Abstract
|
|
9
|
-
# A
|
|
10
|
+
# A classification of the domain. Possible values are:
|
|
11
|
+
# * business
|
|
12
|
+
# * education
|
|
13
|
+
# * government
|
|
14
|
+
# * isp_email
|
|
15
|
+
#
|
|
16
|
+
# @return [String, nil]
|
|
17
|
+
attr_reader :classification
|
|
18
|
+
|
|
19
|
+
# A date string (e.g. 2019-01-01) to identify the date an email domain
|
|
10
20
|
# was first seen by MaxMind. This is expressed using the ISO 8601 date
|
|
11
|
-
# format.
|
|
21
|
+
# format YYYY-MM-DD. The earliest date that may be returned is January
|
|
22
|
+
# 1, 2019.
|
|
12
23
|
#
|
|
13
24
|
# @return [String, nil]
|
|
14
25
|
attr_reader :first_seen
|
|
15
26
|
|
|
27
|
+
# A risk score ranging from 0.01 to 99. Higher values indicate greater
|
|
28
|
+
# risk.
|
|
29
|
+
#
|
|
30
|
+
# @return [Float, nil]
|
|
31
|
+
attr_reader :risk
|
|
32
|
+
|
|
33
|
+
# An object containing information about an automated visit to the email
|
|
34
|
+
# domain.
|
|
35
|
+
#
|
|
36
|
+
# @return [Minfraud::Model::EmailDomainVisit, nil]
|
|
37
|
+
attr_reader :visit
|
|
38
|
+
|
|
39
|
+
# Activity across the minFraud network expressed as sightings per
|
|
40
|
+
# million. The value ranges from 0.001 to 1,000,000.
|
|
41
|
+
#
|
|
42
|
+
# @return [Float, nil]
|
|
43
|
+
attr_reader :volume
|
|
44
|
+
|
|
16
45
|
# @!visibility private
|
|
17
46
|
def initialize(record)
|
|
18
47
|
super
|
|
19
48
|
|
|
20
|
-
@
|
|
49
|
+
@classification = get('classification')
|
|
50
|
+
@first_seen = get('first_seen')
|
|
51
|
+
@risk = get('risk')
|
|
52
|
+
@visit = EmailDomainVisit.new(get('visit'))
|
|
53
|
+
@volume = get('volume')
|
|
21
54
|
end
|
|
22
55
|
end
|
|
23
56
|
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'minfraud/model/abstract'
|
|
4
|
+
|
|
5
|
+
module Minfraud
|
|
6
|
+
module Model
|
|
7
|
+
# Model containing information about an automated visit to the email
|
|
8
|
+
# domain.
|
|
9
|
+
class EmailDomainVisit < Abstract
|
|
10
|
+
# This is true if the domain in the request has redirects (configured
|
|
11
|
+
# to automatically send visitors to another URL). Otherwise, this will
|
|
12
|
+
# be nil.
|
|
13
|
+
#
|
|
14
|
+
# @return [Boolean, nil]
|
|
15
|
+
attr_reader :has_redirect
|
|
16
|
+
|
|
17
|
+
# A date string (e.g. 2025-11-15) identifying the date the automated
|
|
18
|
+
# visit was completed. This is expressed using the ISO 8601 date format.
|
|
19
|
+
#
|
|
20
|
+
# @return [String, nil]
|
|
21
|
+
attr_reader :last_visited_on
|
|
22
|
+
|
|
23
|
+
# The status of the domain. Possible values are:
|
|
24
|
+
# * live - The domain is reachable and serving content normally.
|
|
25
|
+
# * dns_error - The domain is missing, expired, or DNS is misconfigured.
|
|
26
|
+
# * network_error - The domain is offline, blocked, or unreachable.
|
|
27
|
+
# * http_error - The domain is reachable but the web application had a
|
|
28
|
+
# problem or denied the request.
|
|
29
|
+
# * parked - The domain is live and is in a parked state.
|
|
30
|
+
# * pre_development - The domain is live and is in a pre-development
|
|
31
|
+
# state.
|
|
32
|
+
#
|
|
33
|
+
# @return [String, nil]
|
|
34
|
+
attr_reader :status
|
|
35
|
+
|
|
36
|
+
# @!visibility private
|
|
37
|
+
def initialize(record)
|
|
38
|
+
super
|
|
39
|
+
|
|
40
|
+
@has_redirect = get('has_redirect')
|
|
41
|
+
@last_visited_on = get('last_visited_on')
|
|
42
|
+
@status = get('status')
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -21,7 +21,7 @@ module Minfraud
|
|
|
21
21
|
# that are used to calculate the overall risk score.
|
|
22
22
|
#
|
|
23
23
|
# @return [Minfraud::Model::Subscores]
|
|
24
|
-
# @deprecated Use {
|
|
24
|
+
# @deprecated Use {#risk_score_reasons} instead.
|
|
25
25
|
attr_reader :subscores
|
|
26
26
|
|
|
27
27
|
# @!visibility private
|
|
@@ -4,7 +4,7 @@ require 'maxmind/geoip2/record/location'
|
|
|
4
4
|
|
|
5
5
|
module Minfraud
|
|
6
6
|
module Model
|
|
7
|
-
# Model of the
|
|
7
|
+
# Model of the GeoIP location information, including the local time.
|
|
8
8
|
class GeoIP2Location < MaxMind::GeoIP2::Record::Location
|
|
9
9
|
# The date and time of the transaction in the time zone associated with
|
|
10
10
|
# the IP address. The value is formatted according to RFC 3339. For
|
|
@@ -43,7 +43,7 @@ module Minfraud
|
|
|
43
43
|
# @return [Minfraud::Model::Email]
|
|
44
44
|
attr_reader :email
|
|
45
45
|
|
|
46
|
-
# An object containing
|
|
46
|
+
# An object containing GeoIP and minFraud Insights information about the
|
|
47
47
|
# geolocated IP address.
|
|
48
48
|
#
|
|
49
49
|
# @return [Minfraud::Model::IPAddress]
|
|
@@ -6,7 +6,7 @@ require 'minfraud/model/ip_risk_reason'
|
|
|
6
6
|
|
|
7
7
|
module Minfraud
|
|
8
8
|
module Model
|
|
9
|
-
# Model containing
|
|
9
|
+
# Model containing GeoIP data and the risk for the IP address.
|
|
10
10
|
class IPAddress < MaxMind::GeoIP2::Model::Insights
|
|
11
11
|
# This field contains the risk associated with the IP address. The value
|
|
12
12
|
# ranges from 0.01 to 99. A higher score indicates a higher risk.
|
|
@@ -8,7 +8,7 @@ module Minfraud
|
|
|
8
8
|
#
|
|
9
9
|
# This class provides both a machine-readable code and a human-readable
|
|
10
10
|
# explanation of the reason for the risk score, see
|
|
11
|
-
# https://dev.maxmind.com/minfraud/api-documentation/responses
|
|
11
|
+
# https://dev.maxmind.com/minfraud/api-documentation/responses/#schema--response--risk-score-reason--multiplier-reason.
|
|
12
12
|
# Although more codes may be added in the future, the current codes are:
|
|
13
13
|
#
|
|
14
14
|
# * BROWSER_LANGUAGE - Riskiness of the browser user-agent and
|
|
@@ -14,9 +14,9 @@ module Minfraud
|
|
|
14
14
|
# @return [Float]
|
|
15
15
|
attr_reader :multiplier
|
|
16
16
|
|
|
17
|
-
#
|
|
17
|
+
# Reasons for the multiplier.
|
|
18
18
|
#
|
|
19
|
-
# @return [Array<Minfraud::Model::
|
|
19
|
+
# @return [Array<Minfraud::Model::Reason>]
|
|
20
20
|
attr_reader :reasons
|
|
21
21
|
|
|
22
22
|
# @!visibility private
|
|
@@ -6,7 +6,7 @@ module Minfraud
|
|
|
6
6
|
module Model
|
|
7
7
|
# Model containing information about the shipping address.
|
|
8
8
|
class ShippingAddress < Address
|
|
9
|
-
# The distance in kilometers from the shipping address to billing
|
|
9
|
+
# The distance in kilometers from the shipping address to the billing
|
|
10
10
|
# address.
|
|
11
11
|
#
|
|
12
12
|
# @return [Integer, nil]
|
|
@@ -16,6 +16,8 @@ module Minfraud
|
|
|
16
16
|
# with fraudulent transactions. The field is false when the address is
|
|
17
17
|
# not associated with increased risk. The key will only be present when a
|
|
18
18
|
# shipping address is provided.
|
|
19
|
+
#
|
|
20
|
+
# @return [Boolean, nil]
|
|
19
21
|
attr_reader :is_high_risk
|
|
20
22
|
|
|
21
23
|
# @!visibility private
|
|
@@ -17,19 +17,30 @@ module Minfraud
|
|
|
17
17
|
# our database.
|
|
18
18
|
# * BILLING_POSTAL_NOT_FOUND - the billing postal could not be found in our
|
|
19
19
|
# database.
|
|
20
|
+
# * BILLING_REGION_NOT_FOUND - the billing region could not be found in our
|
|
21
|
+
# database.
|
|
22
|
+
# * EMAIL_ADDRESS_UNUSABLE - the email address entered is likely incorrect
|
|
23
|
+
# due to an integration issue. To avoid false positives, it has not been
|
|
24
|
+
# used in scoring.
|
|
20
25
|
# * INPUT_INVALID - the value associated with the key does not meet the
|
|
21
26
|
# required constraints, e.g., "United States" in a field that requires a
|
|
22
27
|
# two-letter country code.
|
|
23
28
|
# * INPUT_UNKNOWN - an unknown key was encountered in the request body.
|
|
29
|
+
# * IP_ADDRESS_INVALID - the IP address supplied is not a valid IPv4 or
|
|
30
|
+
# IPv6 address.
|
|
24
31
|
# * IP_ADDRESS_NOT_FOUND - the IP address could not be geolocated.
|
|
25
|
-
# *
|
|
26
|
-
#
|
|
32
|
+
# * IP_ADDRESS_RESERVED - the IP address supplied is in a reserved
|
|
33
|
+
# network.
|
|
27
34
|
# * SHIPPING_CITY_NOT_FOUND - the shipping city could not be found in our
|
|
28
35
|
# database.
|
|
36
|
+
# * SHIPPING_COUNTRY_MISSING - shipping address information was provided
|
|
37
|
+
# without providing a shipping country.
|
|
29
38
|
# * SHIPPING_COUNTRY_NOT_FOUND - the shipping country could not be found in
|
|
30
39
|
# our database.
|
|
31
40
|
# * SHIPPING_POSTAL_NOT_FOUND - the shipping postal could not be found in
|
|
32
41
|
# our database.
|
|
42
|
+
# * SHIPPING_REGION_NOT_FOUND - the shipping region could not be found in
|
|
43
|
+
# our database.
|
|
33
44
|
class Warning < Abstract
|
|
34
45
|
# This value is a machine-readable code identifying the warning.
|
|
35
46
|
#
|
data/lib/minfraud/report.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module Minfraud
|
|
4
4
|
# Report is used to perform minFraud Report Transaction API requests.
|
|
5
5
|
#
|
|
6
|
-
# @see https://dev.maxmind.com/minfraud/report-a-transaction
|
|
6
|
+
# @see https://dev.maxmind.com/minfraud/report-a-transaction/?lang=en
|
|
7
7
|
class Report
|
|
8
8
|
# The Report::Transaction component.
|
|
9
9
|
#
|
data/lib/minfraud/validates.rb
CHANGED
|
@@ -4,10 +4,23 @@ require 'date'
|
|
|
4
4
|
require 'ipaddr'
|
|
5
5
|
require 'uri'
|
|
6
6
|
|
|
7
|
-
# rubocop:disable Metrics/ModuleLength
|
|
8
7
|
module Minfraud
|
|
9
8
|
# @!visibility private
|
|
9
|
+
# Validates provides validation helper methods for component input values.
|
|
10
|
+
# These methods are used internally when validation is enabled via
|
|
11
|
+
# Minfraud.enable_validation.
|
|
12
|
+
#
|
|
13
|
+
# rubocop:disable Metrics/ModuleLength
|
|
10
14
|
module Validates
|
|
15
|
+
# Validates that a string value does not exceed a maximum length.
|
|
16
|
+
#
|
|
17
|
+
# @param field [String] The field name for error messages.
|
|
18
|
+
# @param length [Integer] The maximum allowed length.
|
|
19
|
+
# @param value [String, nil] The value to validate.
|
|
20
|
+
#
|
|
21
|
+
# @raise [InvalidInputError] If the value exceeds the maximum length.
|
|
22
|
+
#
|
|
23
|
+
# @return [nil]
|
|
11
24
|
def validate_string(field, length, value)
|
|
12
25
|
return if !value
|
|
13
26
|
|
|
@@ -16,6 +29,14 @@ module Minfraud
|
|
|
16
29
|
end
|
|
17
30
|
end
|
|
18
31
|
|
|
32
|
+
# Validates that a value is a valid MD5 hash string.
|
|
33
|
+
#
|
|
34
|
+
# @param field [String] The field name for error messages.
|
|
35
|
+
# @param value [String, nil] The value to validate.
|
|
36
|
+
#
|
|
37
|
+
# @raise [InvalidInputError] If the value is not a valid MD5 hash.
|
|
38
|
+
#
|
|
39
|
+
# @return [nil]
|
|
19
40
|
def validate_md5(field, value)
|
|
20
41
|
return if !value
|
|
21
42
|
|
|
@@ -24,10 +45,18 @@ module Minfraud
|
|
|
24
45
|
end
|
|
25
46
|
end
|
|
26
47
|
|
|
48
|
+
# Validates that a value is a valid UUID string.
|
|
49
|
+
#
|
|
50
|
+
# @param field [String] The field name for error messages.
|
|
51
|
+
# @param value [String, nil] The value to validate.
|
|
52
|
+
#
|
|
53
|
+
# @raise [InvalidInputError] If the value is not a valid UUID.
|
|
54
|
+
#
|
|
55
|
+
# @return [nil]
|
|
27
56
|
def validate_uuid(field, value)
|
|
28
57
|
return if !value
|
|
29
58
|
|
|
30
|
-
stripped_value = value.to_s.
|
|
59
|
+
stripped_value = value.to_s.delete('-')
|
|
31
60
|
|
|
32
61
|
# Define a regex pattern for a valid UUID without dashes
|
|
33
62
|
uuid_regex = /\A[0-9a-f]{32}\z/i
|
|
@@ -37,6 +66,14 @@ module Minfraud
|
|
|
37
66
|
end
|
|
38
67
|
end
|
|
39
68
|
|
|
69
|
+
# Validates that a value is a valid ISO 3166-2 subdivision code.
|
|
70
|
+
#
|
|
71
|
+
# @param field [String] The field name for error messages.
|
|
72
|
+
# @param value [String, nil] The value to validate.
|
|
73
|
+
#
|
|
74
|
+
# @raise [InvalidInputError] If the value is not a valid subdivision code.
|
|
75
|
+
#
|
|
76
|
+
# @return [nil]
|
|
40
77
|
def validate_subdivision_code(field, value)
|
|
41
78
|
return if !value
|
|
42
79
|
|
|
@@ -45,6 +82,14 @@ module Minfraud
|
|
|
45
82
|
end
|
|
46
83
|
end
|
|
47
84
|
|
|
85
|
+
# Validates that a value is a valid ISO 3166-1 alpha-2 country code.
|
|
86
|
+
#
|
|
87
|
+
# @param field [String] The field name for error messages.
|
|
88
|
+
# @param value [String, nil] The value to validate.
|
|
89
|
+
#
|
|
90
|
+
# @raise [InvalidInputError] If the value is not a valid country code.
|
|
91
|
+
#
|
|
92
|
+
# @return [nil]
|
|
48
93
|
def validate_country_code(field, value)
|
|
49
94
|
return if !value
|
|
50
95
|
|
|
@@ -53,6 +98,15 @@ module Minfraud
|
|
|
53
98
|
end
|
|
54
99
|
end
|
|
55
100
|
|
|
101
|
+
# Validates that a value is a valid telephone country code (1-4 digits).
|
|
102
|
+
#
|
|
103
|
+
# @param field [String] The field name for error messages.
|
|
104
|
+
# @param value [String, nil] The value to validate.
|
|
105
|
+
#
|
|
106
|
+
# @raise [InvalidInputError] If the value is not a valid telephone country
|
|
107
|
+
# code.
|
|
108
|
+
#
|
|
109
|
+
# @return [nil]
|
|
56
110
|
def validate_telephone_country_code(field, value)
|
|
57
111
|
return if !value
|
|
58
112
|
|
|
@@ -61,6 +115,15 @@ module Minfraud
|
|
|
61
115
|
end
|
|
62
116
|
end
|
|
63
117
|
|
|
118
|
+
# Validates that a value matches a regular expression pattern.
|
|
119
|
+
#
|
|
120
|
+
# @param field [String] The field name for error messages.
|
|
121
|
+
# @param regex [Regexp] The regular expression pattern to match.
|
|
122
|
+
# @param value [String, nil] The value to validate.
|
|
123
|
+
#
|
|
124
|
+
# @raise [InvalidInputError] If the value does not match the pattern.
|
|
125
|
+
#
|
|
126
|
+
# @return [nil]
|
|
64
127
|
def validate_regex(field, regex, value)
|
|
65
128
|
return if !value
|
|
66
129
|
|
|
@@ -69,6 +132,14 @@ module Minfraud
|
|
|
69
132
|
end
|
|
70
133
|
end
|
|
71
134
|
|
|
135
|
+
# Validates that a value is a valid credit card token.
|
|
136
|
+
#
|
|
137
|
+
# @param field [String] The field name for error messages.
|
|
138
|
+
# @param value [String, nil] The value to validate.
|
|
139
|
+
#
|
|
140
|
+
# @raise [InvalidInputError] If the value is not a valid credit card token.
|
|
141
|
+
#
|
|
142
|
+
# @return [nil]
|
|
72
143
|
def validate_credit_card_token(field, value)
|
|
73
144
|
return if !value
|
|
74
145
|
|
|
@@ -78,11 +149,19 @@ module Minfraud
|
|
|
78
149
|
raise InvalidInputError, "The #{field} value is not valid. It must contain only non-space printable ASCII characters."
|
|
79
150
|
end
|
|
80
151
|
|
|
81
|
-
if /\A[0-9]{1,19}\z/.match(s)
|
|
152
|
+
if /\A[0-9]{1,19}\z/.match?(s)
|
|
82
153
|
raise InvalidInputError, "The #{field} value is not valid. If it is all digits, it must be longer than 19 characters."
|
|
83
154
|
end
|
|
84
155
|
end
|
|
85
156
|
|
|
157
|
+
# Validates a custom input value (boolean, numeric, or string).
|
|
158
|
+
#
|
|
159
|
+
# @param field [String] The field name for error messages.
|
|
160
|
+
# @param value [Boolean, Numeric, String, nil] The value to validate.
|
|
161
|
+
#
|
|
162
|
+
# @raise [InvalidInputError] If the value is not valid.
|
|
163
|
+
#
|
|
164
|
+
# @return [nil]
|
|
86
165
|
def validate_custom_input_value(field, value)
|
|
87
166
|
return if !value
|
|
88
167
|
|
|
@@ -101,6 +180,14 @@ module Minfraud
|
|
|
101
180
|
validate_string(field, 255, value)
|
|
102
181
|
end
|
|
103
182
|
|
|
183
|
+
# Validates that a value is a valid IPv4 or IPv6 address.
|
|
184
|
+
#
|
|
185
|
+
# @param field [String] The field name for error messages.
|
|
186
|
+
# @param value [String, nil] The value to validate.
|
|
187
|
+
#
|
|
188
|
+
# @raise [InvalidInputError] If the value is not a valid IP address.
|
|
189
|
+
#
|
|
190
|
+
# @return [nil]
|
|
104
191
|
def validate_ip(field, value)
|
|
105
192
|
return if !value
|
|
106
193
|
|
|
@@ -120,6 +207,15 @@ module Minfraud
|
|
|
120
207
|
nil
|
|
121
208
|
end
|
|
122
209
|
|
|
210
|
+
# Validates that a value is a non-negative number within range.
|
|
211
|
+
#
|
|
212
|
+
# @param field [String] The field name for error messages.
|
|
213
|
+
# @param value [Numeric, nil] The value to validate.
|
|
214
|
+
#
|
|
215
|
+
# @raise [InvalidInputError] If the value is not a valid non-negative
|
|
216
|
+
# number.
|
|
217
|
+
#
|
|
218
|
+
# @return [nil]
|
|
123
219
|
def validate_nonnegative_number(field, value)
|
|
124
220
|
return if !value
|
|
125
221
|
|
|
@@ -132,6 +228,15 @@ module Minfraud
|
|
|
132
228
|
end
|
|
133
229
|
end
|
|
134
230
|
|
|
231
|
+
# Validates that a value is a non-negative integer within range.
|
|
232
|
+
#
|
|
233
|
+
# @param field [String] The field name for error messages.
|
|
234
|
+
# @param value [Integer, nil] The value to validate.
|
|
235
|
+
#
|
|
236
|
+
# @raise [InvalidInputError] If the value is not a valid non-negative
|
|
237
|
+
# integer.
|
|
238
|
+
#
|
|
239
|
+
# @return [nil]
|
|
135
240
|
def validate_nonnegative_integer(field, value)
|
|
136
241
|
return if !value
|
|
137
242
|
|
|
@@ -144,10 +249,18 @@ module Minfraud
|
|
|
144
249
|
end
|
|
145
250
|
end
|
|
146
251
|
|
|
252
|
+
# Validates that a value is a valid email address or MD5 hash of one.
|
|
253
|
+
#
|
|
254
|
+
# @param field [String] The field name for error messages.
|
|
255
|
+
# @param value [String, nil] The value to validate.
|
|
256
|
+
#
|
|
257
|
+
# @raise [InvalidInputError] If the value is not a valid email or MD5 hash.
|
|
258
|
+
#
|
|
259
|
+
# @return [nil]
|
|
147
260
|
def validate_email(field, value)
|
|
148
261
|
return if !value
|
|
149
262
|
|
|
150
|
-
if /.@./.match(value)
|
|
263
|
+
if /.@./.match?(value)
|
|
151
264
|
validate_string(field, 255, value)
|
|
152
265
|
return
|
|
153
266
|
end
|
|
@@ -155,6 +268,14 @@ module Minfraud
|
|
|
155
268
|
validate_md5(field, value)
|
|
156
269
|
end
|
|
157
270
|
|
|
271
|
+
# Validates that a value is in RFC 3339 date-time format.
|
|
272
|
+
#
|
|
273
|
+
# @param field [String] The field name for error messages.
|
|
274
|
+
# @param value [String, nil] The value to validate.
|
|
275
|
+
#
|
|
276
|
+
# @raise [InvalidInputError] If the value is not in RFC 3339 format.
|
|
277
|
+
#
|
|
278
|
+
# @return [nil]
|
|
158
279
|
def validate_rfc3339(field, value)
|
|
159
280
|
return if !value
|
|
160
281
|
|
|
@@ -169,6 +290,14 @@ module Minfraud
|
|
|
169
290
|
nil
|
|
170
291
|
end
|
|
171
292
|
|
|
293
|
+
# Validates that a value is a boolean.
|
|
294
|
+
#
|
|
295
|
+
# @param field [String] The field name for error messages.
|
|
296
|
+
# @param value [Boolean, nil] The value to validate.
|
|
297
|
+
#
|
|
298
|
+
# @raise [InvalidInputError] If the value is not a boolean.
|
|
299
|
+
#
|
|
300
|
+
# @return [nil]
|
|
172
301
|
def validate_boolean(field, value)
|
|
173
302
|
return if !value
|
|
174
303
|
|
|
@@ -177,6 +306,14 @@ module Minfraud
|
|
|
177
306
|
end
|
|
178
307
|
end
|
|
179
308
|
|
|
309
|
+
# Validates that a value is a valid absolute URI.
|
|
310
|
+
#
|
|
311
|
+
# @param field [String] The field name for error messages.
|
|
312
|
+
# @param value [String, nil] The value to validate.
|
|
313
|
+
#
|
|
314
|
+
# @raise [InvalidInputError] If the value is not a valid absolute URI.
|
|
315
|
+
#
|
|
316
|
+
# @return [nil]
|
|
180
317
|
def validate_uri(field, value)
|
|
181
318
|
return if !value
|
|
182
319
|
|
|
@@ -195,6 +332,6 @@ module Minfraud
|
|
|
195
332
|
end
|
|
196
333
|
# rubocop:enable Style/RescueStandardError
|
|
197
334
|
end
|
|
335
|
+
# rubocop:enable Metrics/ModuleLength
|
|
198
336
|
end
|
|
199
337
|
end
|
|
200
|
-
# rubocop:enable Metrics/ModuleLength
|
data/lib/minfraud/version.rb
CHANGED
data/lib/minfraud.rb
CHANGED
|
@@ -32,6 +32,9 @@ require 'minfraud/report'
|
|
|
32
32
|
# for the gem's classes.
|
|
33
33
|
module Minfraud
|
|
34
34
|
class << self
|
|
35
|
+
# rubocop:disable ThreadSafety/ClassAndModuleAttributes
|
|
36
|
+
# This is a false positive - these configuration attributes are set during initialization
|
|
37
|
+
|
|
35
38
|
# The MaxMind account ID that is used for authorization.
|
|
36
39
|
#
|
|
37
40
|
# @return [Integer, nil]
|
|
@@ -57,6 +60,8 @@ module Minfraud
|
|
|
57
60
|
# @return [String, nil]
|
|
58
61
|
attr_accessor :license_key
|
|
59
62
|
|
|
63
|
+
# rubocop:enable ThreadSafety/ClassAndModuleAttributes
|
|
64
|
+
|
|
60
65
|
# @!visibility private
|
|
61
66
|
attr_reader :connection_pool
|
|
62
67
|
|
|
@@ -67,8 +72,11 @@ module Minfraud
|
|
|
67
72
|
yield self
|
|
68
73
|
|
|
69
74
|
pool_size = 5
|
|
75
|
+
# rubocop:disable ThreadSafety/ClassInstanceVariable
|
|
76
|
+
# This is a false positive - this configuration is set during initialization
|
|
70
77
|
host = @host.nil? ? 'minfraud.maxmind.com' : @host
|
|
71
78
|
@connection_pool = ConnectionPool.new(size: pool_size) do
|
|
79
|
+
# rubocop:enable ThreadSafety/ClassInstanceVariable
|
|
72
80
|
make_http_client.persistent("https://#{host}")
|
|
73
81
|
end
|
|
74
82
|
end
|
|
@@ -76,10 +84,13 @@ module Minfraud
|
|
|
76
84
|
private
|
|
77
85
|
|
|
78
86
|
def make_http_client
|
|
87
|
+
# rubocop:disable ThreadSafety/ClassInstanceVariable
|
|
88
|
+
# This is a false positive - this configuration is set during initialization
|
|
79
89
|
HTTP.basic_auth(
|
|
80
90
|
user: @account_id,
|
|
81
91
|
pass: @license_key,
|
|
82
92
|
).headers(
|
|
93
|
+
# rubocop:enable ThreadSafety/ClassInstanceVariable
|
|
83
94
|
accept: 'application/json',
|
|
84
95
|
user_agent: "minfraud-api-ruby/#{Minfraud::VERSION} ruby/#{RUBY_VERSION} http/#{HTTP::VERSION}",
|
|
85
96
|
)
|