Class: MatrixSdk::User
- Inherits:
-
Object
- Object
- MatrixSdk::User
- Defined in:
- lib/matrix_sdk/user.rb
Overview
A class for tracking information about a user on Matrix
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#id ⇒ Object
(also: #user_id)
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #avatar_url ⇒ Object
- #avatar_url=(url) ⇒ Object
- #display_name ⇒ Object
- #display_name=(name) ⇒ Object
- #friendly_name ⇒ Object
-
#initialize(client, id, data = {}) ⇒ User
constructor
A new instance of User.
Constructor Details
#initialize(client, id, data = {}) ⇒ User
Returns a new instance of User.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/matrix_sdk/user.rb', line 11 def initialize(client, id, data = {}) @client = client @id = id @display_name = nil @avatar_url = nil data.each do |k, v| instance_variable_set("@#{k}", v) if instance_variable_defined? "@#{k}" end end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/matrix_sdk/user.rb', line 6 def client @client end |
#id ⇒ Object (readonly) Also known as: user_id
Returns the value of attribute id.
6 7 8 |
# File 'lib/matrix_sdk/user.rb', line 6 def id @id end |
Instance Method Details
#avatar_url ⇒ Object
38 39 40 |
# File 'lib/matrix_sdk/user.rb', line 38 def avatar_url @avatar_url ||= client.api.get_avatar_url(id)[:avatar_url] end |
#avatar_url=(url) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/matrix_sdk/user.rb', line 42 def avatar_url=(url) client.api.set_avatar_url(id, url) @avatar_url = url rescue MatrixError nil end |
#display_name ⇒ Object
23 24 25 |
# File 'lib/matrix_sdk/user.rb', line 23 def display_name @display_name ||= client.api.get_display_name(id)[:displayname] end |
#display_name=(name) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/matrix_sdk/user.rb', line 27 def display_name=(name) client.api.set_display_name(id, name) @display_name = name rescue MatrixError nil end |
#friendly_name ⇒ Object
34 35 36 |
# File 'lib/matrix_sdk/user.rb', line 34 def friendly_name display_name || id end |