datadome_fraud_sdk_ruby 2.0.0 → 2.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.
- checksums.yaml +4 -4
- data/lib/constants.rb +1 -1
- data/lib/datadome_fraud_sdk_ruby.rb +15 -10
- data/lib/model/api/response.rb +19 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: adce930fd391e2f32e58b8b15fd98feb918cf04f8e4e0bc57352dfa9b1952c62
|
4
|
+
data.tar.gz: 9c9eda3c8e513e183981e1aa27531f8868ba5924a08b0e3962fd5d32885cadd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5144bd55b7d64299943395ecb279d2c6a6d835848b296fcebafe79ddbca7844c75d190fee4db456220d30cea609942c4e1c631b8e32d163c038adffb386e4d61
|
7
|
+
data.tar.gz: de07ed8c8839e8edc29c21cbf49024e14c937c33a112ecc6622002bb0057e27a01f46091986d1bb8bc0f789161a8bf3bd932fced7b1064dc6f263476ac9a678b
|
data/lib/constants.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
SDK_VERSION = '2.
|
1
|
+
SDK_VERSION = '2.2.0'
|
2
2
|
SDK_NAME = 'datadome_fraud_sdk_ruby'
|
@@ -33,22 +33,27 @@ class DataDome
|
|
33
33
|
body = JSON.parse(api_response.body) unless api_response.body.nil?
|
34
34
|
rescue JSON::ParserError => e
|
35
35
|
@logger.error("DataDome: error parsing JSON from Fraud API /validate #{e.message}")
|
36
|
-
return DataDomeResponseError.new(
|
36
|
+
return DataDomeResponseError.new(status: DataDomeResponseStatus::FAILURE, message: "DataDome: error parsing JSON from Fraud API", errors: e.message)
|
37
37
|
end
|
38
38
|
|
39
39
|
if api_response.success?
|
40
|
-
datadome_response = DataDomeResponseSuccess.new(
|
40
|
+
datadome_response = DataDomeResponseSuccess.new(status:DataDomeResponseStatus::OK, score:body["score"],
|
41
|
+
event_id:body["eventId"]&.to_s, reasons: body["reasons"], ip: body["ip"], location: DataDomeLocation.new(location: body["location"]))
|
41
42
|
if body["action"] === DataDomeResponseAction::DENY
|
42
43
|
datadome_response.action = DataDomeResponseAction::DENY
|
44
|
+
elsif body["action"] === DataDomeResponseAction::REVIEW
|
45
|
+
datadome_response.action = DataDomeResponseAction::REVIEW
|
46
|
+
elsif body["action"] === DataDomeResponseAction::CHALLENGE
|
47
|
+
datadome_response.action = DataDomeResponseAction::CHALLENGE
|
43
48
|
end
|
44
49
|
else
|
45
50
|
@logger.error("DataDome: error on Fraud API /validate response #{body["errors"]}")
|
46
|
-
return DataDomeResponseError.new(
|
51
|
+
return DataDomeResponseError.new(status: DataDomeResponseStatus::FAILURE, message: body["message"], errors: body["errors"].map { |error| DataDomeError.new(error) })
|
47
52
|
end
|
48
53
|
rescue Faraday::TimeoutError => e
|
49
|
-
return DataDomeResponseError.new(
|
54
|
+
return DataDomeResponseError.new(status: DataDomeResponseStatus::TIMEOUT, message: "DataDome Fraud API request timeout", errors: e.message)
|
50
55
|
rescue Faraday::ConnectionFailed => e
|
51
|
-
return DataDomeResponseError.new(
|
56
|
+
return DataDomeResponseError.new(status: DataDomeResponseStatus::FAILURE, message: "DataDome Fraud API request failed", errors: e.message)
|
52
57
|
end
|
53
58
|
|
54
59
|
datadome_response
|
@@ -65,21 +70,21 @@ class DataDome
|
|
65
70
|
api_response = send_request(DataDomeOperationType::COLLECT, event.action, payload)
|
66
71
|
|
67
72
|
if api_response.success?
|
68
|
-
datadome_response = DataDomeResponseSuccess.new(
|
73
|
+
datadome_response = DataDomeResponseSuccess.new(status: DataDomeResponseStatus::OK)
|
69
74
|
else
|
70
75
|
begin
|
71
76
|
body = JSON.parse(api_response.body)
|
72
77
|
@logger.error("DataDome: error on Fraud API /collect response #{body["errors"]}")
|
73
|
-
datadome_response = DataDomeResponseError.new(
|
78
|
+
datadome_response = DataDomeResponseError.new(status: DataDomeResponseStatus::FAILURE, message: body["message"], errors: body["errors"].map { |error| DataDomeError.new(error) })
|
74
79
|
rescue JSON::ParserError => e
|
75
80
|
@logger.error("DataDome: error parsing JSON from Fraud API /collect #{e.message}")
|
76
|
-
return DataDomeResponseError.new(
|
81
|
+
return DataDomeResponseError.new(status: DataDomeResponseStatus::FAILURE, message: "DataDome: error parsing JSON from Fraud API", errors: e.message)
|
77
82
|
end
|
78
83
|
end
|
79
84
|
rescue Faraday::TimeoutError => e
|
80
|
-
datadome_response = DataDomeResponseError.new(
|
85
|
+
datadome_response = DataDomeResponseError.new(status: DataDomeResponseStatus::TIMEOUT, message: "DataDome Fraud API request timeout", errors: e.message)
|
81
86
|
rescue Faraday::ConnectionFailed => e
|
82
|
-
datadome_response = DataDomeResponseError.new(
|
87
|
+
datadome_response = DataDomeResponseError.new(status: DataDomeResponseStatus::FAILURE, message: "DataDome Fraud API request failed", errors: e.message)
|
83
88
|
end
|
84
89
|
|
85
90
|
datadome_response
|
data/lib/model/api/response.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
module DataDomeResponseAction
|
4
4
|
ALLOW = "allow"
|
5
|
+
CHALLENGE = "challenge"
|
6
|
+
REVIEW = "review"
|
5
7
|
DENY = "deny"
|
6
8
|
end
|
7
9
|
|
@@ -21,21 +23,25 @@ class DataDomeError
|
|
21
23
|
end
|
22
24
|
|
23
25
|
class DataDomeResponse
|
24
|
-
attr_accessor :action, :status
|
26
|
+
attr_accessor :action, :score, :status, :event_id
|
25
27
|
|
26
|
-
def initialize(
|
27
|
-
@action =
|
28
|
+
def initialize(status:, score:nil, event_id:nil)
|
29
|
+
@action = DataDomeResponseAction::ALLOW
|
28
30
|
@status = status
|
31
|
+
@score = score
|
32
|
+
@event_id = event_id
|
29
33
|
end
|
30
34
|
|
31
35
|
def to_s
|
32
|
-
"DataDomeResponse: action=#{@action}, status=#{@status}"
|
36
|
+
"DataDomeResponse: action=#{@action}, score=#{@score}, status=#{@status}, event_id=#{@event_id}"
|
33
37
|
end
|
34
38
|
|
35
39
|
def to_json(options = {})
|
36
40
|
{
|
37
41
|
action: @action,
|
42
|
+
score: @score,
|
38
43
|
status: @status,
|
44
|
+
event_id: @event_id,
|
39
45
|
}.to_json
|
40
46
|
end
|
41
47
|
end
|
@@ -43,21 +49,23 @@ end
|
|
43
49
|
class DataDomeResponseSuccess < DataDomeResponse
|
44
50
|
attr_reader :ip, :reasons, :location
|
45
51
|
|
46
|
-
def initialize(
|
47
|
-
super(
|
52
|
+
def initialize(status:, score:, event_id:, reasons:, ip:, location:)
|
53
|
+
super(status: status, score: score, event_id: event_id)
|
48
54
|
@reasons = reasons
|
49
55
|
@ip = ip
|
50
56
|
@location = location
|
51
57
|
end
|
52
58
|
|
53
59
|
def to_s
|
54
|
-
"DataDomeResponseSuccess: action=#{@action}, status=#{@status}, reasons=#{@reasons}, ip=#{@ip}, location=#{@location}"
|
60
|
+
"DataDomeResponseSuccess: action=#{@action}, score=#{@score}, status=#{@status}, event_id=#{@event_id}, reasons=#{@reasons}, ip=#{@ip}, location=#{@location}"
|
55
61
|
end
|
56
62
|
|
57
63
|
def to_json(options = {})
|
58
64
|
{
|
59
65
|
action: @action,
|
66
|
+
score: @score,
|
60
67
|
status: @status,
|
68
|
+
event_id: @event_id,
|
61
69
|
reasons: @reasons,
|
62
70
|
ip: @ip,
|
63
71
|
location: @location,
|
@@ -68,19 +76,20 @@ end
|
|
68
76
|
class DataDomeResponseError < DataDomeResponse
|
69
77
|
attr_reader :message, :errors
|
70
78
|
|
71
|
-
def initialize(
|
72
|
-
super(
|
79
|
+
def initialize(status:, message:, errors:)
|
80
|
+
super(status: status)
|
73
81
|
@message = message
|
74
82
|
@errors = errors
|
75
83
|
end
|
76
84
|
|
77
85
|
def to_s
|
78
|
-
"DataDomeResponseError: action=#{@action}, status=#{@status}, message=#{@message}, errors=#{@errors}"
|
86
|
+
"DataDomeResponseError: action=#{@action}, score=#{@score}, status=#{@status}, message=#{@message}, errors=#{@errors}"
|
79
87
|
end
|
80
88
|
|
81
89
|
def to_json(options = {})
|
82
90
|
{
|
83
91
|
action: @action,
|
92
|
+
score: @score,
|
84
93
|
status: @status,
|
85
94
|
message: @message,
|
86
95
|
errors: @errors,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datadome_fraud_sdk_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DataDome
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-05
|
11
|
+
date: 2024-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|