Class: ComplyanceSDK::Models::UnifyResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/complyance_sdk/models/unify_response.rb

Overview

UnifyResponse model representing the API response structure

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ UnifyResponse

Initialize a new UnifyResponse

Parameters:

  • options (Hash) (defaults to: {})

    Response options

Options Hash (options):

  • :status (String)

    The response status

  • :message (String)

    The response message

  • :data (Hash)

    The response data

  • :error (Hash)

    The error details

  • :metadata (Hash)

    The response metadata



32
33
34
35
36
37
38
# File 'lib/complyance_sdk/models/unify_response.rb', line 32

def initialize(options = {})
  @status = options[:status]
  @message = options[:message]
  @data = options[:data]
  @error = options[:error]
  @metadata = options[:metadata] || {}
end

Instance Attribute Details

#dataObject (readonly)

Response data



16
17
18
# File 'lib/complyance_sdk/models/unify_response.rb', line 16

def data
  @data
end

#errorObject (readonly)

Error details



19
20
21
# File 'lib/complyance_sdk/models/unify_response.rb', line 19

def error
  @error
end

#messageObject (readonly)

Response message



13
14
15
# File 'lib/complyance_sdk/models/unify_response.rb', line 13

def message
  @message
end

#metadataObject (readonly)

Response metadata



22
23
24
# File 'lib/complyance_sdk/models/unify_response.rb', line 22

def 
  @metadata
end

#statusObject (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

Parameters:

  • error (Hash) (defaults to: {})

    The error details

  • message (String) (defaults to: "Error")

    The error message

  • metadata (Hash) (defaults to: {})

    The response metadata

Returns:



188
189
190
191
192
193
194
195
# File 'lib/complyance_sdk/models/unify_response.rb', line 188

def self.error(error = {}, message = "Error",  = {})
  new(
    status: "error",
    message: message,
    error: error,
    metadata: 
  )
end

.from_h(hash) ⇒ UnifyResponse

Create a UnifyResponse from a hash

Parameters:

  • hash (Hash)

    The hash to convert

Returns:



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

Parameters:

  • json (String)

    The JSON string to convert

Returns:



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.message}",
    context: { json: json }
  )
end

.success(data = {}, message = "Success", metadata = {}) ⇒ UnifyResponse

Create a success response

Parameters:

  • data (Hash) (defaults to: {})

    The response data

  • message (String) (defaults to: "Success")

    The success message

  • metadata (Hash) (defaults to: {})

    The response metadata

Returns:



173
174
175
176
177
178
179
180
# File 'lib/complyance_sdk/models/unify_response.rb', line 173

def self.success(data = {}, message = "Success",  = {})
  new(
    status: "success",
    message: message,
    data: data,
    metadata: 
  )
end

Instance Method Details

#error?Boolean

Check if the response indicates an error

Returns:

  • (Boolean)

    True if error, false otherwise



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

Returns:

  • (Boolean)

    True if validation errors exist, false otherwise



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_timeNumeric?

Get the processing time from metadata

Returns:

  • (Numeric, nil)

    The processing time in milliseconds



86
87
88
# File 'lib/complyance_sdk/models/unify_response.rb', line 86

def processing_time
  @metadata[:processing_time] || @metadata["processing_time"]
end

#request_idString?

Get the request ID from metadata

Returns:

  • (String, nil)

    The request ID



79
80
81
# File 'lib/complyance_sdk/models/unify_response.rb', line 79

def request_id
  @metadata[:request_id] || @metadata["request_id"]
end

#submission_idString?

Get the submission ID from data Checks multiple possible locations: data.submission_id, data.submission.submissionId, data.submission.submission_id

Returns:

  • (String, nil)

    The 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

Returns:

  • (Boolean)

    True if successful, false otherwise



43
44
45
# File 'lib/complyance_sdk/models/unify_response.rb', line 43

def success?
  (@status == "success" || @status == "completed") && !has_validation_errors?
end

#to_hHash

Convert the response to a hash

Returns:

  • (Hash)

    The response as 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

Returns:

  • (String)

    The response as 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_idString?

Get the trace ID from metadata

Returns:

  • (String, nil)

    The trace ID



93
94
95
# File 'lib/complyance_sdk/models/unify_response.rb', line 93

def trace_id
  @metadata[:trace_id] || @metadata["trace_id"]
end

#validation_errorsArray

Get validation errors from the response

Returns:

  • (Array)

    Array of validation error hashes



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