Class: ComplyanceSDK::Models::UnifyRequest
- Inherits:
-
Object
- Object
- ComplyanceSDK::Models::UnifyRequest
- Defined in:
- lib/complyance_sdk/models/unify_request.rb
Overview
UnifyRequest model representing the main API request structure
Instance Attribute Summary collapse
-
#country ⇒ Object
Country code.
-
#destinations ⇒ Object
Destinations.
-
#document_type ⇒ Object
Document type.
-
#document_type_v2 ⇒ Object
GETS V2 document type object (modifiers?, variant?).
-
#metadata ⇒ Object
Request metadata.
-
#mode ⇒ Object
Mode.
-
#operation ⇒ Object
Operation type.
-
#payload ⇒ Object
Request payload.
-
#purpose ⇒ Object
Purpose.
-
#source ⇒ Object
Source of the request.
-
#source_origin ⇒ Object
Origin for Integration Engine payload filtering: “SDK” | “LOCAL”.
Class Method Summary collapse
-
.from_h(hash) ⇒ UnifyRequest
Create a UnifyRequest from a hash.
-
.from_json(json) ⇒ UnifyRequest
Create a UnifyRequest from JSON.
Instance Method Summary collapse
-
#errors ⇒ Array<String>
Get validation errors.
-
#initialize(options = {}) ⇒ UnifyRequest
constructor
Initialize a new UnifyRequest.
-
#to_h ⇒ Hash
Convert the request to a hash.
-
#to_json(*args) ⇒ String
Convert the request to JSON.
-
#valid? ⇒ Boolean
Check if the request is valid.
Constructor Details
#initialize(options = {}) ⇒ UnifyRequest
Initialize a new UnifyRequest
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/complyance_sdk/models/unify_request.rb', line 54 def initialize( = {}) @source = [:source] @document_type = DocumentType.normalize([:document_type]) @document_type_v2 = [:document_type_v2] || ["document_type_v2"] || [:documentType] || ["documentType"] @country = [:country] @operation = Operation.normalize([:operation]) @mode = Mode.normalize([:mode]) @purpose = Purpose.normalize([:purpose]) @payload = [:payload] || {} @destinations = [:destinations] || [] @metadata = ([:metadata] || {}) @source_origin = [:source_origin] || ["source_origin"] || [:sourceOrigin] || ["sourceOrigin"] || "SDK" end |
Instance Attribute Details
#country ⇒ Object
Country code
19 20 21 |
# File 'lib/complyance_sdk/models/unify_request.rb', line 19 def country @country end |
#destinations ⇒ Object
Destinations
34 35 36 |
# File 'lib/complyance_sdk/models/unify_request.rb', line 34 def destinations @destinations end |
#document_type ⇒ Object
Document type
13 14 15 |
# File 'lib/complyance_sdk/models/unify_request.rb', line 13 def document_type @document_type end |
#document_type_v2 ⇒ Object
GETS V2 document type object (modifiers?, variant?)
16 17 18 |
# File 'lib/complyance_sdk/models/unify_request.rb', line 16 def document_type_v2 @document_type_v2 end |
#metadata ⇒ Object
Request metadata
37 38 39 |
# File 'lib/complyance_sdk/models/unify_request.rb', line 37 def @metadata end |
#mode ⇒ Object
Mode
25 26 27 |
# File 'lib/complyance_sdk/models/unify_request.rb', line 25 def mode @mode end |
#operation ⇒ Object
Operation type
22 23 24 |
# File 'lib/complyance_sdk/models/unify_request.rb', line 22 def operation @operation end |
#payload ⇒ Object
Request payload
31 32 33 |
# File 'lib/complyance_sdk/models/unify_request.rb', line 31 def payload @payload end |
#purpose ⇒ Object
Purpose
28 29 30 |
# File 'lib/complyance_sdk/models/unify_request.rb', line 28 def purpose @purpose end |
#source ⇒ Object
Source of the request
10 11 12 |
# File 'lib/complyance_sdk/models/unify_request.rb', line 10 def source @source end |
#source_origin ⇒ Object
Origin for Integration Engine payload filtering: “SDK” | “LOCAL”
40 41 42 |
# File 'lib/complyance_sdk/models/unify_request.rb', line 40 def source_origin @source_origin end |
Class Method Details
.from_h(hash) ⇒ UnifyRequest
Create a UnifyRequest from a hash
130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/complyance_sdk/models/unify_request.rb', line 130 def self.from_h(hash) return nil unless hash.is_a?(Hash) = hash.dup # Convert source hash to Source object if needed if [:source].is_a?(Hash) [:source] = Source.new([:source]) end new() end |
.from_json(json) ⇒ UnifyRequest
Create a UnifyRequest from JSON
147 148 149 150 151 152 153 154 155 |
# File 'lib/complyance_sdk/models/unify_request.rb', line 147 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 |
Instance Method Details
#errors ⇒ Array<String>
Get validation errors
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/complyance_sdk/models/unify_request.rb', line 78 def errors errors = [] errors << "Source is required" if @source.nil? errors << "Source must be valid" if @source && !@source.valid? errors << "Document type is required" if @document_type.nil? errors << "Document type must be valid" unless DocumentType.valid?(@document_type) errors << "Country is required" if @country.nil? || @country.empty? errors << "Operation is required" if @operation.nil? errors << "Operation must be valid" unless Operation.valid?(@operation) errors << "Mode is required" if @mode.nil? errors << "Mode must be valid" unless Mode.valid?(@mode) errors << "Purpose is required" if @purpose.nil? errors << "Purpose must be valid" unless Purpose.valid?(@purpose) errors << "Payload is required" if @payload.nil? || @payload.empty? errors end |
#to_h ⇒ Hash
Convert the request to a hash
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/complyance_sdk/models/unify_request.rb', line 100 def to_h { source: @source&.to_h, country: @country.to_s.upcase, operation: @operation.to_s.upcase, mode: @mode.to_s.upcase, payload: @payload, apiKey: @metadata[:api_key], requestId: @metadata[:request_id], timestamp: @metadata[:timestamp], env: @metadata[:environment], destinations: format_destinations(@destinations), correlationId: @metadata[:correlation_id], documentType: (@document_type_v2 || @document_type.to_s.upcase), purpose: @purpose.to_s.downcase, sourceOrigin: @source_origin || "SDK" } end |
#to_json(*args) ⇒ String
Convert the request to JSON
122 123 124 |
# File 'lib/complyance_sdk/models/unify_request.rb', line 122 def to_json(*args) to_h.to_json(*args) end |
#valid? ⇒ Boolean
Check if the request is valid
71 72 73 |
# File 'lib/complyance_sdk/models/unify_request.rb', line 71 def valid? errors.empty? end |