class WorkOS::Profile

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.

Attributes

connection_id[RW]
connection_type[RW]
email[RW]
first_name[RW]
id[RW]
idp_id[RW]
last_name[RW]
raw_attributes[RW]

Public Class Methods

new(profile_json) click to toggle source
# File lib/workos/profile.rb, line 18
def initialize(profile_json)
  raw = parse_json(profile_json)

  @id = T.let(raw.id, String)
  @email = T.let(raw.email, String)
  @first_name = raw.first_name
  @last_name = raw.last_name
  @connection_id = T.let(raw.connection_id, String)
  @connection_type = T.let(raw.connection_type, String)
  @idp_id = raw.idp_id
  @raw_attributes = raw.raw_attributes
end

Public Instance Methods

full_name() click to toggle source
# File lib/workos/profile.rb, line 32
def full_name
  [first_name, last_name].compact.join(' ')
end
to_json(*) click to toggle source
# File lib/workos/profile.rb, line 36
def to_json(*)
  {
    id: id,
    email: email,
    first_name: first_name,
    last_name: last_name,
    connection_id: connection_id,
    connection_type: connection_type,
    idp_id: idp_id,
    raw_attributes: raw_attributes,
  }
end

Private Instance Methods

parse_json(json_string) click to toggle source
# File lib/workos/profile.rb, line 52
def parse_json(json_string)
  hash = JSON.parse(json_string, symbolize_names: true)

  WorkOS::Types::ProfileStruct.new(
    id: hash[:id],
    email: hash[:email],
    first_name: hash[:first_name],
    last_name: hash[:last_name],
    connection_id: hash[:connection_id],
    connection_type: hash[:connection_type],
    idp_id: hash[:idp_id],
    raw_attributes: hash[:raw_attributes],
  )
end