Class: Teems::Models::UserProfile

Inherits:
Data
  • Object
show all
Defined in:
lib/teems/models/user_profile.rb

Overview

Rich user profile with extended fields for who/org commands

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#business_phonesObject (readonly)

Returns the value of attribute business_phones

Returns:

  • (Object)

    the current value of business_phones



6
7
8
# File 'lib/teems/models/user_profile.rb', line 6

def business_phones
  @business_phones
end

#departmentObject (readonly)

Returns the value of attribute department

Returns:

  • (Object)

    the current value of department



6
7
8
# File 'lib/teems/models/user_profile.rb', line 6

def department
  @department
end

#display_nameObject (readonly)

Returns the value of attribute display_name

Returns:

  • (Object)

    the current value of display_name



6
7
8
# File 'lib/teems/models/user_profile.rb', line 6

def display_name
  @display_name
end

#emailObject (readonly)

Returns the value of attribute email

Returns:

  • (Object)

    the current value of email



6
7
8
# File 'lib/teems/models/user_profile.rb', line 6

def email
  @email
end

#idObject (readonly)

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



6
7
8
# File 'lib/teems/models/user_profile.rb', line 6

def id
  @id
end

#job_titleObject (readonly)

Returns the value of attribute job_title

Returns:

  • (Object)

    the current value of job_title



6
7
8
# File 'lib/teems/models/user_profile.rb', line 6

def job_title
  @job_title
end

#mobile_phoneObject (readonly)

Returns the value of attribute mobile_phone

Returns:

  • (Object)

    the current value of mobile_phone



6
7
8
# File 'lib/teems/models/user_profile.rb', line 6

def mobile_phone
  @mobile_phone
end

#office_locationObject (readonly)

Returns the value of attribute office_location

Returns:

  • (Object)

    the current value of office_location



6
7
8
# File 'lib/teems/models/user_profile.rb', line 6

def office_location
  @office_location
end

#user_principal_nameObject (readonly)

Returns the value of attribute user_principal_name

Returns:

  • (Object)

    the current value of user_principal_name



6
7
8
# File 'lib/teems/models/user_profile.rb', line 6

def user_principal_name
  @user_principal_name
end

Class Method Details

.detail_attrs(data) ⇒ Object



26
27
28
29
30
# File 'lib/teems/models/user_profile.rb', line 26

def self.detail_attrs(data)
  { job_title: data['jobTitle'], department: data['department'],
    office_location: data['officeLocation'],
    business_phones: data['businessPhones'] || [], mobile_phone: data['mobilePhone'] }
end

.from_api(data) ⇒ Object



17
18
19
# File 'lib/teems/models/user_profile.rb', line 17

def self.from_api(data)
  new(**identity_attrs(data), **detail_attrs(data))
end

.identity_attrs(data) ⇒ Object



21
22
23
24
# File 'lib/teems/models/user_profile.rb', line 21

def self.identity_attrs(data)
  { id: data['id'], display_name: data['displayName'],
    email: data['mail'] || data['email'], user_principal_name: data['userPrincipalName'] }
end

Instance Method Details

#best_nameObject



32
33
34
# File 'lib/teems/models/user_profile.rb', line 32

def best_name
  [display_name, email, user_principal_name, id].find { |value| value && !value.empty? }
end

#json_attrsObject



36
37
38
# File 'lib/teems/models/user_profile.rb', line 36

def json_attrs
  [to_h, id]
end

#search_displayObject



40
41
42
# File 'lib/teems/models/user_profile.rb', line 40

def search_display
  [best_name, job_title, email]
end