Class: WorkOS::DirectoryUser

Inherits:
DeprecatedHashWrapper show all
Includes:
HashProvider
Defined in:
lib/workos/directory_user.rb

Overview

The DirectoryUser class provides a lightweight wrapper around a WorkOS DirectoryUser resource. This class is not meant to be instantiated in DirectoryUser space, and is instantiated internally but exposed.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HashProvider

#to_h

Methods inherited from DeprecatedHashWrapper

#[], #replace_without_warning

Constructor Details

#initialize(json) ⇒ DirectoryUser

rubocop:disable Metrics/AbcSize



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/workos/directory_user.rb', line 15

def initialize(json)
  hash = JSON.parse(json, symbolize_names: true)

  @id = hash[:id]
  @directory_id = hash[:directory_id]
  @organization_id = hash[:organization_id]
  @idp_id = hash[:idp_id]
  @email = hash[:email]
  # @deprecated Will be removed in a future major version.
  # Enable the `emails` custom attribute in dashboard and pull from customAttributes instead.
  # See https://workos.com/docs/directory-sync/attributes/custom-attributes/auto-mapped-attributes for details.
  @emails = hash[:emails]
  @first_name = hash[:first_name]
  @last_name = hash[:last_name]
  # @deprecated Will be removed in a future major version.
  # Enable the `job_title` custom attribute in dashboard and pull from customAttributes instead.
  # See https://workos.com/docs/directory-sync/attributes/custom-attributes/auto-mapped-attributes for details.
  @job_title = hash[:job_title]
  # @deprecated Will be removed in a future major version.
  # Enable the `username` custom attribute in dashboard and pull from customAttributes instead.
  # See https://workos.com/docs/directory-sync/attributes/custom-attributes/auto-mapped-attributes for details.
  @username = hash[:username]
  @state = hash[:state]
  @groups = hash[:groups]
  @role = hash[:role]
  @custom_attributes = hash[:custom_attributes]
  @raw_attributes = hash[:raw_attributes]
  @created_at = hash[:created_at]
  @updated_at = hash[:updated_at]

  replace_without_warning(to_json)
end

Instance Attribute Details

#created_atObject

Returns the value of attribute created_at.



10
11
12
# File 'lib/workos/directory_user.rb', line 10

def created_at
  @created_at
end

#custom_attributesObject

Returns the value of attribute custom_attributes.



10
11
12
# File 'lib/workos/directory_user.rb', line 10

def custom_attributes
  @custom_attributes
end

#directory_idObject

Returns the value of attribute directory_id.



10
11
12
# File 'lib/workos/directory_user.rb', line 10

def directory_id
  @directory_id
end

#emailObject

Returns the value of attribute email.



10
11
12
# File 'lib/workos/directory_user.rb', line 10

def email
  @email
end

#emailsObject

Returns the value of attribute emails.



10
11
12
# File 'lib/workos/directory_user.rb', line 10

def emails
  @emails
end

#first_nameObject

Returns the value of attribute first_name.



10
11
12
# File 'lib/workos/directory_user.rb', line 10

def first_name
  @first_name
end

#groupsObject

Returns the value of attribute groups.



10
11
12
# File 'lib/workos/directory_user.rb', line 10

def groups
  @groups
end

#idObject

Returns the value of attribute id.



10
11
12
# File 'lib/workos/directory_user.rb', line 10

def id
  @id
end

#idp_idObject

Returns the value of attribute idp_id.



10
11
12
# File 'lib/workos/directory_user.rb', line 10

def idp_id
  @idp_id
end

#job_titleObject

Returns the value of attribute job_title.



10
11
12
# File 'lib/workos/directory_user.rb', line 10

def job_title
  @job_title
end

#last_nameObject

Returns the value of attribute last_name.



10
11
12
# File 'lib/workos/directory_user.rb', line 10

def last_name
  @last_name
end

#organization_idObject

Returns the value of attribute organization_id.



10
11
12
# File 'lib/workos/directory_user.rb', line 10

def organization_id
  @organization_id
end

#raw_attributesObject

Returns the value of attribute raw_attributes.



10
11
12
# File 'lib/workos/directory_user.rb', line 10

def raw_attributes
  @raw_attributes
end

#roleObject

Returns the value of attribute role.



10
11
12
# File 'lib/workos/directory_user.rb', line 10

def role
  @role
end

#stateObject

Returns the value of attribute state.



10
11
12
# File 'lib/workos/directory_user.rb', line 10

def state
  @state
end

#updated_atObject

Returns the value of attribute updated_at.



10
11
12
# File 'lib/workos/directory_user.rb', line 10

def updated_at
  @updated_at
end

#usernameObject

Returns the value of attribute username.



10
11
12
# File 'lib/workos/directory_user.rb', line 10

def username
  @username
end

Instance Method Details

#primary_emailObject

Deprecated.

Will be removed in a future major version. Use #email instead.



72
73
74
75
# File 'lib/workos/directory_user.rb', line 72

def primary_email
  primary_email = (emails || []).find { |email| email[:primary] }
  return primary_email[:value] if primary_email
end

#to_jsonObject

rubocop:enable Metrics/AbcSize



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/workos/directory_user.rb', line 49

def to_json(*)
  {
    id: id,
    directory_id: directory_id,
    organization_id: organization_id,
    idp_id: idp_id,
    email: email,
    emails: emails,
    first_name: first_name,
    last_name: last_name,
    job_title: job_title,
    username: username,
    state: state,
    groups: groups,
    role: role,
    custom_attributes: custom_attributes,
    raw_attributes: raw_attributes,
    created_at: created_at,
    updated_at: updated_at,
  }
end