Sha256: 402ad867a45ff2d9f56264e6114d4026d10e888ffa8f88aab580b44765c018de

Contents?: true

Size: 1.84 KB

Versions: 1

Compression:

Stored size: 1.84 KB

Contents

module Yoti
  # Encapsulates Yoti user profile
  class Profile
    def initialize(profile_data)
      profile_data = {} unless profile_data.is_a? Object
      @profile_data = profile_data
    end

    def selfie
      get_attribute(Yoti::Attribute::SELFIE)
    end

    def family_name
      get_attribute(Yoti::Attribute::FAMILY_NAME)
    end

    def given_names
      get_attribute(Yoti::Attribute::GIVEN_NAMES)
    end

    def full_name
      get_attribute(Yoti::Attribute::FULL_NAME)
    end

    def phone_number
      get_attribute(Yoti::Attribute::PHONE_NUMBER)
    end

    def email_address
      get_attribute(Yoti::Attribute::EMAIL_ADDRESS)
    end

    def date_of_birth
      get_attribute(Yoti::Attribute::DATE_OF_BIRTH)
    end

    def gender
      get_attribute(Yoti::Attribute::GENDER)
    end

    def nationality
      get_attribute(Yoti::Attribute::NATIONALITY)
    end

    def document_images
      get_attribute(Yoti::Attribute::DOCUMENT_IMAGES)
    end

    def postal_address
      postal_address = get_attribute(Yoti::Attribute::POSTAL_ADDRESS)
      return postal_address unless postal_address.nil?

      attribute_from_formatted_address
    end

    def structured_postal_address
      get_attribute(Yoti::Attribute::STRUCTURED_POSTAL_ADDRESS)
    end

    # @return attribute value by name
    def get_attribute(attr_name)
      return nil unless @profile_data.key? attr_name

      @profile_data[attr_name]
    end

    protected

    def attribute_from_formatted_address
      return nil if structured_postal_address.nil?
      return nil unless structured_postal_address.value.key?('formatted_address')

      Yoti::Attribute.new(
        Yoti::Attribute::POSTAL_ADDRESS,
        structured_postal_address.value['formatted_address'],
        structured_postal_address.sources,
        structured_postal_address.verifiers
      )
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
yoti-1.4.0 lib/yoti/data_type/profile.rb