lib/yoti/activity_details.rb in yoti-1.3.1 vs lib/yoti/activity_details.rb in yoti-1.4.0

- old
+ new

@@ -4,13 +4,20 @@ # Encapsulates the user profile data class ActivityDetails # @return [String] the outcome of the profile request, eg: SUCCESS attr_reader :outcome + # @deprecated replaced by :remember_me_id # @return [String] the Yoti ID attr_reader :user_id + # @return [String] the Remember Me ID + attr_reader :remember_me_id + + # @return [String] the Parent Remember Me ID + attr_reader :parent_remember_me_id + # @return [Hash] the decoded profile attributes attr_reader :user_profile # @return [String] the selfie in base64 format attr_reader :base64_selfie_uri @@ -19,43 +26,60 @@ 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 + @remember_me_id = receipt['remember_me_id'] + @user_id = @remember_me_id + @parent_remember_me_id = receipt['parent_remember_me_id'] + @outcome = receipt['sharing_outcome'] @user_profile = {} @extended_profile = {} + process_decrypted_profile(decrypted_profile) + end - 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 + # @return [Hash] a JSON of the address + def structured_postal_address + @user_profile['structured_postal_address'] + end - if field.name == 'selfie' - @base64_selfie_uri = Yoti::Protobuf.image_uri_based_on_content_type(field.value, field.content_type) - end + # @return [Profile] of Yoti user + def profile + Yoti::Profile.new(@extended_profile) + end + protected - if Yoti::AgeProcessor.is_age_verification(field.name) - @age_verified = field.value == 'true' - end + def process_decrypted_profile(decrypted_profile) + return nil unless decrypted_profile.is_a?(Object) + return nil unless decrypted_profile.respond_to?(:attributes) - @extended_profile[field.name] = Yoti::Attribute.new(field.name, field.value, anchors_list['sources'], anchors_list['verifiers']) + decrypted_profile.attributes.each do |attribute| + begin + process_attribute(attribute) + process_age_verified(attribute) + rescue StandardError => e + Yoti::Log.logger.warn("#{e.message} (Attribute: #{attribute.name})") 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'] + def process_attribute(attribute) + attr_value = Yoti::Protobuf.value_based_on_content_type(attribute.value, attribute.content_type) + attr_value = Yoti::Protobuf.value_based_on_attribute_name(attr_value, attribute.name) + + # Handle selfies for backwards compatibility. + if attribute.name == Yoti::Attribute::SELFIE && attr_value.is_a?(Yoti::Image) + @base64_selfie_uri = attr_value.base64_content + attr_value = attr_value.content + end + + anchors_list = Yoti::AnchorProcessor.new(attribute.anchors).process + @extended_profile[attribute.name] = Yoti::Attribute.new(attribute.name, attr_value, anchors_list['sources'], anchors_list['verifiers']) + @user_profile[attribute.name] = attr_value end - # @return [Profile] of Yoti user - def profile - return Yoti::Profile.new(@extended_profile) + def process_age_verified(attribute) + @age_verified = attribute.value == 'true' if Yoti::AgeProcessor.is_age_verification(attribute.name) end end end