Class: LogaltyCertificateIssuanceApiCerty::Profile

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/logalty_certificate_issuance_api_certy/models/profile.rb

Overview

Profile Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(name:, phone:, idtype: IdType::IDC, idcountry: 'EN', idnumber: SKIP, surname1: SKIP, surname2: SKIP, email: SKIP, validation: SKIP, additional_properties: nil) ⇒ Profile

Returns a new instance of Profile.



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/logalty_certificate_issuance_api_certy/models/profile.rb', line 82

def initialize(name:, phone:, idtype: IdType::IDC, idcountry: 'EN',
               idnumber: SKIP, surname1: SKIP, surname2: SKIP, email: SKIP,
               validation: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @idtype = idtype unless idtype == SKIP
  @idcountry = idcountry unless idcountry == SKIP
  @idnumber = idnumber unless idnumber == SKIP
  @name = name
  @surname1 = surname1 unless surname1 == SKIP
  @surname2 = surname2 unless surname2 == SKIP
  @phone = phone
  @email = email unless email == SKIP
  @validation = validation unless validation == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#emailString

End-user’s e-mail address. Required for e-mail notifications.

Returns:

  • (String)


43
44
45
# File 'lib/logalty_certificate_issuance_api_certy/models/profile.rb', line 43

def email
  @email
end

#idcountryString

Issuing country of the document, coded according to ISO 3166-1. Default is ‘EN`.

Returns:

  • (String)


19
20
21
# File 'lib/logalty_certificate_issuance_api_certy/models/profile.rb', line 19

def idcountry
  @idcountry
end

#idnumberString

Identity document number.

Returns:

  • (String)


23
24
25
# File 'lib/logalty_certificate_issuance_api_certy/models/profile.rb', line 23

def idnumber
  @idnumber
end

#idtypeIdType

TODO: Write general description for this method

Returns:



14
15
16
# File 'lib/logalty_certificate_issuance_api_certy/models/profile.rb', line 14

def idtype
  @idtype
end

#nameString

End-user’s given name.

Returns:

  • (String)


27
28
29
# File 'lib/logalty_certificate_issuance_api_certy/models/profile.rb', line 27

def name
  @name
end

#phoneString

End-user’s telephone number. Required for SMS notifications.

Returns:

  • (String)


39
40
41
# File 'lib/logalty_certificate_issuance_api_certy/models/profile.rb', line 39

def phone
  @phone
end

#surname1String

End-user’s first family name.

Returns:

  • (String)


31
32
33
# File 'lib/logalty_certificate_issuance_api_certy/models/profile.rb', line 31

def surname1
  @surname1
end

#surname2String

End-user’s second family name.

Returns:

  • (String)


35
36
37
# File 'lib/logalty_certificate_issuance_api_certy/models/profile.rb', line 35

def surname2
  @surname2
end

#validationArray[ValidationRule]

Additional validations to perform on the user’s data.

Returns:



47
48
49
# File 'lib/logalty_certificate_issuance_api_certy/models/profile.rb', line 47

def validation
  @validation
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/logalty_certificate_issuance_api_certy/models/profile.rb', line 101

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  name = hash.key?('name') ? hash['name'] : nil
  phone = hash.key?('phone') ? hash['phone'] : nil
  idtype = hash['idtype'] ||= IdType::IDC
  idcountry = hash['idcountry'] ||= 'EN'
  idnumber = hash.key?('idnumber') ? hash['idnumber'] : SKIP
  surname1 = hash.key?('surname1') ? hash['surname1'] : SKIP
  surname2 = hash.key?('surname2') ? hash['surname2'] : SKIP
  email = hash.key?('email') ? hash['email'] : SKIP
  # Parameter is an array, so we need to iterate through it
  validation = nil
  unless hash['validation'].nil?
    validation = []
    hash['validation'].each do |structure|
      validation << (ValidationRule.from_hash(structure) if structure)
    end
  end

  validation = SKIP unless hash.key?('validation')

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  Profile.new(name: name,
              phone: phone,
              idtype: idtype,
              idcountry: idcountry,
              idnumber: idnumber,
              surname1: surname1,
              surname2: surname2,
              email: email,
              validation: validation,
              additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/logalty_certificate_issuance_api_certy/models/profile.rb', line 50

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['idtype'] = 'idtype'
  @_hash['idcountry'] = 'idcountry'
  @_hash['idnumber'] = 'idnumber'
  @_hash['name'] = 'name'
  @_hash['surname1'] = 'surname1'
  @_hash['surname2'] = 'surname2'
  @_hash['phone'] = 'phone'
  @_hash['email'] = 'email'
  @_hash['validation'] = 'validation'
  @_hash
end

.nullablesObject

An array for nullable fields



78
79
80
# File 'lib/logalty_certificate_issuance_api_certy/models/profile.rb', line 78

def self.nullables
  []
end

.optionalsObject

An array for optional fields



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/logalty_certificate_issuance_api_certy/models/profile.rb', line 65

def self.optionals
  %w[
    idtype
    idcountry
    idnumber
    surname1
    surname2
    email
    validation
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



153
154
155
156
157
158
159
# File 'lib/logalty_certificate_issuance_api_certy/models/profile.rb', line 153

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} idtype: #{@idtype.inspect}, idcountry: #{@idcountry.inspect}, idnumber:"\
  " #{@idnumber.inspect}, name: #{@name.inspect}, surname1: #{@surname1.inspect}, surname2:"\
  " #{@surname2.inspect}, phone: #{@phone.inspect}, email: #{@email.inspect}, validation:"\
  " #{@validation.inspect}, additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



145
146
147
148
149
150
# File 'lib/logalty_certificate_issuance_api_certy/models/profile.rb', line 145

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} idtype: #{@idtype}, idcountry: #{@idcountry}, idnumber: #{@idnumber}, name:"\
  " #{@name}, surname1: #{@surname1}, surname2: #{@surname2}, phone: #{@phone}, email:"\
  " #{@email}, validation: #{@validation}, additional_properties: #{@additional_properties}>"
end