Class: ComplyanceSDK::Models::UnifyResponse
- Inherits:
-
Object
- Object
- ComplyanceSDK::Models::UnifyResponse
- Defined in:
- lib/complyance_sdk/models/unify_response.rb
Overview
UnifyResponse model representing the API response structure
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Response data.
-
#error ⇒ Object
readonly
Error details.
-
#message ⇒ Object
readonly
Response message.
-
#metadata ⇒ Object
readonly
Response metadata.
-
#status ⇒ Object
readonly
Response status.
Class Method Summary collapse
-
.error(error = {}, message = "Error", metadata = {}) ⇒ UnifyResponse
Create an error response.
-
.from_h(hash) ⇒ UnifyResponse
Create a UnifyResponse from a hash.
-
.from_json(json) ⇒ UnifyResponse
Create a UnifyResponse from JSON.
-
.success(data = {}, message = "Success", metadata = {}) ⇒ UnifyResponse
Create a success response.
Instance Method Summary collapse
-
#error? ⇒ Boolean
Check if the response indicates an error.
-
#has_validation_errors? ⇒ Boolean
Check if the response has validation errors.
-
#initialize(options = {}) ⇒ UnifyResponse
constructor
Initialize a new UnifyResponse.
-
#processing_time ⇒ Numeric?
Get the processing time from metadata.
-
#request_id ⇒ String?
Get the request ID from metadata.
-
#submission_id ⇒ String?
Get the submission ID from data Checks multiple possible locations: data.submission_id, data.submission.submissionId, data.submission.submission_id.
-
#success? ⇒ Boolean
Check if the response indicates success.
-
#to_h ⇒ Hash
Convert the response to a hash.
-
#to_json(*args) ⇒ String
Convert the response to JSON.
-
#trace_id ⇒ String?
Get the trace ID from metadata.
-
#validation_errors ⇒ Array
Get validation errors from the response.
Constructor Details
#initialize(options = {}) ⇒ UnifyResponse
Initialize a new UnifyResponse
32 33 34 35 36 37 38 |
# File 'lib/complyance_sdk/models/unify_response.rb', line 32 def initialize( = {}) @status = [:status] @message = [:message] @data = [:data] @error = [:error] @metadata = [:metadata] || {} end |
Instance Attribute Details
#data ⇒ Object (readonly)
Response data
16 17 18 |
# File 'lib/complyance_sdk/models/unify_response.rb', line 16 def data @data end |
#error ⇒ Object (readonly)
Error details
19 20 21 |
# File 'lib/complyance_sdk/models/unify_response.rb', line 19 def error @error end |
#message ⇒ Object (readonly)
Response message
13 14 15 |
# File 'lib/complyance_sdk/models/unify_response.rb', line 13 def @message end |
#metadata ⇒ Object (readonly)
Response metadata
22 23 24 |
# File 'lib/complyance_sdk/models/unify_response.rb', line 22 def @metadata end |
#status ⇒ Object (readonly)
Response status
10 11 12 |
# File 'lib/complyance_sdk/models/unify_response.rb', line 10 def status @status end |
Class Method Details
.error(error = {}, message = "Error", metadata = {}) ⇒ UnifyResponse
Create an error response
188 189 190 191 192 193 194 195 |
# File 'lib/complyance_sdk/models/unify_response.rb', line 188 def self.error(error = {}, = "Error", = {}) new( status: "error", message: , error: error, metadata: ) end |
.from_h(hash) ⇒ UnifyResponse
Create a UnifyResponse from a hash
140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/complyance_sdk/models/unify_response.rb', line 140 def self.from_h(hash) return nil unless hash.is_a?(Hash) # Convert string keys to symbol keys for consistency normalized_hash = {} hash.each do |key, value| symbol_key = key.is_a?(String) ? key.to_sym : key normalized_hash[symbol_key] = value end new(normalized_hash) end |
.from_json(json) ⇒ UnifyResponse
Create a UnifyResponse from JSON
157 158 159 160 161 162 163 164 165 |
# File 'lib/complyance_sdk/models/unify_response.rb', line 157 def self.from_json(json) hash = JSON.parse(json, symbolize_names: true) from_h(hash) rescue JSON::ParserError => e raise ComplyanceSDK::Exceptions::ValidationError.new( "Invalid JSON: #{e.}", context: { json: json } ) end |
.success(data = {}, message = "Success", metadata = {}) ⇒ UnifyResponse
Create a success response
173 174 175 176 177 178 179 180 |
# File 'lib/complyance_sdk/models/unify_response.rb', line 173 def self.success(data = {}, = "Success", = {}) new( status: "success", message: , data: data, metadata: ) end |
Instance Method Details
#error? ⇒ Boolean
Check if the response indicates an error
50 51 52 |
# File 'lib/complyance_sdk/models/unify_response.rb', line 50 def error? !success? end |
#has_validation_errors? ⇒ Boolean
Check if the response has validation errors
57 58 59 60 61 62 |
# File 'lib/complyance_sdk/models/unify_response.rb', line 57 def has_validation_errors? return false unless @data.is_a?(Hash) validation_errors = @data.dig("validation", "errors") || @data.dig(:validation, :errors) validation_errors.is_a?(Array) && !validation_errors.empty? end |
#processing_time ⇒ Numeric?
Get the processing time from metadata
86 87 88 |
# File 'lib/complyance_sdk/models/unify_response.rb', line 86 def processing_time @metadata[:processing_time] || @metadata["processing_time"] end |
#request_id ⇒ String?
Get the request ID from metadata
79 80 81 |
# File 'lib/complyance_sdk/models/unify_response.rb', line 79 def request_id @metadata[:request_id] || @metadata["request_id"] end |
#submission_id ⇒ String?
Get the submission ID from data Checks multiple possible locations: data.submission_id, data.submission.submissionId, data.submission.submission_id
101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/complyance_sdk/models/unify_response.rb', line 101 def submission_id return nil unless @data.is_a?(Hash) # Check direct submission_id submission_id = @data[:submission_id] || @data["submission_id"] return submission_id if submission_id # Check nested submission.submissionId or submission.submission_id submission = @data[:submission] || @data["submission"] return nil unless submission.is_a?(Hash) submission[:submissionId] || submission["submissionId"] || submission[:submission_id] || submission["submission_id"] end |
#success? ⇒ Boolean
Check if the response indicates success
43 44 45 |
# File 'lib/complyance_sdk/models/unify_response.rb', line 43 def success? (@status == "success" || @status == "completed") && !has_validation_errors? end |
#to_h ⇒ Hash
Convert the response to a hash
119 120 121 122 123 124 125 126 127 |
# File 'lib/complyance_sdk/models/unify_response.rb', line 119 def to_h { status: @status, message: @message, data: @data, error: @error, metadata: @metadata } end |
#to_json(*args) ⇒ String
Convert the response to JSON
132 133 134 |
# File 'lib/complyance_sdk/models/unify_response.rb', line 132 def to_json(*args) to_h.to_json(*args) end |
#trace_id ⇒ String?
Get the trace ID from metadata
93 94 95 |
# File 'lib/complyance_sdk/models/unify_response.rb', line 93 def trace_id @metadata[:trace_id] || @metadata["trace_id"] end |
#validation_errors ⇒ Array
Get validation errors from the response
67 68 69 70 71 72 73 74 |
# File 'lib/complyance_sdk/models/unify_response.rb', line 67 def validation_errors return [] unless @data.is_a?(Hash) validation_errors = @data.dig("validation", "errors") || @data.dig(:validation, :errors) return [] unless validation_errors.is_a?(Array) validation_errors end |