trustid_sdk 0.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.
Files changed (90) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +80 -0
  3. data/lib/trustid_sdk/client.rb +21 -0
  4. data/lib/trustid_sdk/concerns/attribute_resolution.rb +19 -0
  5. data/lib/trustid_sdk/concerns/has_nested_models.rb +179 -0
  6. data/lib/trustid_sdk/config.rb +45 -0
  7. data/lib/trustid_sdk/errors.rb +23 -0
  8. data/lib/trustid_sdk/models/access_lock.rb +28 -0
  9. data/lib/trustid_sdk/models/advanced_query_arguments.rb +78 -0
  10. data/lib/trustid_sdk/models/application_flexible_field.rb +34 -0
  11. data/lib/trustid_sdk/models/application_flexible_field_attribute.rb +75 -0
  12. data/lib/trustid_sdk/models/application_flexible_field_list.rb +79 -0
  13. data/lib/trustid_sdk/models/application_flexible_field_value.rb +79 -0
  14. data/lib/trustid_sdk/models/base_model.rb +53 -0
  15. data/lib/trustid_sdk/models/branch.rb +34 -0
  16. data/lib/trustid_sdk/models/callback_info.rb +33 -0
  17. data/lib/trustid_sdk/models/callback_state.rb +46 -0
  18. data/lib/trustid_sdk/models/chargeable_status.rb +31 -0
  19. data/lib/trustid_sdk/models/configuration.rb +78 -0
  20. data/lib/trustid_sdk/models/container.rb +254 -0
  21. data/lib/trustid_sdk/models/custom_field.rb +29 -0
  22. data/lib/trustid_sdk/models/dbs_check_initiation.rb +14 -0
  23. data/lib/trustid_sdk/models/dbs_form.rb +108 -0
  24. data/lib/trustid_sdk/models/digital_identification_scheme.rb +43 -0
  25. data/lib/trustid_sdk/models/document.rb +646 -0
  26. data/lib/trustid_sdk/models/document_configuration.rb +21 -0
  27. data/lib/trustid_sdk/models/document_container_field.rb +31 -0
  28. data/lib/trustid_sdk/models/document_container_validation.rb +45 -0
  29. data/lib/trustid_sdk/models/document_container_validation_outcome.rb +58 -0
  30. data/lib/trustid_sdk/models/document_feature_feedback.rb +24 -0
  31. data/lib/trustid_sdk/models/document_feedback.rb +35 -0
  32. data/lib/trustid_sdk/models/document_field.rb +48 -0
  33. data/lib/trustid_sdk/models/document_field_data_type.rb +22 -0
  34. data/lib/trustid_sdk/models/document_field_source.rb +34 -0
  35. data/lib/trustid_sdk/models/document_sorting_column.rb +27 -0
  36. data/lib/trustid_sdk/models/document_source.rb +29 -0
  37. data/lib/trustid_sdk/models/document_status.rb +34 -0
  38. data/lib/trustid_sdk/models/document_storage_type.rb +32 -0
  39. data/lib/trustid_sdk/models/document_type.rb +46 -0
  40. data/lib/trustid_sdk/models/document_type_charge_status.rb +37 -0
  41. data/lib/trustid_sdk/models/document_validation.rb +45 -0
  42. data/lib/trustid_sdk/models/document_validation_result.rb +60 -0
  43. data/lib/trustid_sdk/models/established_document_data.rb +20 -0
  44. data/lib/trustid_sdk/models/external_service_data.rb +29 -0
  45. data/lib/trustid_sdk/models/filter_date_option.rb +36 -0
  46. data/lib/trustid_sdk/models/flexible_field_data_type.rb +39 -0
  47. data/lib/trustid_sdk/models/flexible_field_search_specification.rb +50 -0
  48. data/lib/trustid_sdk/models/flexible_field_specification_search_operator.rb +30 -0
  49. data/lib/trustid_sdk/models/gender.rb +31 -0
  50. data/lib/trustid_sdk/models/guest_link_response.rb +38 -0
  51. data/lib/trustid_sdk/models/image.rb +101 -0
  52. data/lib/trustid_sdk/models/image_orientation.rb +52 -0
  53. data/lib/trustid_sdk/models/image_type.rb +89 -0
  54. data/lib/trustid_sdk/models/kdb_country.rb +37 -0
  55. data/lib/trustid_sdk/models/kdb_document_number.rb +37 -0
  56. data/lib/trustid_sdk/models/kdb_document_sub_type.rb +28 -0
  57. data/lib/trustid_sdk/models/kdb_feature_type.rb +45 -0
  58. data/lib/trustid_sdk/models/liveness_result_type.rb +55 -0
  59. data/lib/trustid_sdk/models/mrz_query_option.rb +35 -0
  60. data/lib/trustid_sdk/models/ocr_coordinates.rb +19 -0
  61. data/lib/trustid_sdk/models/ocr_field.rb +78 -0
  62. data/lib/trustid_sdk/models/ocr_field_data.rb +28 -0
  63. data/lib/trustid_sdk/models/organisation.rb +19 -0
  64. data/lib/trustid_sdk/models/overall_status.rb +39 -0
  65. data/lib/trustid_sdk/models/pdf.rb +17 -0
  66. data/lib/trustid_sdk/models/referral_history_record.rb +68 -0
  67. data/lib/trustid_sdk/models/referral_type.rb +27 -0
  68. data/lib/trustid_sdk/models/remaining_credits.rb +16 -0
  69. data/lib/trustid_sdk/models/report.rb +17 -0
  70. data/lib/trustid_sdk/models/review_application_state.rb +33 -0
  71. data/lib/trustid_sdk/models/sorting_direction.rb +28 -0
  72. data/lib/trustid_sdk/models/user.rb +41 -0
  73. data/lib/trustid_sdk/models/user_archive_visibility.rb +28 -0
  74. data/lib/trustid_sdk/models/user_reference.rb +16 -0
  75. data/lib/trustid_sdk/models/webhook_callback.rb +129 -0
  76. data/lib/trustid_sdk/models/webhook_data.rb +272 -0
  77. data/lib/trustid_sdk/models/webhook_response.rb +89 -0
  78. data/lib/trustid_sdk/models/workflow_storage_item.rb +52 -0
  79. data/lib/trustid_sdk/models/workflow_type.rb +31 -0
  80. data/lib/trustid_sdk/request.rb +116 -0
  81. data/lib/trustid_sdk/services/authentication.rb +23 -0
  82. data/lib/trustid_sdk/services/containers.rb +20 -0
  83. data/lib/trustid_sdk/services/documents.rb +23 -0
  84. data/lib/trustid_sdk/services/guest_links.rb +19 -0
  85. data/lib/trustid_sdk/services/images.rb +21 -0
  86. data/lib/trustid_sdk/services/reports.rb +79 -0
  87. data/lib/trustid_sdk/services/webhook_parser.rb +220 -0
  88. data/lib/trustid_sdk/version.rb +5 -0
  89. data/lib/trustid_sdk.rb +23 -0
  90. metadata +186 -0
@@ -0,0 +1,272 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'webhook_response'
4
+ require_relative 'container'
5
+ require_relative 'document'
6
+
7
+ module TrustID
8
+ # WebhookData
9
+ #
10
+ # Enhanced webhook data object that provides fetch methods for related resources.
11
+ # This class wraps a WebhookResponse and adds convenience methods for fetching
12
+ # containers, documents, and other related resources.
13
+ class WebhookData
14
+ attr_reader :webhook_response
15
+
16
+ def initialize(webhook_response)
17
+ @webhook_response = webhook_response
18
+ end
19
+
20
+ # Delegate all methods to the underlying webhook_response
21
+ def method_missing(method_name, *, &)
22
+ if webhook_response.respond_to?(method_name)
23
+ webhook_response.send(method_name, *, &)
24
+ else
25
+ super
26
+ end
27
+ end
28
+
29
+ def respond_to_missing?(method_name, include_private = false)
30
+ webhook_response.respond_to?(method_name, include_private) || super
31
+ end
32
+
33
+ # Fetch the container associated with this webhook
34
+ #
35
+ # @return [Container, nil] The container if found, nil otherwise
36
+ def fetch_container
37
+ container_id = self.container_id || callback&.container_id
38
+ return nil unless container_id
39
+
40
+ Container.find(container_id)
41
+ rescue StandardError => e
42
+ warn "Failed to fetch container #{container_id}: #{e.message}"
43
+ nil
44
+ end
45
+
46
+ # Get the container associated with this webhook (cached)
47
+ #
48
+ # @return [Container, nil] The container if found, nil otherwise
49
+ def container
50
+ @container ||= fetch_container
51
+ end
52
+
53
+ # Fetch the document associated with this webhook
54
+ #
55
+ # @return [Document, nil] The document if found, nil otherwise
56
+ def fetch_document
57
+ document_id = callback&.document_id
58
+ return nil unless document_id
59
+
60
+ Document.find(document_id)
61
+ rescue StandardError => e
62
+ warn "Failed to fetch document #{document_id}: #{e.message}"
63
+ nil
64
+ end
65
+
66
+ # Get the document associated with this webhook (cached)
67
+ #
68
+ # @return [Document, nil] The document if found, nil otherwise
69
+ def document
70
+ @document ||= fetch_document
71
+ end
72
+
73
+ # Get the container ID from either the response or callback
74
+ #
75
+ # @return [String, nil] The container ID
76
+ def effective_container_id
77
+ container_id || callback&.container_id
78
+ end
79
+
80
+ # Get the document ID from the callback
81
+ #
82
+ # @return [String, nil] The document ID
83
+ def effective_document_id
84
+ callback&.document_id
85
+ end
86
+
87
+ # Get the client application reference from the callback
88
+ #
89
+ # @return [String, nil] The client application reference
90
+ def effective_client_application_reference
91
+ callback&.client_application_reference
92
+ end
93
+
94
+ # Check if this webhook has a container
95
+ #
96
+ # @return [Boolean] True if a container ID is present
97
+ def container?
98
+ effective_container_id.present?
99
+ end
100
+
101
+ # Check if this webhook has a document
102
+ #
103
+ # @return [Boolean] True if a document ID is present
104
+ def document?
105
+ effective_document_id.present?
106
+ end
107
+
108
+ # Get a summary of the webhook data
109
+ #
110
+ # @return [Hash] Summary information
111
+ def summary
112
+ {
113
+ success: success,
114
+ operation_successful: operation_successful?,
115
+ container_id: effective_container_id,
116
+ document_id: effective_document_id,
117
+ client_application_reference: effective_client_application_reference,
118
+ workflow_name: workflow_name,
119
+ workflow_state: workflow_state,
120
+ message: message,
121
+ has_callback: callback?,
122
+ has_container: container?,
123
+ has_document: document?
124
+ }
125
+ end
126
+
127
+ # Build a complete JSON representation of the webhook data including fetched resources
128
+ #
129
+ # @param include_resources [Boolean] Whether to include fetched container and document data
130
+ # @return [Hash] Complete webhook data structure
131
+ def to_json_data(include_resources: true)
132
+ data = {
133
+ webhook_response: webhook_response_to_hash,
134
+ effective_values: build_effective_values,
135
+ availability: build_availability,
136
+ summary: summary
137
+ }
138
+
139
+ data[:fetched_resources] = build_fetched_resources if include_resources
140
+
141
+ data
142
+ end
143
+
144
+ # Convert webhook data to JSON string
145
+ #
146
+ # @param include_resources [Boolean] Whether to include fetched container and document data
147
+ # @param pretty [Boolean] Whether to format JSON with indentation
148
+ # @return [String] JSON string representation
149
+ def to_json(include_resources: true, pretty: false)
150
+ require 'json'
151
+ data = to_json_data(include_resources: include_resources)
152
+
153
+ if pretty
154
+ JSON.pretty_generate(data)
155
+ else
156
+ data.to_json
157
+ end
158
+ end
159
+
160
+ # Save webhook data to a JSON file
161
+ #
162
+ # @param file_path [String] Path to save the JSON file
163
+ # @param include_resources [Boolean] Whether to include fetched container and document data
164
+ # @param pretty [Boolean] Whether to format JSON with indentation
165
+ # @return [Boolean] True if file was saved successfully
166
+ def save_to_file(file_path, include_resources: true, pretty: true)
167
+ require 'json'
168
+
169
+ json_data = to_json(include_resources: include_resources, pretty: pretty)
170
+ File.write(file_path, json_data)
171
+ true
172
+ rescue StandardError => e
173
+ warn "Failed to save webhook data to #{file_path}: #{e.message}"
174
+ false
175
+ end
176
+
177
+ private
178
+
179
+ def build_effective_values
180
+ {
181
+ container_id: effective_container_id,
182
+ document_id: effective_document_id,
183
+ client_application_reference: effective_client_application_reference
184
+ }
185
+ end
186
+
187
+ def build_availability
188
+ {
189
+ has_container: container?,
190
+ has_document: document?,
191
+ has_callback: callback?
192
+ }
193
+ end
194
+
195
+ def build_fetched_resources
196
+ {
197
+ container: container&.to_hash,
198
+ document: document&.to_hash
199
+ }
200
+ end
201
+
202
+ # Convert webhook response to hash representation
203
+ #
204
+ # @return [Hash] Webhook response as hash
205
+ def webhook_response_to_hash
206
+ {
207
+ callback: callback_to_hash,
208
+ response: response_to_hash,
209
+ success: webhook_response.success,
210
+ message: webhook_response.message,
211
+ container_id: webhook_response.container_id,
212
+ access_denied: webhook_response.access_denied,
213
+ locked: webhook_response.locked,
214
+ session_expired: webhook_response.session_expired,
215
+ vpe_unreachable: webhook_response.vpe_unreachable,
216
+ auto_referred: webhook_response.auto_referred,
217
+ document_replaced: webhook_response.document_replaced,
218
+ merge_containers: webhook_response.merge_containers,
219
+ merged: webhook_response.merged
220
+ }
221
+ end
222
+
223
+ # Convert callback to hash representation
224
+ #
225
+ # @return [Hash] Callback as hash
226
+ def callback_to_hash
227
+ return nil unless webhook_response.callback
228
+
229
+ callback = webhook_response.callback
230
+ {
231
+ aborted: callback.aborted,
232
+ callback_at: callback.callback_at&.iso8601,
233
+ callback_id: callback.callback_id,
234
+ callback_status_code: callback.callback_status_code,
235
+ callback_url: callback.callback_url,
236
+ error_message: callback.error_message,
237
+ process_name: callback.process_name,
238
+ retry_counter: callback.retry_counter,
239
+ scheduled_at: callback.scheduled_at&.iso8601,
240
+ state: callback.state,
241
+ updated_at: callback.updated_at&.iso8601,
242
+ workflow_name: callback.workflow_name,
243
+ workflow_state: callback.workflow_state,
244
+ workflow_storage: callback.workflow_storage&.map(&:to_hash),
245
+ # Helper values
246
+ container_id: callback.container_id,
247
+ document_id: callback.document_id,
248
+ client_application_reference: callback.client_application_reference
249
+ }
250
+ end
251
+
252
+ # Convert response to hash representation
253
+ #
254
+ # @return [Hash] Response as hash
255
+ def response_to_hash
256
+ {
257
+ access_denied: webhook_response.access_denied,
258
+ callback_id: webhook_response.callback_id,
259
+ locked: webhook_response.locked,
260
+ message: webhook_response.message,
261
+ session_expired: webhook_response.session_expired,
262
+ success: webhook_response.success,
263
+ vpe_unreachable: webhook_response.vpe_unreachable,
264
+ auto_referred: webhook_response.auto_referred,
265
+ container_id: webhook_response.container_id,
266
+ document_replaced: webhook_response.document_replaced,
267
+ merge_containers: webhook_response.merge_containers,
268
+ merged: webhook_response.merged
269
+ }
270
+ end
271
+ end
272
+ end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'webhook_callback'
4
+
5
+ module TrustID
6
+ # Represents a webhook response as per TrustID API.
7
+ #
8
+ # This model provides details about the webhook response, including the process name,
9
+ # retry attempts, workflow details, and the success status of the operation.
10
+ #
11
+ # ## Fields
12
+ # - `callback [WebhookCallback, nil]`: The callback object containing detailed callback information.
13
+ # - `response [Hash, nil]`: The response object containing operation results.
14
+ # - `access_denied [Boolean, nil]`: Whether access was denied.
15
+ # - `callback_id [String, nil]`: ID of the callback, if any.
16
+ # - `locked [Boolean, nil]`: Whether the resource is locked.
17
+ # - `message [String, nil]`: Message about the operation (usually 'Operation executed successfully.').
18
+ # - `session_expired [Boolean, nil]`: Whether the session has expired.
19
+ # - `success [Boolean, nil]`: Whether the operation was successful.
20
+ # - `vpe_unreachable [Boolean, nil]`: Whether the VPE is unreachable.
21
+ # - `auto_referred [Boolean, nil]`: Whether the operation was auto-referred.
22
+ # - `container_id [String, nil]`: Unique ID of the check in TrustID servers.
23
+ # - `document_replaced [Boolean, nil]`: Whether a document was replaced.
24
+ # - `merge_containers [Boolean, nil]`: Whether containers should be merged.
25
+ # - `merged [Boolean, nil]`: Whether containers were merged.
26
+ #
27
+ # ## Usage Notes
28
+ # This model is used to parse and handle webhook responses from TrustID.
29
+ # Ensure that all fields are properly validated before use.
30
+ #
31
+ # ## References
32
+ # [TrustID API Documentation - WebhookResponse](https://developer.trustid.co.uk/documentation/ref/raw_ref/model/WebhookResponse.html)
33
+ class WebhookResponse < BaseModel
34
+ include HasNestedModels
35
+
36
+ # Define nested models
37
+ nested_model :callback, WebhookCallback
38
+
39
+ # Define all attributes
40
+ attribute :callback
41
+ attribute :response
42
+ attribute :access_denied, :boolean
43
+ attribute :callback_id, :string
44
+ attribute :locked, :boolean
45
+ attribute :message, :string
46
+ attribute :session_expired, :boolean
47
+ attribute :success, :boolean
48
+ attribute :vpe_unreachable, :boolean
49
+ attribute :auto_referred, :boolean
50
+ attribute :container_id, :string
51
+ attribute :document_replaced, :boolean
52
+ attribute :merge_containers, :boolean
53
+ attribute :merged, :boolean
54
+
55
+ # Helper methods for easy access to common properties
56
+ def operation_successful?
57
+ success == true
58
+ end
59
+
60
+ def container?
61
+ container_id.present?
62
+ end
63
+
64
+ def callback?
65
+ callback.present?
66
+ end
67
+
68
+ # Delegate common callback properties for convenience
69
+ def callback_container_id
70
+ callback&.container_id
71
+ end
72
+
73
+ def callback_document_id
74
+ callback&.document_id
75
+ end
76
+
77
+ def callback_client_application_reference
78
+ callback&.client_application_reference
79
+ end
80
+
81
+ def workflow_name
82
+ callback&.workflow_name
83
+ end
84
+
85
+ def workflow_state
86
+ callback&.workflow_state
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base_model'
4
+
5
+ module TrustID
6
+ # WorkflowStorageItem
7
+ #
8
+ # Represents a single storage item in the workflow storage array.
9
+ # This model provides key-value storage for workflow state.
10
+ #
11
+ # Fields:
12
+ # key - String: The storage key
13
+ # value - String: The storage value
14
+ #
15
+ # @see https://developer.trustid.co.uk/documentation/ref/raw_ref/model/WorkflowStorageItem.html
16
+ class WorkflowStorageItem < BaseModel
17
+ attribute :key, :string
18
+ attribute :value, :string
19
+
20
+ # Convert to hash representation
21
+ #
22
+ # @return [Hash] Hash representation of the storage item
23
+ def to_hash
24
+ {
25
+ key: key,
26
+ value: value
27
+ }
28
+ end
29
+
30
+ # Create instance from hash representation
31
+ #
32
+ # @param hash [Hash] Hash representation from to_hash
33
+ # @return [WorkflowStorageItem] New instance
34
+ def self.from_hash(hash)
35
+ return nil if hash.nil?
36
+
37
+ # Normalize keys to handle both original and generated formats
38
+ normalized_hash = hash.transform_keys do |key|
39
+ case key.to_s
40
+ when 'Key', 'key'
41
+ 'key'
42
+ when 'Value', 'value'
43
+ 'value'
44
+ else
45
+ key.to_s.underscore
46
+ end
47
+ end
48
+
49
+ new(normalized_hash)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TrustID
4
+ # Represents the type of workflow a container is in as per TrustID API.
5
+ #
6
+ # This model provides constants representing possible workflow types
7
+ # and a utility method to retrieve the symbolic name for a given workflow type value.
8
+ #
9
+ # ## Enum Values
10
+ # - `STANDARD (0)`: Standard application workflow.
11
+ # - `AUTO_REFERRAL (1)`: Applications may be referred for manual inspection.
12
+ #
13
+ # ## Usage Notes
14
+ # Use the `name_for` method to retrieve the symbolic name for a given workflow type value.
15
+ #
16
+ # ## References
17
+ # [TrustID API Documentation - WorkflowType](https://developer.trustid.co.uk/documentation/ref/raw_ref/model/WorkflowType.html)
18
+ class WorkflowType
19
+ STANDARD = 0
20
+ AUTO_REFERRAL = 1
21
+
22
+ NAMES = {
23
+ STANDARD => 'Standard',
24
+ AUTO_REFERRAL => 'AutoReferral'
25
+ }.freeze
26
+
27
+ def self.name_for(value)
28
+ NAMES[value]
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,116 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+ require 'uri'
5
+ require 'json'
6
+
7
+ module TrustID
8
+ class Request
9
+ def self.post(path, data)
10
+ client = TrustID.client
11
+ raise Errors::ClientError, 'Client not initialized' unless client
12
+
13
+ data = prepare_request_data(data, client)
14
+ uri = URI.join(client.server_url, path)
15
+ headers = prepare_headers
16
+
17
+ res = Net::HTTP.post(uri, data.to_json, headers)
18
+
19
+ handle_error(res) unless res.is_a?(Net::HTTPSuccess)
20
+
21
+ log_response(res) if TrustID.debug_mode
22
+
23
+ parse_response(res)
24
+ end
25
+
26
+ def self.get(path, params = {})
27
+ client = TrustID.client
28
+ raise Errors::ClientError, 'Client not initialized' unless client
29
+
30
+ uri = build_get_uri(client, path, params)
31
+ res = execute_get_request(uri)
32
+
33
+ handle_error(res) unless res.is_a?(Net::HTTPSuccess)
34
+
35
+ log_response(res) if TrustID.debug_mode
36
+
37
+ parse_response(res)
38
+ end
39
+
40
+ def self.build_get_uri(client, path, params)
41
+ uri = URI.join(client.server_url, path)
42
+ uri = URI.parse(uri.to_s) # Convert to URI object for query manipulation
43
+
44
+ query_params = prepare_query_params(params, client)
45
+ uri.query = URI.encode_www_form(query_params) unless query_params.empty?
46
+
47
+ uri
48
+ end
49
+
50
+ def self.prepare_query_params(params, client)
51
+ query_params = params.dup
52
+ query_params['DeviceId'] = client.device_id if client.device_id
53
+ query_params['SessionId'] = client.session_id if client.session_id
54
+ query_params
55
+ end
56
+
57
+ def self.execute_get_request(uri)
58
+ headers = prepare_get_headers
59
+ http = Net::HTTP.new(uri.host, uri.port)
60
+ http.use_ssl = (uri.scheme == 'https')
61
+
62
+ req = Net::HTTP::Get.new(uri.request_uri, headers)
63
+ http.request(req)
64
+ end
65
+
66
+ def self.prepare_request_data(data, client)
67
+ data = data.merge('SessionId' => client.session_id) if client.session_id
68
+ data = data.merge('DeviceId' => client.device_id) if client.device_id
69
+ data
70
+ end
71
+
72
+ def self.prepare_headers
73
+ headers = { 'Content-Type' => 'application/json' }
74
+ config = TrustID.config
75
+ headers[config.api_header_key] = config.api_key if config.api_key
76
+ headers
77
+ end
78
+
79
+ def self.prepare_get_headers
80
+ headers = {}
81
+ config = TrustID.config
82
+ headers[config.api_header_key] = config.api_key if config.api_key
83
+ headers
84
+ end
85
+
86
+ def self.log_response(res)
87
+ puts "Response: #{res.body}"
88
+ puts "Response Code: #{res.code}"
89
+ puts "Response Headers: #{res.each_header.to_h}"
90
+ end
91
+
92
+ def self.parse_response(res)
93
+ content_type = res['Content-Type']
94
+ if content_type&.include?('application/json')
95
+ JSON.parse(res.body)
96
+ else
97
+ res.body
98
+ end
99
+ end
100
+
101
+ def self.handle_error(res)
102
+ case res
103
+ when Net::HTTPBadRequest
104
+ raise Errors::BadRequestError, res.body
105
+ when Net::HTTPUnauthorized
106
+ raise Errors::AuthenticationError, res.body
107
+ when Net::HTTPForbidden
108
+ raise Errors::AuthorizationError, res.body
109
+ when Net::HTTPNotFound
110
+ raise Errors::NotFoundError, res.body
111
+ else
112
+ raise Errors::ServerError, res.body
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TrustID
4
+ module Services
5
+ class Authentication
6
+ def initialize(username, password)
7
+ @username = username
8
+ @password = password
9
+ @client = TrustID.client
10
+ end
11
+
12
+ def login
13
+ response = Request.post('/VPE/session/login/', {
14
+ 'Username' => @username,
15
+ 'Password' => @password
16
+ })
17
+ raise Errors::AuthenticationError, response, caller if response['AccessDenied']
18
+
19
+ @client.session_id = response['SessionId']
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TrustID
4
+ module Services
5
+ class Containers
6
+ # Fetch a container by ID (class-level convenience method)
7
+ def self.retrieve(container_id:)
8
+ new.retrieve(container_id:)
9
+ end
10
+
11
+ # Fetch a container by ID (instance-level method)
12
+ def retrieve(container_id:)
13
+ response = Request.post('/VPE/dataAccess/retrieveDocumentContainer/', {
14
+ 'ContainerId' => container_id
15
+ })
16
+ TrustID::Container.from_hash(response['Container'])
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TrustID
4
+ require_relative '../models/document'
5
+
6
+ module Services
7
+ class Documents
8
+ # Fetch a document by ID (class-level convenience method)
9
+ def self.retrieve(container_id:, document_id:)
10
+ new.retrieve(container_id:, document_id:)
11
+ end
12
+
13
+ # Fetch a document by ID (instance-level method)
14
+ def retrieve(container_id:, document_id:)
15
+ response = Request.post('/VPE/dataAccess/retrieveDocument/', {
16
+ 'ContainerId' => container_id,
17
+ 'DocumentId' => document_id
18
+ })
19
+ TrustID::Document.from_hash(response['Document'])
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TrustID
4
+ module Services
5
+ class GuestLinks
6
+ def self.create(email:, name:)
7
+ new.create(email:, name:)
8
+ end
9
+
10
+ def create(email:, name:)
11
+ response = Request.post('/VPE/guestLink/createGuestLink/', {
12
+ 'Email' => email,
13
+ 'Name' => name
14
+ })
15
+ TrustID::GuestLinkResponse.from_hash(response)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TrustID
4
+ require_relative '../models/image'
5
+ module Services
6
+ class Images
7
+ # Fetch an image by ID (class-level convenience method)
8
+ def self.retrieve(image_id:)
9
+ new.retrieve(image_id:)
10
+ end
11
+
12
+ # Fetch an image by ID (instance-level method)
13
+ def retrieve(image_id:)
14
+ response = Request.post('/VPE/dataAccess/retrieveImage/', {
15
+ 'ImageId' => image_id
16
+ })
17
+ TrustID::Image.from_binary(response)
18
+ end
19
+ end
20
+ end
21
+ end