Class: NewStoreApi::User

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/new_store_api/models/user.rb

Overview

User 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(associate_id = SKIP, created_at = SKIP, email = SKIP, external_directory = SKIP, first_name = SKIP, id = SKIP, is_active = SKIP, last_login_at = SKIP, last_name = SKIP, phone = SKIP, roles = SKIP, updated_at = SKIP) ⇒ User

Returns a new instance of User.



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/new_store_api/models/user.rb', line 105

def initialize(associate_id = SKIP, created_at = SKIP, email = SKIP,
               external_directory = SKIP, first_name = SKIP, id = SKIP,
               is_active = SKIP,  = SKIP, last_name = SKIP,
               phone = SKIP, roles = SKIP, updated_at = SKIP)
  @associate_id = associate_id unless associate_id == SKIP
  @created_at = created_at unless created_at == SKIP
  @email = email unless email == SKIP
  @external_directory = external_directory unless external_directory == SKIP
  @first_name = first_name unless first_name == SKIP
  @id = id unless id == SKIP
  @is_active = is_active unless is_active == SKIP
  @last_login_at =  unless  == SKIP
  @last_name = last_name unless last_name == SKIP
  @phone = phone unless phone == SKIP
  @roles = roles unless roles == SKIP
  @updated_at = updated_at unless updated_at == SKIP
end

Instance Attribute Details

#associate_idString

External identifier for the NewStore plattform. Formerly known as "newstore_id".

Returns:

  • (String)


16
17
18
# File 'lib/new_store_api/models/user.rb', line 16

def associate_id
  @associate_id
end

#created_atDateTime

External identifier for the NewStore plattform. Formerly known as "newstore_id".

Returns:

  • (DateTime)


21
22
23
# File 'lib/new_store_api/models/user.rb', line 21

def created_at
  @created_at
end

#emailString

Email address of the user.

Returns:

  • (String)


25
26
27
# File 'lib/new_store_api/models/user.rb', line 25

def email
  @email
end

#external_directoryTrueClass | FalseClass

User is managed by an external directory.

Returns:

  • (TrueClass | FalseClass)


29
30
31
# File 'lib/new_store_api/models/user.rb', line 29

def external_directory
  @external_directory
end

#first_nameString

First name of the user.

Returns:

  • (String)


33
34
35
# File 'lib/new_store_api/models/user.rb', line 33

def first_name
  @first_name
end

#idString

Identifier of the user.

Returns:

  • (String)


37
38
39
# File 'lib/new_store_api/models/user.rb', line 37

def id
  @id
end

#is_activeTrueClass | FalseClass

Whether the user can login or not.

Returns:

  • (TrueClass | FalseClass)


41
42
43
# File 'lib/new_store_api/models/user.rb', line 41

def is_active
  @is_active
end

#last_login_atDateTime

Shows last login time of the user. If user never logged in the property is not presence.

Returns:

  • (DateTime)


46
47
48
# File 'lib/new_store_api/models/user.rb', line 46

def 
  @last_login_at
end

#last_nameString

Last name of the user.

Returns:

  • (String)


50
51
52
# File 'lib/new_store_api/models/user.rb', line 50

def last_name
  @last_name
end

#phoneString

Telephone number of the user.

Returns:

  • (String)


54
55
56
# File 'lib/new_store_api/models/user.rb', line 54

def phone
  @phone
end

#rolesArray[RoleItem]

List of roles the user is assigned to.

Returns:



58
59
60
# File 'lib/new_store_api/models/user.rb', line 58

def roles
  @roles
end

#updated_atDateTime

List of roles the user is assigned to.

Returns:

  • (DateTime)


62
63
64
# File 'lib/new_store_api/models/user.rb', line 62

def updated_at
  @updated_at
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/new_store_api/models/user.rb', line 124

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  associate_id = hash.key?('associate_id') ? hash['associate_id'] : SKIP
  created_at = if hash.key?('created_at')
                 (DateTimeHelper.from_rfc3339(hash['created_at']) if hash['created_at'])
               else
                 SKIP
               end
  email = hash.key?('email') ? hash['email'] : SKIP
  external_directory =
    hash.key?('external_directory') ? hash['external_directory'] : SKIP
  first_name = hash.key?('first_name') ? hash['first_name'] : SKIP
  id = hash.key?('id') ? hash['id'] : SKIP
  is_active = hash.key?('is_active') ? hash['is_active'] : SKIP
   = if hash.key?('last_login_at')
                    (DateTimeHelper.from_rfc3339(hash['last_login_at']) if hash['last_login_at'])
                  else
                    SKIP
                  end
  last_name = hash.key?('last_name') ? hash['last_name'] : SKIP
  phone = hash.key?('phone') ? hash['phone'] : SKIP
  # Parameter is an array, so we need to iterate through it
  roles = nil
  unless hash['roles'].nil?
    roles = []
    hash['roles'].each do |structure|
      roles << (RoleItem.from_hash(structure) if structure)
    end
  end

  roles = SKIP unless hash.key?('roles')
  updated_at = if hash.key?('updated_at')
                 (DateTimeHelper.from_rfc3339(hash['updated_at']) if hash['updated_at'])
               else
                 SKIP
               end

  # Create object from extracted values.
  User.new(associate_id,
           created_at,
           email,
           external_directory,
           first_name,
           id,
           is_active,
           ,
           last_name,
           phone,
           roles,
           updated_at)
end

.namesObject

A mapping from model property names to API property names.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/new_store_api/models/user.rb', line 65

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['associate_id'] = 'associate_id'
  @_hash['created_at'] = 'created_at'
  @_hash['email'] = 'email'
  @_hash['external_directory'] = 'external_directory'
  @_hash['first_name'] = 'first_name'
  @_hash['id'] = 'id'
  @_hash['is_active'] = 'is_active'
  @_hash['last_login_at'] = 'last_login_at'
  @_hash['last_name'] = 'last_name'
  @_hash['phone'] = 'phone'
  @_hash['roles'] = 'roles'
  @_hash['updated_at'] = 'updated_at'
  @_hash
end

.nullablesObject

An array for nullable fields



101
102
103
# File 'lib/new_store_api/models/user.rb', line 101

def self.nullables
  []
end

.optionalsObject

An array for optional fields



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

def self.optionals
  %w[
    associate_id
    created_at
    email
    external_directory
    first_name
    id
    is_active
    last_login_at
    last_name
    phone
    roles
    updated_at
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



200
201
202
203
204
205
206
207
# File 'lib/new_store_api/models/user.rb', line 200

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} associate_id: #{@associate_id.inspect}, created_at: #{@created_at.inspect},"\
  " email: #{@email.inspect}, external_directory: #{@external_directory.inspect}, first_name:"\
  " #{@first_name.inspect}, id: #{@id.inspect}, is_active: #{@is_active.inspect},"\
  " last_login_at: #{@last_login_at.inspect}, last_name: #{@last_name.inspect}, phone:"\
  " #{@phone.inspect}, roles: #{@roles.inspect}, updated_at: #{@updated_at.inspect}>"
end

#to_custom_created_atObject



178
179
180
# File 'lib/new_store_api/models/user.rb', line 178

def to_custom_created_at
  DateTimeHelper.to_rfc3339(created_at)
end

#to_custom_last_login_atObject



182
183
184
# File 'lib/new_store_api/models/user.rb', line 182

def 
  DateTimeHelper.to_rfc3339()
end

#to_custom_updated_atObject



186
187
188
# File 'lib/new_store_api/models/user.rb', line 186

def to_custom_updated_at
  DateTimeHelper.to_rfc3339(updated_at)
end

#to_sObject

Provides a human-readable string representation of the object.



191
192
193
194
195
196
197
# File 'lib/new_store_api/models/user.rb', line 191

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} associate_id: #{@associate_id}, created_at: #{@created_at}, email:"\
  " #{@email}, external_directory: #{@external_directory}, first_name: #{@first_name}, id:"\
  " #{@id}, is_active: #{@is_active}, last_login_at: #{@last_login_at}, last_name:"\
  " #{@last_name}, phone: #{@phone}, roles: #{@roles}, updated_at: #{@updated_at}>"
end