-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdevice.rb
More file actions
75 lines (63 loc) · 2.43 KB
/
Copy pathdevice.rb
File metadata and controls
75 lines (63 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# frozen_string_literal: true
module Minfraud
module Components
# Device corresponds to the device object of a minFraud request.
#
# @see https://dev.maxmind.com/minfraud/api-documentation/requests/?lang=en#schema--request--device
class Device < Base
include Minfraud::Validates
# The IP address associated with the device used by the customer in the
# transaction. The IP address must be in IPv4 or IPv6 presentation
# format, i.e., dotted-quad notation or the IPv6 hexadecimal-colon
# notation.
#
# @return [String, nil]
attr_accessor :ip_address
# The HTTP "User-Agent" header of the browser used in the transaction.
#
# @return [String, nil]
attr_accessor :user_agent
# The HTTP "Accept-Language" header of the browser used in the
# transaction.
#
# @return [String, nil]
attr_accessor :accept_language
# The number of seconds between the creation of the user's session and
# the time of the transaction. Note that session_age is not the duration
# of the current visit, but the time since the start of the first visit.
# The value must be at least 0 and at most 10^13-1.
#
# @return [Float, nil]
attr_accessor :session_age
# An ID that uniquely identifies a visitor's session on the site.
#
# @return [String, nil]
attr_accessor :session_id
# The token generated by the Device Tracking Add-on for explicit
# device linking.
#
# @return [String, nil]
attr_accessor :tracking_token
# @param params [Hash] Hash of parameters. Each key/value should
# correspond to one of the available attributes.
def initialize(params = {})
@ip_address = params[:ip_address]
@user_agent = params[:user_agent]
@accept_language = params[:accept_language]
@session_age = params[:session_age]
@session_id = params[:session_id]
@tracking_token = params[:tracking_token]
validate
end
private
def validate
return if !Minfraud.enable_validation
validate_ip('ip_address', @ip_address)
validate_string('user_agent', 512, @user_agent)
validate_string('accept_language', 255, @accept_language)
validate_nonnegative_number('session_age', @session_age)
validate_string('session_id', 255, @session_id)
end
end
end
end