Sha256: aac4697792931036eb415f3a9e5a0e1ab561cb194f3c414b650cd3f6f6728aee

Contents?: true

Size: 1.4 KB

Versions: 21

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true
# typed: false

module WorkOS
  # The Factor 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 Factor
    include HashProvider
    extend T::Sig
    attr_accessor :id, :object, :type, :sms, :totp, :updated_at, :created_at

    sig { params(json: String).void }
    def initialize(json)
      raw = parse_json(json)
      @id = T.let(raw.id, String)
      @object = T.let(raw.object, String)
      @type = T.let(raw.type, String)
      @created_at = T.let(raw.created_at, String)
      @updated_at = T.let(raw.updated_at, String)
      @totp = raw.totp
      @sms = raw.sms
    end

    def to_json(*)
      {
        id: id,
        object: object,
        type: type,
        totp: totp,
        sms: sms,
        created_at: created_at,
        updated_at: updated_at,
      }
    end

    private

    sig { params(json_string: String).returns(WorkOS::Types::FactorStruct) }
    def parse_json(json_string)
      hash = JSON.parse(json_string, symbolize_names: true)

      WorkOS::Types::FactorStruct.new(
        id: hash[:id],
        object: hash[:object],
        type: hash[:type],
        totp: hash[:totp],
        sms: hash[:sms],
        created_at: hash[:created_at],
        updated_at: hash[:updated_at],
      )
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
workos-4.1.0 lib/workos/factor.rb
workos-4.0.0 lib/workos/factor.rb
workos-3.1.0 lib/workos/factor.rb
workos-3.0.0 lib/workos/factor.rb
workos-2.17.0 lib/workos/factor.rb
workos-2.16.0 lib/workos/factor.rb
workos-2.15.0 lib/workos/factor.rb
workos-2.14.0 lib/workos/factor.rb
workos-2.13.0 lib/workos/factor.rb
workos-2.12.1 lib/workos/factor.rb
workos-2.12.0 lib/workos/factor.rb
workos-2.11.0 lib/workos/factor.rb
workos-2.10.0 lib/workos/factor.rb
workos-2.9.0 lib/workos/factor.rb
workos-2.8.0 lib/workos/factor.rb
workos-2.7.0 lib/workos/factor.rb
workos-2.6.0 lib/workos/factor.rb
workos-2.5.1 lib/workos/factor.rb
workos-2.5.0 lib/workos/factor.rb
workos-2.4.0 lib/workos/factor.rb