yoti 1.6.4 → 1.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/Gemfile +1 -1
- data/README.md +22 -224
- data/lib/yoti.rb +63 -1
- data/lib/yoti/activity_details.rb +3 -5
- data/lib/yoti/client.rb +13 -4
- data/lib/yoti/configuration.rb +8 -3
- data/lib/yoti/data_type/age_verification.rb +1 -1
- data/lib/yoti/data_type/base_profile.rb +1 -1
- data/lib/yoti/data_type/document_details.rb +1 -1
- data/lib/yoti/data_type/image.rb +4 -12
- data/lib/yoti/data_type/image_jpeg.rb +2 -0
- data/lib/yoti/data_type/image_png.rb +2 -0
- data/lib/yoti/data_type/media.rb +22 -0
- data/lib/yoti/data_type/signed_time_stamp.rb +1 -1
- data/lib/yoti/doc_scan/client.rb +191 -0
- data/lib/yoti/doc_scan/constants.rb +35 -0
- data/lib/yoti/doc_scan/errors.rb +81 -0
- data/lib/yoti/doc_scan/session/create/create_session_result.rb +50 -0
- data/lib/yoti/doc_scan/session/create/document_filter.rb +31 -0
- data/lib/yoti/doc_scan/session/create/document_restrictions_filter.rb +140 -0
- data/lib/yoti/doc_scan/session/create/notification_config.rb +142 -0
- data/lib/yoti/doc_scan/session/create/objective/objective.rb +31 -0
- data/lib/yoti/doc_scan/session/create/objective/proof_of_address_objective.rb +31 -0
- data/lib/yoti/doc_scan/session/create/orthogonal_restrictions_filter.rb +150 -0
- data/lib/yoti/doc_scan/session/create/requested_check.rb +39 -0
- data/lib/yoti/doc_scan/session/create/requested_document_authenticity_check.rb +95 -0
- data/lib/yoti/doc_scan/session/create/requested_face_match_check.rb +95 -0
- data/lib/yoti/doc_scan/session/create/requested_id_document_comparison_check.rb +53 -0
- data/lib/yoti/doc_scan/session/create/requested_liveness_check.rb +108 -0
- data/lib/yoti/doc_scan/session/create/requested_supplementary_doc_text_extraction_task.rb +94 -0
- data/lib/yoti/doc_scan/session/create/requested_task.rb +39 -0
- data/lib/yoti/doc_scan/session/create/requested_text_extraction_task.rb +116 -0
- data/lib/yoti/doc_scan/session/create/required_document.rb +31 -0
- data/lib/yoti/doc_scan/session/create/required_id_document.rb +53 -0
- data/lib/yoti/doc_scan/session/create/required_supplementary_document.rb +90 -0
- data/lib/yoti/doc_scan/session/create/sdk_config.rb +221 -0
- data/lib/yoti/doc_scan/session/create/session_specification.rb +221 -0
- data/lib/yoti/doc_scan/session/retrieve/authenticity_check_response.rb +12 -0
- data/lib/yoti/doc_scan/session/retrieve/breakdown_response.rb +38 -0
- data/lib/yoti/doc_scan/session/retrieve/check_response.rb +63 -0
- data/lib/yoti/doc_scan/session/retrieve/details_response.rb +28 -0
- data/lib/yoti/doc_scan/session/retrieve/document_fields_response.rb +21 -0
- data/lib/yoti/doc_scan/session/retrieve/document_id_photo_response.rb +21 -0
- data/lib/yoti/doc_scan/session/retrieve/face_map_response.rb +21 -0
- data/lib/yoti/doc_scan/session/retrieve/face_match_check_response.rb +12 -0
- data/lib/yoti/doc_scan/session/retrieve/file_response.rb +21 -0
- data/lib/yoti/doc_scan/session/retrieve/frame_response.rb +21 -0
- data/lib/yoti/doc_scan/session/retrieve/generated_check_response.rb +28 -0
- data/lib/yoti/doc_scan/session/retrieve/generated_media.rb +28 -0
- data/lib/yoti/doc_scan/session/retrieve/generated_supplementary_document_text_data_check_response.rb +12 -0
- data/lib/yoti/doc_scan/session/retrieve/generated_text_data_check_response.rb +12 -0
- data/lib/yoti/doc_scan/session/retrieve/get_session_result.rb +145 -0
- data/lib/yoti/doc_scan/session/retrieve/id_document_comparison_check_response.rb +12 -0
- data/lib/yoti/doc_scan/session/retrieve/id_document_resource_response.rb +57 -0
- data/lib/yoti/doc_scan/session/retrieve/liveness_check_response.rb +12 -0
- data/lib/yoti/doc_scan/session/retrieve/liveness_resource_response.rb +24 -0
- data/lib/yoti/doc_scan/session/retrieve/media_response.rb +38 -0
- data/lib/yoti/doc_scan/session/retrieve/page_response.rb +37 -0
- data/lib/yoti/doc_scan/session/retrieve/recommendation_response.rb +34 -0
- data/lib/yoti/doc_scan/session/retrieve/report_response.rb +31 -0
- data/lib/yoti/doc_scan/session/retrieve/resource_container.rb +69 -0
- data/lib/yoti/doc_scan/session/retrieve/resource_response.rb +41 -0
- data/lib/yoti/doc_scan/session/retrieve/supplementary_document_resource_response.rb +57 -0
- data/lib/yoti/doc_scan/session/retrieve/supplementary_document_text_data_check_response.rb +12 -0
- data/lib/yoti/doc_scan/session/retrieve/supplementary_document_text_extraction_task_response.rb +18 -0
- data/lib/yoti/doc_scan/session/retrieve/task_response.rb +89 -0
- data/lib/yoti/doc_scan/session/retrieve/text_data_check_response.rb +12 -0
- data/lib/yoti/doc_scan/session/retrieve/text_extraction_task_response.rb +18 -0
- data/lib/yoti/doc_scan/session/retrieve/zoom_liveness_resource_response.rb +33 -0
- data/lib/yoti/doc_scan/support/supported_documents.rb +60 -0
- data/lib/yoti/dynamic_share_service/dynamic_scenario.rb +5 -0
- data/lib/yoti/dynamic_share_service/extension/extension.rb +3 -0
- data/lib/yoti/dynamic_share_service/extension/location_constraint_extension.rb +3 -0
- data/lib/yoti/dynamic_share_service/extension/thirdparty_attribute_extension.rb +1 -1
- data/lib/yoti/dynamic_share_service/extension/transactional_flow_extension.rb +4 -0
- data/lib/yoti/dynamic_share_service/policy/dynamic_policy.rb +74 -9
- data/lib/yoti/dynamic_share_service/policy/wanted_anchor.rb +3 -0
- data/lib/yoti/dynamic_share_service/policy/wanted_attribute.rb +5 -0
- data/lib/yoti/dynamic_share_service/share_url.rb +26 -33
- data/lib/yoti/errors.rb +15 -2
- data/lib/yoti/http/aml_check_request.rb +12 -6
- data/lib/yoti/http/payloads/aml_address.rb +4 -0
- data/lib/yoti/http/payloads/aml_profile.rb +7 -1
- data/lib/yoti/http/profile_request.rb +11 -6
- data/lib/yoti/http/request.rb +219 -18
- data/lib/yoti/http/signed_request.rb +13 -4
- data/lib/yoti/protobuf/main.rb +8 -8
- data/lib/yoti/share/attribute_issuance_details.rb +6 -0
- data/lib/yoti/ssl.rb +4 -4
- data/lib/yoti/util/age_processor.rb +1 -1
- data/lib/yoti/util/anchor_processor.rb +2 -2
- data/lib/yoti/util/log.rb +1 -1
- data/lib/yoti/util/validation.rb +41 -0
- data/lib/yoti/version.rb +1 -1
- data/yoti.gemspec +18 -6
- metadata +69 -33
- data/.github/ISSUE_TEMPLATE.md +0 -17
- data/.gitignore +0 -39
- data/CONTRIBUTING.md +0 -98
- data/Guardfile +0 -11
- data/Rakefile +0 -54
- data/login_flow.png +0 -0
- data/rubocop.yml +0 -57
- data/yardstick.yml +0 -9
data/lib/yoti/configuration.rb
CHANGED
@@ -3,7 +3,7 @@ module Yoti
|
|
3
3
|
attr_accessor :client_sdk_id, :key_file_path, :key, :sdk_identifier,
|
4
4
|
:api_url, :api_port, :api_version
|
5
5
|
|
6
|
-
attr_writer :api_endpoint
|
6
|
+
attr_writer :api_endpoint, :doc_scan_api_endpoint
|
7
7
|
|
8
8
|
# Set config variables by using a configuration block
|
9
9
|
def initialize
|
@@ -18,7 +18,12 @@ module Yoti
|
|
18
18
|
|
19
19
|
# @return [String] the API endpoint for the selected API version
|
20
20
|
def api_endpoint
|
21
|
-
@api_endpoint ||= "#{@api_url}/api/#{@api_version}"
|
21
|
+
@api_endpoint ||= ENV['YOTI_API_URL'] || "#{@api_url}/api/#{@api_version}"
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [String] the Doc Scan API endpoint
|
25
|
+
def doc_scan_api_endpoint
|
26
|
+
@doc_scan_api_endpoint ||= ENV['YOTI_DOC_SCAN_API_URL'] || "#{@api_url}/idverify/#{@api_version}"
|
22
27
|
end
|
23
28
|
|
24
29
|
# Validates the configuration values set in instance variables
|
@@ -51,7 +56,7 @@ module Yoti
|
|
51
56
|
|
52
57
|
return if valid.any?
|
53
58
|
|
54
|
-
config_list = required_configs.map { |conf|
|
59
|
+
config_list = required_configs.map { |conf| "`#{conf}`" }.join(', ')
|
55
60
|
message = "At least one of the configuration values has to be set: #{config_list}."
|
56
61
|
raise ConfigurationError, message
|
57
62
|
end
|
@@ -37,7 +37,7 @@ module Yoti
|
|
37
37
|
attr_reader :age
|
38
38
|
|
39
39
|
#
|
40
|
-
# @param [Yoti::Attribute]
|
40
|
+
# @param [Yoti::Attribute] attribute
|
41
41
|
#
|
42
42
|
def initialize(attribute)
|
43
43
|
raise(ArgumentError, "'#{attribute.name}' is not a valid age verification") unless /^[^:]+:(?!.*:)[0-9]+$/.match?(attribute.name)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Yoti
|
2
2
|
class DocumentDetails
|
3
3
|
#
|
4
|
-
# @deprecated 2.0.0 pattern is no longer used for validation.
|
4
|
+
# @deprecated will be removed in 2.0.0 - pattern is no longer used for validation.
|
5
5
|
#
|
6
6
|
VALIDATION_PATTERN = '^([A-Za-z_]*) ([A-Za-z]{3}) ([A-Za-z0-9]{1}).*$'
|
7
7
|
|
data/lib/yoti/data_type/image.rb
CHANGED
@@ -1,19 +1,11 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Yoti
|
4
|
-
class Image
|
5
|
-
attr_reader :content
|
6
|
-
attr_reader :mime_type
|
7
|
-
|
4
|
+
class Image < Media
|
8
5
|
def initialize(content, mime_type)
|
9
|
-
raise(TypeError,
|
10
|
-
|
11
|
-
@content = content
|
12
|
-
@mime_type = mime_type
|
13
|
-
end
|
6
|
+
raise(TypeError, "#{self.class} is an abstract class, so cannot be instantiated") if instance_of?(Image)
|
14
7
|
|
15
|
-
|
16
|
-
"data:#{mime_type};base64,#{Base64.strict_encode64(content)}"
|
8
|
+
super(content, mime_type)
|
17
9
|
end
|
18
10
|
end
|
19
11
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'base64'
|
4
|
+
|
5
|
+
module Yoti
|
6
|
+
class Media
|
7
|
+
# @return [String|bin]
|
8
|
+
attr_reader :content
|
9
|
+
|
10
|
+
# @return [String]
|
11
|
+
attr_reader :mime_type
|
12
|
+
|
13
|
+
def initialize(content, mime_type)
|
14
|
+
@content = content
|
15
|
+
@mime_type = mime_type
|
16
|
+
end
|
17
|
+
|
18
|
+
def base64_content
|
19
|
+
"data:#{mime_type};base64,#{Base64.strict_encode64(content)}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,191 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Yoti
|
4
|
+
module DocScan
|
5
|
+
class Client
|
6
|
+
class << self
|
7
|
+
#
|
8
|
+
# Creates a Doc Scan session using the supplied session specification
|
9
|
+
#
|
10
|
+
# @param [Yoti::DocScan::Session::Create::SessionSpecification] session_specification
|
11
|
+
#
|
12
|
+
# @return [Yoti::DocScan::Session::Create::CreateSessionResult]
|
13
|
+
#
|
14
|
+
def create_session(session_specification)
|
15
|
+
Validation.assert_is_a(
|
16
|
+
Yoti::DocScan::Session::Create::SessionSpecification,
|
17
|
+
session_specification,
|
18
|
+
'session_specification'
|
19
|
+
)
|
20
|
+
|
21
|
+
request = create_request
|
22
|
+
.with_http_method('POST')
|
23
|
+
.with_endpoint('sessions')
|
24
|
+
.with_payload(session_specification)
|
25
|
+
.with_query_param('sdkId', Yoti.configuration.client_sdk_id)
|
26
|
+
.build
|
27
|
+
|
28
|
+
begin
|
29
|
+
Yoti::DocScan::Session::Create::CreateSessionResult.new(JSON.parse(request.execute.body))
|
30
|
+
rescue Yoti::RequestError => e
|
31
|
+
raise Yoti::DocScan::Error.wrap(e)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# Retrieves the state of a previously created Yoti Doc Scan session
|
37
|
+
#
|
38
|
+
# @param [String] session_id
|
39
|
+
#
|
40
|
+
# @return [Yoti::DocScan::Session::Retrieve::GetSessionResult]
|
41
|
+
#
|
42
|
+
def get_session(session_id)
|
43
|
+
Validation.assert_is_a(String, session_id, 'session_id')
|
44
|
+
|
45
|
+
request = create_request
|
46
|
+
.with_http_method('GET')
|
47
|
+
.with_endpoint(session_path(session_id))
|
48
|
+
.with_query_param('sdkId', Yoti.configuration.client_sdk_id)
|
49
|
+
.build
|
50
|
+
|
51
|
+
begin
|
52
|
+
Yoti::DocScan::Session::Retrieve::GetSessionResult.new(JSON.parse(request.execute.body))
|
53
|
+
rescue Yoti::RequestError => e
|
54
|
+
raise Yoti::DocScan::Error.wrap(e)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
#
|
59
|
+
# Deletes a previously created Yoti Doc Scan session and all
|
60
|
+
# of its related resources
|
61
|
+
#
|
62
|
+
# @param [String] session_id
|
63
|
+
#
|
64
|
+
def delete_session(session_id)
|
65
|
+
Validation.assert_is_a(String, session_id, 'session_id')
|
66
|
+
|
67
|
+
request = create_request
|
68
|
+
.with_http_method('DELETE')
|
69
|
+
.with_endpoint(session_path(session_id))
|
70
|
+
.with_query_param('sdkId', Yoti.configuration.client_sdk_id)
|
71
|
+
.build
|
72
|
+
|
73
|
+
begin
|
74
|
+
request.execute
|
75
|
+
rescue Yoti::RequestError => e
|
76
|
+
raise Yoti::DocScan::Error.wrap(e)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
#
|
81
|
+
# Retrieves media related to a Yoti Doc Scan session based
|
82
|
+
# on the supplied media ID
|
83
|
+
#
|
84
|
+
# @param [String] session_id
|
85
|
+
# @param [String] media_id
|
86
|
+
#
|
87
|
+
# @return [Yoti::Media|nil]
|
88
|
+
#
|
89
|
+
def get_media_content(session_id, media_id)
|
90
|
+
Validation.assert_is_a(String, session_id, 'session_id')
|
91
|
+
Validation.assert_is_a(String, media_id, 'media_id')
|
92
|
+
|
93
|
+
request = create_request
|
94
|
+
.with_http_method('GET')
|
95
|
+
.with_endpoint(media_path(session_id, media_id))
|
96
|
+
.with_query_param('sdkId', Yoti.configuration.client_sdk_id)
|
97
|
+
.build
|
98
|
+
|
99
|
+
begin
|
100
|
+
response = request.execute
|
101
|
+
|
102
|
+
content_type = response.get_fields('content-type')
|
103
|
+
|
104
|
+
return nil if response.code == 204 || content_type.nil?
|
105
|
+
|
106
|
+
Yoti::Media.new(
|
107
|
+
response.body,
|
108
|
+
content_type[0]
|
109
|
+
)
|
110
|
+
rescue Yoti::RequestError => e
|
111
|
+
raise Yoti::DocScan::Error.wrap(e)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
#
|
116
|
+
# Deletes media related to a Yoti Doc Scan session based
|
117
|
+
# on the supplied media ID
|
118
|
+
#
|
119
|
+
# @param [String] session_id
|
120
|
+
# @param [String] media_id
|
121
|
+
#
|
122
|
+
def delete_media_content(session_id, media_id)
|
123
|
+
Validation.assert_is_a(String, session_id, 'session_id')
|
124
|
+
Validation.assert_is_a(String, media_id, 'media_id')
|
125
|
+
|
126
|
+
request = create_request
|
127
|
+
.with_http_method('DELETE')
|
128
|
+
.with_endpoint(media_path(session_id, media_id))
|
129
|
+
.with_query_param('sdkId', Yoti.configuration.client_sdk_id)
|
130
|
+
.build
|
131
|
+
|
132
|
+
begin
|
133
|
+
request.execute
|
134
|
+
rescue Yoti::RequestError => e
|
135
|
+
raise Yoti::DocScan::Error.wrap(e)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
#
|
140
|
+
# Gets a list of supported documents.
|
141
|
+
#
|
142
|
+
# @return [Yoti::DocScan::Support::SupportedDocumentsResponse]
|
143
|
+
#
|
144
|
+
def supported_documents
|
145
|
+
request = create_request
|
146
|
+
.with_http_method('GET')
|
147
|
+
.with_endpoint('supported-documents')
|
148
|
+
.build
|
149
|
+
|
150
|
+
begin
|
151
|
+
Yoti::DocScan::Support::SupportedDocumentsResponse.new(JSON.parse(request.execute.body))
|
152
|
+
rescue Yoti::RequestError => e
|
153
|
+
raise Yoti::DocScan::Error.wrap(e)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
private
|
158
|
+
|
159
|
+
#
|
160
|
+
# @param [String] session_id
|
161
|
+
#
|
162
|
+
# @return [String]
|
163
|
+
#
|
164
|
+
def session_path(session_id)
|
165
|
+
"sessions/#{session_id}"
|
166
|
+
end
|
167
|
+
|
168
|
+
#
|
169
|
+
# @param [String] session_id
|
170
|
+
# @param [String] media_id
|
171
|
+
#
|
172
|
+
# @return [String]
|
173
|
+
#
|
174
|
+
def media_path(session_id, media_id)
|
175
|
+
"#{session_path(session_id)}/media/#{media_id}/content"
|
176
|
+
end
|
177
|
+
|
178
|
+
#
|
179
|
+
# Create a base Doc Scan request
|
180
|
+
#
|
181
|
+
# @return [Yoti::Request]
|
182
|
+
#
|
183
|
+
def create_request
|
184
|
+
Yoti::Request
|
185
|
+
.builder
|
186
|
+
.with_base_url(Yoti.configuration.doc_scan_api_endpoint)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Yoti
|
4
|
+
module DocScan
|
5
|
+
class Constants
|
6
|
+
ID_DOCUMENT_AUTHENTICITY = 'ID_DOCUMENT_AUTHENTICITY'
|
7
|
+
ID_DOCUMENT_COMPARISON = 'ID_DOCUMENT_COMPARISON'
|
8
|
+
ID_DOCUMENT_TEXT_DATA_CHECK = 'ID_DOCUMENT_TEXT_DATA_CHECK'
|
9
|
+
SUPPLEMENTARY_DOCUMENT_TEXT_DATA_CHECK = 'SUPPLEMENTARY_DOCUMENT_TEXT_DATA_CHECK'
|
10
|
+
ID_DOCUMENT_FACE_MATCH = 'ID_DOCUMENT_FACE_MATCH'
|
11
|
+
LIVENESS = 'LIVENESS'
|
12
|
+
ID_DOCUMENT_TEXT_DATA_EXTRACTION = 'ID_DOCUMENT_TEXT_DATA_EXTRACTION'
|
13
|
+
SUPPLEMENTARY_DOCUMENT_TEXT_DATA_EXTRACTION = 'SUPPLEMENTARY_DOCUMENT_TEXT_DATA_EXTRACTION'
|
14
|
+
ID_DOCUMENT = 'ID_DOCUMENT'
|
15
|
+
SUPPLEMENTARY_DOCUMENT = 'SUPPLEMENTARY_DOCUMENT'
|
16
|
+
ORTHOGONAL_RESTRICTIONS = 'ORTHOGONAL_RESTRICTIONS'
|
17
|
+
DOCUMENT_RESTRICTIONS = 'DOCUMENT_RESTRICTIONS'
|
18
|
+
INCLUDE = 'WHITELIST'
|
19
|
+
EXCLUDE = 'BLACKLIST'
|
20
|
+
ALWAYS = 'ALWAYS'
|
21
|
+
FALLBACK = 'FALLBACK'
|
22
|
+
DESIRED = 'DESIRED'
|
23
|
+
IGNORE = 'IGNORE'
|
24
|
+
NEVER = 'NEVER'
|
25
|
+
ZOOM = 'ZOOM'
|
26
|
+
CAMERA = 'CAMERA'
|
27
|
+
CAMERA_AND_UPLOAD = 'CAMERA_AND_UPLOAD'
|
28
|
+
RESOURCE_UPDATE = 'RESOURCE_UPDATE'
|
29
|
+
TASK_COMPLETION = 'TASK_COMPLETION'
|
30
|
+
CHECK_COMPLETION = 'CHECK_COMPLETION'
|
31
|
+
SESSION_COMPLETION = 'SESSION_COMPLETION'
|
32
|
+
PROOF_OF_ADDRESS = 'PROOF_OF_ADDRESS'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Yoti
|
4
|
+
module DocScan
|
5
|
+
#
|
6
|
+
# Raises exceptions related to Doc Scan API requests
|
7
|
+
#
|
8
|
+
class Error < RequestError
|
9
|
+
def initialize(msg = nil, response = nil)
|
10
|
+
super(msg, response)
|
11
|
+
|
12
|
+
@default_message = msg
|
13
|
+
end
|
14
|
+
|
15
|
+
def message
|
16
|
+
@message ||= format_message
|
17
|
+
end
|
18
|
+
|
19
|
+
#
|
20
|
+
# Wraps an existing error
|
21
|
+
#
|
22
|
+
# @param [Error] error
|
23
|
+
#
|
24
|
+
# @return [self]
|
25
|
+
#
|
26
|
+
def self.wrap(error)
|
27
|
+
new(error.message, error.response)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
#
|
33
|
+
# Formats error message from response.
|
34
|
+
#
|
35
|
+
# @return [String]
|
36
|
+
#
|
37
|
+
def format_message
|
38
|
+
return @default_message if @response.nil? || @response['Content-Type'] != 'application/json'
|
39
|
+
|
40
|
+
json = JSON.parse(@response.body)
|
41
|
+
format_response(json) || @default_message
|
42
|
+
end
|
43
|
+
|
44
|
+
#
|
45
|
+
# Format JSON error response.
|
46
|
+
#
|
47
|
+
# @param [Hash] json
|
48
|
+
#
|
49
|
+
# @return [String, nil]
|
50
|
+
#
|
51
|
+
def format_response(json)
|
52
|
+
return nil if json['code'].nil? || json['message'].nil?
|
53
|
+
|
54
|
+
code_message = "#{json['code']} - #{json['message']}"
|
55
|
+
|
56
|
+
unless json['errors'].nil?
|
57
|
+
property_errors = format_property_errors(json['errors'])
|
58
|
+
|
59
|
+
return "#{code_message}: #{property_errors.compact.join(', ')}" if property_errors.count.positive?
|
60
|
+
end
|
61
|
+
|
62
|
+
code_message
|
63
|
+
end
|
64
|
+
|
65
|
+
#
|
66
|
+
# Format property errors.
|
67
|
+
#
|
68
|
+
# @param [Array<Hash>] errors
|
69
|
+
#
|
70
|
+
# @return [Array<String>]
|
71
|
+
#
|
72
|
+
def format_property_errors(errors)
|
73
|
+
errors
|
74
|
+
.map do |e|
|
75
|
+
"#{e['property']} \"#{e['message']}\"" if e['property'] && e['message']
|
76
|
+
end
|
77
|
+
.compact
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Yoti
|
4
|
+
module DocScan
|
5
|
+
module Session
|
6
|
+
module Create
|
7
|
+
#
|
8
|
+
# The response to a successful CreateSession call
|
9
|
+
#
|
10
|
+
class CreateSessionResult
|
11
|
+
#
|
12
|
+
# Returns the time-to-live (TTL) for the client session
|
13
|
+
# token for the created session
|
14
|
+
#
|
15
|
+
# @return [Integer]
|
16
|
+
#
|
17
|
+
attr_reader :client_session_token_ttl
|
18
|
+
|
19
|
+
#
|
20
|
+
# Returns the client session token for the created session
|
21
|
+
#
|
22
|
+
# @return [String]
|
23
|
+
#
|
24
|
+
attr_reader :client_session_token
|
25
|
+
|
26
|
+
#
|
27
|
+
# Session ID of the created session
|
28
|
+
#
|
29
|
+
# @return [String]
|
30
|
+
#
|
31
|
+
attr_reader :session_id
|
32
|
+
|
33
|
+
#
|
34
|
+
# @param [Hash] response
|
35
|
+
#
|
36
|
+
def initialize(response)
|
37
|
+
Validation.assert_is_a(Integer, response['client_session_token_ttl'], 'client_session_token_ttl', true)
|
38
|
+
@client_session_token_ttl = response['client_session_token_ttl']
|
39
|
+
|
40
|
+
Validation.assert_is_a(String, response['client_session_token'], 'client_session_token', true)
|
41
|
+
@client_session_token = response['client_session_token']
|
42
|
+
|
43
|
+
Validation.assert_is_a(String, response['session_id'], 'session_id', true)
|
44
|
+
@session_id = response['session_id']
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|