lib/cfoundry/v2/user.rb in cfoundry-2.4.0 vs lib/cfoundry/v2/user.rb in cfoundry-2.4.1.rc1

- old
+ new

@@ -38,20 +38,27 @@ # optional metadata from UAA attr_accessor :emails, :name def email + # if the email collection is nil or empty? collect from UAA + get_meta_from_uaa if @emails.nil? + return unless @emails && @emails.first - @emails.first[:value] + @emails.first["value"] end def given_name + get_meta_from_uaa if @name.nil? + return unless @name && @name[:givenName] != email @name[:givenName] end def family_name + get_meta_from_uaa if @name.nil? + return unless @name && @name[:familyName] != email @name[:familyName] end def full_name @@ -65,8 +72,22 @@ def delete! (options = {}) super(options) @client.base.uaa.delete_user(guid) true end + + private + + def get_meta_from_uaa + user = @client.base.uaa.user(guid) + return if user.nil? + return if not user['error'].nil? + + @emails = user["emails"] + @name ||= {} + @name[:familyName] = user["name"]["familyname"] + @name[:givenName] = user["name"]["givenname"] + end + end end end