Class: WorkOS::Profile

Inherits:
Object
  • Object
show all
Includes:
HashProvider
Defined in:
lib/workos/profile.rb

Overview

The Profile class provides a lighweight wrapper around a normalized response from the various IDPs WorkOS supports as part of the SSO integration. This class is not meant to be instantiated in user space, and is instantiated internally but exposed.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HashProvider

#to_h

Constructor Details

#initialize(profile_json) ⇒ Profile

rubocop:disable Metrics/AbcSize



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/workos/profile.rb', line 16

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

  @id = hash[:id]
  @email = hash[:email]
  @first_name = hash[:first_name]
  @last_name = hash[:last_name]
  @role = hash[:role]
  @groups = hash[:groups]
  @organization_id = hash[:organization_id]
  @connection_id = hash[:connection_id]
  @connection_type = hash[:connection_type]
  @idp_id = hash[:idp_id]
  @custom_attributes = hash[:custom_attributes]
  @raw_attributes = hash[:raw_attributes]
end

Instance Attribute Details

#connection_idObject

Returns the value of attribute connection_id.



12
13
14
# File 'lib/workos/profile.rb', line 12

def connection_id
  @connection_id
end

#connection_typeObject

Returns the value of attribute connection_type.



12
13
14
# File 'lib/workos/profile.rb', line 12

def connection_type
  @connection_type
end

#custom_attributesObject

Returns the value of attribute custom_attributes.



12
13
14
# File 'lib/workos/profile.rb', line 12

def custom_attributes
  @custom_attributes
end

#emailObject

Returns the value of attribute email.



12
13
14
# File 'lib/workos/profile.rb', line 12

def email
  @email
end

#first_nameObject

Returns the value of attribute first_name.



12
13
14
# File 'lib/workos/profile.rb', line 12

def first_name
  @first_name
end

#groupsObject

Returns the value of attribute groups.



12
13
14
# File 'lib/workos/profile.rb', line 12

def groups
  @groups
end

#idObject

Returns the value of attribute id.



12
13
14
# File 'lib/workos/profile.rb', line 12

def id
  @id
end

#idp_idObject

Returns the value of attribute idp_id.



12
13
14
# File 'lib/workos/profile.rb', line 12

def idp_id
  @idp_id
end

#last_nameObject

Returns the value of attribute last_name.



12
13
14
# File 'lib/workos/profile.rb', line 12

def last_name
  @last_name
end

#organization_idObject

Returns the value of attribute organization_id.



12
13
14
# File 'lib/workos/profile.rb', line 12

def organization_id
  @organization_id
end

#raw_attributesObject

Returns the value of attribute raw_attributes.



12
13
14
# File 'lib/workos/profile.rb', line 12

def raw_attributes
  @raw_attributes
end

#roleObject

Returns the value of attribute role.



12
13
14
# File 'lib/workos/profile.rb', line 12

def role
  @role
end

Instance Method Details

#full_nameObject

rubocop:enable Metrics/AbcSize



34
35
36
# File 'lib/workos/profile.rb', line 34

def full_name
  [first_name, last_name].compact.join(' ')
end

#to_jsonObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/workos/profile.rb', line 38

def to_json(*)
  {
    id: id,
    email: email,
    first_name: first_name,
    last_name: last_name,
    role: role,
    groups: groups,
    organization_id: organization_id,
    connection_id: connection_id,
    connection_type: connection_type,
    idp_id: idp_id,
    custom_attributes: custom_attributes,
    raw_attributes: raw_attributes,
  }
end