Sha256: 3d946aa5ac69ed03f9b9d7bc606170a003c0bd98b80d43f8da602b2d25f0f5f5

Contents?: true

Size: 1.65 KB

Versions: 6

Compression:

Stored size: 1.65 KB

Contents

# frozen_string_literal: true

module Yoti
  module Sandbox
    module Profile
      #
      # Represents an anchor that can be used by the profile sandbox service
      #
      class Anchor
        #
        # @param [String] type
        # @param [String] value
        # @param [String] sub_type
        # @param [DateTime|Time] timestamp
        #
        def initialize(type:, value:, sub_type: '', timestamp: Time.now)
          @type = type
          @value = value
          @sub_type = sub_type
          @timestamp = timestamp
        end

        #
        # @return [Hash]
        #
        def as_json(*_args)
          {
            type: @type,
            value: @value,
            sub_type: @sub_type,
            timestamp: @timestamp.strftime('%s').to_i * 1_000_000
          }
        end

        #
        # @return [String]
        #
        def to_json(*args)
          as_json.to_json(*args)
        end

        #
        # @param [String] value
        # @param [String] sub_type
        # @param [DateTime|Time] timestamp
        #
        def self.source(value, sub_type: '', timestamp: Time.now)
          Anchor.new(
            type: 'SOURCE',
            value: value,
            sub_type: sub_type,
            timestamp: timestamp
          )
        end

        #
        # @param [String] value
        # @param [String] sub_type
        # @param [DateTime|Time] timestamp
        #
        def self.verifier(value, sub_type: '', timestamp: Time.now)
          Anchor.new(
            type: 'VERIFIER',
            value: value,
            sub_type: sub_type,
            timestamp: timestamp
          )
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
yoti_sandbox-1.4.0 lib/yoti_sandbox/profile/anchor.rb
yoti_sandbox-1.3.0 lib/yoti_sandbox/profile/anchor.rb
yoti_sandbox-1.2.1 lib/yoti_sandbox/profile/anchor.rb
yoti_sandbox-1.2.0 lib/yoti_sandbox/profile/anchor.rb
yoti_sandbox-1.1.0 lib/yoti_sandbox/profile/anchor.rb
yoti_sandbox-1.0.0 lib/yoti_sandbox/profile/anchor.rb