Sha256: 25e72dbd45584adb44c5b0120722272f0ceaf70af8eeea603e0d4c6edeece306

Contents?: true

Size: 979 Bytes

Versions: 4

Compression:

Stored size: 979 Bytes

Contents

# frozen_string_literal: true

module Trusona
  module Resources
    #
    ## A TruCode used for magic logins
    class TruCode < BaseResource
      include Trusona::Resources::Validators
      include Trusona::Helpers::KeyNormalizer

      attr_reader :relying_party_id, :payload, :id

      def initialize(params = {})
        normalized_params = normalize_keys(params)
        @id = normalized_params[:id]
        @payload = normalized_params[:payload]
        @relying_party_id = normalized_params[:relying_party_id] ||
                            Trusona::TruCodeConfig.new.relying_party_id
        raise ArgumentError unless validate
      end

      def to_json(*_args)
        JSON(to_h)
      end

      def to_h
        {
          id: @id,
          relying_party_id: @relying_party_id,
          payload: @payload
        }
      end

      private

      def validate
        return false unless present?(@relying_party_id)

        true
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
trusona-2.5.3 lib/trusona/resources/tru_code.rb
trusona-2.5.2 lib/trusona/resources/tru_code.rb
trusona-2.5.1 lib/trusona/resources/tru_code.rb
trusona-2.5.0 lib/trusona/resources/tru_code.rb