Sha256: b7df5dd0b6c66e5c6fabe289aa46579fdc6e944cd32a5c1ccf5e2cb9a18600ef

Contents?: true

Size: 1.95 KB

Versions: 8

Compression:

Stored size: 1.95 KB

Contents

# frozen_string_literal: true
# typed: true

module WorkOS
  # 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.
  class DirectoryUser
    extend T::Sig

    attr_accessor :id, :idp_id, :emails, :first_name, :last_name, :username, :state,
                  :groups, :custom_attributes, :raw_attributes

    # rubocop:disable Metrics/AbcSize
    sig { params(json: String).void }
    def initialize(json)
      raw = parse_json(json)

      @id = T.let(raw.id, String)
      @idp_id = T.let(raw.idp_id, String)
      @emails = T.let(raw.emails, Array)
      @first_name = raw.first_name
      @last_name = raw.last_name
      @username = raw.username
      @state = raw.state
      @groups = T.let(raw.groups, Array)
      @custom_attributes = raw.custom_attributes
      @raw_attributes = raw.raw_attributes
    end
    # rubocop:enable Metrics/AbcSize

    def to_json(*)
      {
        id: id,
        idp_id: idp_id,
        emails: emails,
        first_name: first_name,
        last_name: last_name,
        username: username,
        state: state,
        groups: groups,
        custom_attributes: custom_attributes,
        raw_attributes: raw_attributes,
      }
    end

    private

    sig do
      params(
        json_string: String,
      ).returns(WorkOS::Types::DirectoryUserStruct)
    end
    def parse_json(json_string)
      hash = JSON.parse(json_string, symbolize_names: true)

      WorkOS::Types::DirectoryUserStruct.new(
        id: hash[:id],
        idp_id: hash[:idp_id],
        emails: hash[:emails],
        first_name: hash[:first_name],
        last_name: hash[:last_name],
        username: hash[:username],
        state: hash[:state],
        groups: hash[:groups],
        custom_attributes: hash[:custom_attributes],
        raw_attributes: hash[:raw_attributes],
      )
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
workos-2.2.0 lib/workos/directory_user.rb
workos-2.1.1 lib/workos/directory_user.rb
workos-2.1.0 lib/workos/directory_user.rb
workos-2.0.0 lib/workos/directory_user.rb
workos-1.6.1 lib/workos/directory_user.rb
workos-1.6.0 lib/workos/directory_user.rb
workos-1.5.1 lib/workos/directory_user.rb
workos-1.5.0 lib/workos/directory_user.rb