Sha256: 42b6e8e2f84216c623d942a91ba8712b0e2ec975ccfb37ecbff0995f15b6f3d0

Contents?: true

Size: 1.98 KB

Versions: 2

Compression:

Stored size: 1.98 KB

Contents

require 'net/http'

module Yoti
  # Encapsulates the user profile data
  class ActivityDetails
    # @return [String] the outcome of the profile request, eg: SUCCESS
    attr_reader :outcome

    # @return [String] the Yoti ID
    attr_reader :user_id

    # @return [Hash] the decoded profile attributes
    attr_reader :user_profile

    # @return [String] the selfie in base64 format
    attr_reader :base64_selfie_uri

    # @return [Boolean] the age under/over attribute
    attr_reader :age_verified

    # @param receipt [Hash] the receipt from the API request
    # @param decrypted_profile [Object] Protobuf AttributeList decrypted object containing the profile attributes
    def initialize(receipt, decrypted_profile = nil)
      @decrypted_profile = decrypted_profile
      @user_profile = {}
      @extended_profile = {}

      if @decrypted_profile.is_a?(Object) && @decrypted_profile.respond_to?(:attributes)
        @decrypted_profile.attributes.each do |field|
          @user_profile[field.name] = Yoti::Protobuf.value_based_on_content_type(field.value, field.content_type)
          anchor_processor = Yoti::AnchorProcessor.new(field.anchors)
          anchors_list = anchor_processor.process

          if field.name == 'selfie'
            @base64_selfie_uri = Yoti::Protobuf.image_uri_based_on_content_type(field.value, field.content_type)
          end


          if Yoti::AgeProcessor.is_age_verification(field.name)
            @age_verified = field.value == 'true'
          end

          @extended_profile[field.name] = Yoti::Attribute.new(field.name, field.value, anchors_list['sources'], anchors_list['verifiers'])
        end
      end

      @user_id = receipt['remember_me_id']
      @outcome = receipt['sharing_outcome']
    end

    # @return [Hash] a JSON of the address
    def structured_postal_address
        @user_profile['structured_postal_address']
    end

    # @return [Profile] of Yoti user
    def profile
        return Yoti::Profile.new(@extended_profile)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
yoti-1.3.1 lib/yoti/activity_details.rb
yoti-1.3.0 lib/yoti/activity_details.rb