yoti_sandbox 1.0.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/README.md +8 -1
  4. data/lib/yoti_sandbox.rb +1 -0
  5. data/lib/yoti_sandbox/doc_scan.rb +25 -0
  6. data/lib/yoti_sandbox/doc_scan/client.rb +59 -0
  7. data/lib/yoti_sandbox/doc_scan/errors.rb +83 -0
  8. data/lib/yoti_sandbox/doc_scan/request/check/check.rb +115 -0
  9. data/lib/yoti_sandbox/doc_scan/request/check/document_authenticity_check.rb +29 -0
  10. data/lib/yoti_sandbox/doc_scan/request/check/document_check.rb +48 -0
  11. data/lib/yoti_sandbox/doc_scan/request/check/document_face_match_check.rb +29 -0
  12. data/lib/yoti_sandbox/doc_scan/request/check/document_text_data_check.rb +78 -0
  13. data/lib/yoti_sandbox/doc_scan/request/check/id_document_comparison_check.rb +56 -0
  14. data/lib/yoti_sandbox/doc_scan/request/check/liveness_check.rb +34 -0
  15. data/lib/yoti_sandbox/doc_scan/request/check/report/breakdown.rb +97 -0
  16. data/lib/yoti_sandbox/doc_scan/request/check/report/detail.rb +34 -0
  17. data/lib/yoti_sandbox/doc_scan/request/check/report/recommendation.rb +88 -0
  18. data/lib/yoti_sandbox/doc_scan/request/check/supplementary_document_text_data_check.rb +78 -0
  19. data/lib/yoti_sandbox/doc_scan/request/check/zoom_liveness_check.rb +36 -0
  20. data/lib/yoti_sandbox/doc_scan/request/check_reports.rb +182 -0
  21. data/lib/yoti_sandbox/doc_scan/request/document_filter.rb +77 -0
  22. data/lib/yoti_sandbox/doc_scan/request/response_config.rb +75 -0
  23. data/lib/yoti_sandbox/doc_scan/request/task/document_id_photo.rb +35 -0
  24. data/lib/yoti_sandbox/doc_scan/request/task/document_text_data_extraction_task.rb +170 -0
  25. data/lib/yoti_sandbox/doc_scan/request/task/supplementary_document_text_data_extraction_task.rb +152 -0
  26. data/lib/yoti_sandbox/doc_scan/request/task/text_data_extraction_reason.rb +78 -0
  27. data/lib/yoti_sandbox/doc_scan/request/task/text_data_extraction_recommendation.rb +86 -0
  28. data/lib/yoti_sandbox/doc_scan/request/task_results.rb +96 -0
  29. data/lib/yoti_sandbox/profile.rb +5 -0
  30. data/lib/yoti_sandbox/profile/age_verification.rb +7 -0
  31. data/lib/yoti_sandbox/profile/client.rb +8 -26
  32. data/lib/yoti_sandbox/profile/document_images.rb +69 -0
  33. data/lib/yoti_sandbox/profile/extra_data.rb +92 -0
  34. data/lib/yoti_sandbox/profile/third_party.rb +158 -0
  35. data/lib/yoti_sandbox/profile/token_request.rb +47 -6
  36. data/yoti_sandbox.gemspec +18 -5
  37. metadata +38 -18
  38. data/.github/ISSUE_TEMPLATE.md +0 -17
  39. data/.gitignore +0 -56
  40. data/CONTRIBUTING.md +0 -30
  41. data/Guardfile +0 -11
  42. data/Rakefile +0 -41
  43. data/rubocop.yml +0 -44
  44. data/yardstick.yml +0 -9
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yoti
4
+ module Sandbox
5
+ module DocScan
6
+ module Request
7
+ class IdDocumentComparisonCheck < Check
8
+ #
9
+ # @param [CheckResult] result
10
+ # @param [DocumentFilter] secondary_document_filter
11
+ #
12
+ def initialize(result, secondary_document_filter)
13
+ super(result)
14
+
15
+ Validation.assert_is_a(DocumentFilter, secondary_document_filter, 'secondary_document_filter', true)
16
+ @secondary_document_filter = secondary_document_filter
17
+ end
18
+
19
+ def as_json(*_args)
20
+ json = super
21
+ json[:secondary_document_filter] = @secondary_document_filter.as_json unless @secondary_document_filter.nil?
22
+ json
23
+ end
24
+
25
+ #
26
+ # @return [IdDocumentComparisonCheckBuilder]
27
+ #
28
+ def self.builder
29
+ IdDocumentComparisonCheckBuilder.new
30
+ end
31
+ end
32
+
33
+ class IdDocumentComparisonCheckBuilder < CheckBuilder
34
+ #
35
+ # @param [DocumentFilter] secondary_document_filter
36
+ #
37
+ # @return [self]
38
+ #
39
+ def with_secondary_document_filter(secondary_document_filter)
40
+ @secondary_document_filter = secondary_document_filter
41
+ self
42
+ end
43
+
44
+ #
45
+ # @return [IdDocumentComparisonCheck]
46
+ #
47
+ def build
48
+ report = CheckReport.new(@recommendation, @breakdowns)
49
+ result = CheckResult.new(report)
50
+ IdDocumentComparisonCheck.new(result, @secondary_document_filter)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yoti
4
+ module Sandbox
5
+ module DocScan
6
+ module Request
7
+ class LivenessCheck < Check
8
+ #
9
+ # @param [CheckResult] result
10
+ # @param [String] liveness_type
11
+ #
12
+ def initialize(result, liveness_type)
13
+ raise(TypeError, "#{self.class} cannot be instantiated") if instance_of?(LivenessCheck)
14
+
15
+ super(result)
16
+
17
+ Validation.assert_is_a(String, liveness_type, 'liveness_type')
18
+ @liveness_type = liveness_type
19
+ end
20
+
21
+ def to_json(*_args)
22
+ as_json.to_json
23
+ end
24
+
25
+ def as_json(*_args)
26
+ super.merge(
27
+ liveness_type: @liveness_type
28
+ ).compact
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yoti
4
+ module Sandbox
5
+ module DocScan
6
+ module Request
7
+ class Breakdown
8
+ #
9
+ # @param [String] sub_check
10
+ # @param [String] result
11
+ # @param [Array<Detail>] details
12
+ #
13
+ def initialize(sub_check, result, details)
14
+ Validation.assert_is_a(String, sub_check, 'sub_check')
15
+ @sub_check = sub_check
16
+
17
+ Validation.assert_is_a(String, result, 'result')
18
+ @result = result
19
+
20
+ Validation.assert_is_a(Array, details, 'details')
21
+ @details = details
22
+ end
23
+
24
+ def as_json(*_args)
25
+ {
26
+ sub_check: @sub_check,
27
+ result: @result,
28
+ details: @details.map(&:as_json)
29
+ }
30
+ end
31
+
32
+ def to_json(*_args)
33
+ as_json.to_json
34
+ end
35
+
36
+ #
37
+ # @return [BreakdownBuilder]
38
+ #
39
+ def self.builder
40
+ BreakdownBuilder.new
41
+ end
42
+ end
43
+
44
+ class BreakdownBuilder
45
+ def initialize
46
+ @details = []
47
+ end
48
+
49
+ #
50
+ # @param [String] sub_check
51
+ #
52
+ # @return [self]
53
+ #
54
+ def with_sub_check(sub_check)
55
+ Validation.assert_is_a(String, sub_check, 'sub_check')
56
+ @sub_check = sub_check
57
+ self
58
+ end
59
+
60
+ #
61
+ # @param [String] result
62
+ #
63
+ # @return [self]
64
+ #
65
+ def with_result(result)
66
+ Validation.assert_is_a(String, result, 'result')
67
+ @result = result
68
+ self
69
+ end
70
+
71
+ #
72
+ # @param [String] name
73
+ # @param [String] value
74
+ #
75
+ # @return [self]
76
+ #
77
+ def with_detail(name, value)
78
+ Validation.assert_is_a(String, name, 'name')
79
+ Validation.assert_is_a(String, value, 'value')
80
+ @details.push(Detail.new(name, value))
81
+ self
82
+ end
83
+
84
+ #
85
+ # @return [Breakdown]
86
+ #
87
+ def build
88
+ Validation.assert_not_nil(@sub_check, 'sub_check')
89
+ Validation.assert_not_nil(@result, 'result')
90
+
91
+ Breakdown.new(@sub_check, @result, @details)
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yoti
4
+ module Sandbox
5
+ module DocScan
6
+ module Request
7
+ class Detail
8
+ #
9
+ # @param [String] name
10
+ # @param [String] value
11
+ #
12
+ def initialize(name, value)
13
+ Validation.assert_is_a(String, name, 'name')
14
+ @name = name
15
+
16
+ Validation.assert_is_a(String, value, 'value')
17
+ @value = value
18
+ end
19
+
20
+ def as_json(*_args)
21
+ {
22
+ name: @name,
23
+ value: @value
24
+ }
25
+ end
26
+
27
+ def to_json(*_args)
28
+ as_json.to_json
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yoti
4
+ module Sandbox
5
+ module DocScan
6
+ module Request
7
+ class Recommendation
8
+ #
9
+ # @param [String] value
10
+ # @param [String] reason
11
+ # @param [String] recovery_suggestion
12
+ #
13
+ def initialize(value, reason, recovery_suggestion)
14
+ Validation.assert_is_a(String, value, 'value')
15
+ @value = value
16
+
17
+ Validation.assert_is_a(String, reason, 'reason', true)
18
+ @reason = reason
19
+
20
+ Validation.assert_is_a(String, recovery_suggestion, 'recovery_suggestion', true)
21
+ @recovery_suggestion = recovery_suggestion
22
+ end
23
+
24
+ def as_json(*_args)
25
+ {
26
+ value: @value,
27
+ reason: @reason,
28
+ recovery_suggestion: @recovery_suggestion
29
+ }.compact
30
+ end
31
+
32
+ def to_json(*_args)
33
+ as_json.to_json
34
+ end
35
+
36
+ #
37
+ # @return [RecommendationBuilder]
38
+ #
39
+ def self.builder
40
+ RecommendationBuilder.new
41
+ end
42
+ end
43
+
44
+ class RecommendationBuilder
45
+ #
46
+ # @param [String] value
47
+ #
48
+ # @return [self]
49
+ #
50
+ def with_value(value)
51
+ Validation.assert_is_a(String, value, 'value')
52
+ @value = value
53
+ self
54
+ end
55
+
56
+ #
57
+ # @param [String] reason
58
+ #
59
+ # @return [self]
60
+ #
61
+ def with_reason(reason)
62
+ Validation.assert_is_a(String, reason, 'reason')
63
+ @reason = reason
64
+ self
65
+ end
66
+
67
+ #
68
+ # @param [String] recovery_suggestion
69
+ #
70
+ # @return [self]
71
+ #
72
+ def with_recovery_suggestion(recovery_suggestion)
73
+ Validation.assert_is_a(String, recovery_suggestion, 'recovery_suggestion')
74
+ @recovery_suggestion = recovery_suggestion
75
+ self
76
+ end
77
+
78
+ #
79
+ # @return [Recommendation]
80
+ #
81
+ def build
82
+ Recommendation.new(@value, @reason, @recovery_suggestion)
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ module Yoti
6
+ module Sandbox
7
+ module DocScan
8
+ module Request
9
+ class SupplementaryDocumentTextDataCheck < DocumentCheck
10
+ #
11
+ # @return [SupplementaryDocumentTextDataCheckBuilder]
12
+ #
13
+ def self.builder
14
+ SupplementaryDocumentTextDataCheckBuilder.new
15
+ end
16
+ end
17
+
18
+ class SupplementaryDocumentTextDataCheckResult < CheckResult
19
+ #
20
+ # @param [CheckReport] report
21
+ # @param [Hash,nil] document_fields
22
+ #
23
+ def initialize(report, document_fields)
24
+ super(report)
25
+
26
+ unless document_fields.nil?
27
+ Validation.assert_is_a(Hash, document_fields, 'document_fields')
28
+ document_fields.each { |_k, v| Validation.assert_respond_to(:to_json, v, 'document_fields value') }
29
+ end
30
+ @document_fields = document_fields
31
+ end
32
+
33
+ def as_json(*_args)
34
+ super.merge(
35
+ document_fields: @document_fields
36
+ ).compact
37
+ end
38
+ end
39
+
40
+ class SupplementaryDocumentTextDataCheckBuilder < DocumentCheckBuilder
41
+ #
42
+ # @param [String] key
43
+ # @param [#to_json] value
44
+ #
45
+ # @return [self]
46
+ #
47
+ def with_document_field(key, value)
48
+ Validation.assert_is_a(String, key, 'key')
49
+ Validation.assert_respond_to(:to_json, value, 'value')
50
+ @document_fields ||= {}
51
+ @document_fields[key] = value
52
+ self
53
+ end
54
+
55
+ #
56
+ # @param [Hash] document_fields
57
+ #
58
+ # @return [self]
59
+ #
60
+ def with_document_fields(document_fields)
61
+ Validation.assert_is_a(Hash, document_fields, 'document_fields')
62
+ @document_fields = document_fields
63
+ self
64
+ end
65
+
66
+ #
67
+ # @return [SupplementaryDocumentTextDataCheck]
68
+ #
69
+ def build
70
+ report = CheckReport.new(@recommendation, @breakdowns)
71
+ result = SupplementaryDocumentTextDataCheckResult.new(report, @document_fields)
72
+ SupplementaryDocumentTextDataCheck.new(result, @document_filter)
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yoti
4
+ module Sandbox
5
+ module DocScan
6
+ module Request
7
+ class ZoomLivenessCheck < LivenessCheck
8
+ #
9
+ # @param [CheckResult] result
10
+ #
11
+ def initialize(result)
12
+ super(result, Yoti::DocScan::Constants::ZOOM)
13
+ end
14
+
15
+ #
16
+ # @return [ZoomLivenessCheckBuilder]
17
+ #
18
+ def self.builder
19
+ ZoomLivenessCheckBuilder.new
20
+ end
21
+ end
22
+
23
+ class ZoomLivenessCheckBuilder < CheckBuilder
24
+ #
25
+ # @return [ZoomLivenessCheck]
26
+ #
27
+ def build
28
+ report = CheckReport.new(@recommendation, @breakdowns)
29
+ result = CheckResult.new(report)
30
+ ZoomLivenessCheck.new(result)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,182 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yoti
4
+ module Sandbox
5
+ module DocScan
6
+ module Request
7
+ class CheckReports
8
+ #
9
+ # @param [Array<DocumentTextDataCheck>] document_text_data_checks
10
+ # @param [Array<DocumentAuthenticityCheck>] document_authenticity_checks
11
+ # @param [Array<LivenessCheck>] liveness_checks
12
+ # @param [Array<DocumentFaceMatchCheck>] document_face_match_checks
13
+ # @param [Integer] async_report_delay
14
+ # @param [Array<IdDocumentComparisonCheck>] id_document_comparison_checks
15
+ #
16
+ def initialize(
17
+ document_text_data_checks,
18
+ document_authenticity_checks,
19
+ liveness_checks,
20
+ document_face_match_checks,
21
+ async_report_delay,
22
+ id_document_comparison_checks = nil,
23
+ supplementary_document_text_data_checks = nil
24
+ )
25
+ Validation.assert_is_a(Array, document_text_data_checks, 'document_text_data_checks')
26
+ @document_text_data_checks = document_text_data_checks
27
+
28
+ Validation.assert_is_a(Array, document_authenticity_checks, 'document_authenticity_checks')
29
+ @document_authenticity_checks = document_authenticity_checks
30
+
31
+ Validation.assert_is_a(Array, liveness_checks, 'liveness_checks')
32
+ @liveness_checks = liveness_checks
33
+
34
+ Validation.assert_is_a(Array, document_face_match_checks, 'document_face_match_checks')
35
+ @document_face_match_checks = document_face_match_checks
36
+
37
+ Validation.assert_is_a(Integer, async_report_delay, 'async_report_delay', true)
38
+ @async_report_delay = async_report_delay
39
+
40
+ Validation.assert_is_a(Array, id_document_comparison_checks, 'id_document_comparison_checks', true)
41
+ @id_document_comparison_checks = id_document_comparison_checks
42
+
43
+ Validation.assert_is_a(
44
+ Array,
45
+ supplementary_document_text_data_checks,
46
+ 'supplementary_document_text_data_checks',
47
+ true
48
+ )
49
+ @supplementary_document_text_data_checks = supplementary_document_text_data_checks
50
+ end
51
+
52
+ def self.builder
53
+ CheckReportsBuilder.new
54
+ end
55
+
56
+ def to_json(*_args)
57
+ as_json.to_json
58
+ end
59
+
60
+ def as_json(*_args)
61
+ {
62
+ ID_DOCUMENT_TEXT_DATA_CHECK: @document_text_data_checks,
63
+ ID_DOCUMENT_AUTHENTICITY: @document_authenticity_checks,
64
+ ID_DOCUMENT_FACE_MATCH: @document_face_match_checks,
65
+ LIVENESS: @liveness_checks,
66
+ ID_DOCUMENT_COMPARISON: @id_document_comparison_checks,
67
+ SUPPLEMENTARY_DOCUMENT_TEXT_DATA_CHECK: @supplementary_document_text_data_checks,
68
+ async_report_delay: @async_report_delay
69
+ }.compact
70
+ end
71
+ end
72
+
73
+ class CheckReportsBuilder
74
+ def initialize
75
+ @liveness_checks = []
76
+ @document_text_data_checks = []
77
+ @document_authenticity_checks = []
78
+ @document_face_match_checks = []
79
+ @id_document_comparison_checks = []
80
+ @supplementary_document_text_data_checks = []
81
+ end
82
+
83
+ #
84
+ # @param [LivenessCheck] liveness_check
85
+ #
86
+ # @return [self]
87
+ #
88
+ def with_liveness_check(liveness_check)
89
+ Validation.assert_is_a(LivenessCheck, liveness_check, 'liveness_check')
90
+ @liveness_checks << liveness_check
91
+ self
92
+ end
93
+
94
+ #
95
+ # @param [DocumentTextDataCheck] document_text_data_check
96
+ #
97
+ # @return [self]
98
+ #
99
+ def with_document_text_data_check(document_text_data_check)
100
+ Validation.assert_is_a(DocumentTextDataCheck, document_text_data_check, 'document_text_data_check')
101
+ @document_text_data_checks << document_text_data_check
102
+ self
103
+ end
104
+
105
+ #
106
+ # @param [DocumentAuthenticityCheck] document_authenticity_check
107
+ #
108
+ # @return [self]
109
+ #
110
+ def with_document_authenticity_check(document_authenticity_check)
111
+ Validation.assert_is_a(DocumentAuthenticityCheck, document_authenticity_check, 'document_authenticity_check')
112
+ @document_authenticity_checks << document_authenticity_check
113
+ self
114
+ end
115
+
116
+ #
117
+ # @param [DocumentFaceMatchCheck] document_face_match_check
118
+ #
119
+ # @return [self]
120
+ #
121
+ def with_document_face_match_check(document_face_match_check)
122
+ Validation.assert_is_a(DocumentFaceMatchCheck, document_face_match_check, 'document_face_match_check')
123
+ @document_face_match_checks << document_face_match_check
124
+ self
125
+ end
126
+
127
+ #
128
+ # @param [Integer] async_report_delay
129
+ #
130
+ # @return [self]
131
+ #
132
+ def with_async_report_delay(async_report_delay)
133
+ Validation.assert_is_a(Integer, async_report_delay, 'async_report_delay')
134
+ @async_report_delay = async_report_delay
135
+ self
136
+ end
137
+
138
+ #
139
+ # @param [IdDocumentComparisonCheck] id_document_comparison_check
140
+ #
141
+ # @return [self]
142
+ #
143
+ def with_id_document_comparison_check(id_document_comparison_check)
144
+ Validation.assert_is_a(IdDocumentComparisonCheck, id_document_comparison_check, 'id_document_comparison_check')
145
+ @id_document_comparison_checks << id_document_comparison_check
146
+ self
147
+ end
148
+
149
+ #
150
+ # @param [SupplementaryDocumentTextDataCheck] supplementary_document_text_data_check
151
+ #
152
+ # @return [self]
153
+ #
154
+ def with_supplementary_document_text_data_check(supplementary_document_text_data_check)
155
+ Validation.assert_is_a(
156
+ SupplementaryDocumentTextDataCheck,
157
+ supplementary_document_text_data_check,
158
+ 'supplementary_document_text_data_check'
159
+ )
160
+ @supplementary_document_text_data_checks << supplementary_document_text_data_check
161
+ self
162
+ end
163
+
164
+ #
165
+ # @return [CheckReports]
166
+ #
167
+ def build
168
+ CheckReports.new(
169
+ @document_text_data_checks,
170
+ @document_authenticity_checks,
171
+ @liveness_checks,
172
+ @document_face_match_checks,
173
+ @async_report_delay,
174
+ @id_document_comparison_checks,
175
+ @supplementary_document_text_data_checks
176
+ )
177
+ end
178
+ end
179
+ end
180
+ end
181
+ end
182
+ end