Class: RocketChat::User
- Inherits:
-
Object
- Object
- RocketChat::User
- Defined in:
- lib/rocket_chat/user.rb
Overview
Rocket.Chat User
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Raw user data.
Instance Method Summary collapse
-
#active? ⇒ Boolean
User active.
-
#email ⇒ Object
User email.
-
#email_verified? ⇒ Boolean
User email verified.
-
#emails ⇒ Object
User emails.
-
#id ⇒ Object
User ID.
-
#initialize(data) ⇒ User
constructor
A new instance of User.
- #inspect ⇒ Object
-
#name ⇒ Object
User name.
-
#roles ⇒ Object
User roles.
-
#rooms ⇒ Object
User rooms.
-
#status ⇒ Object
User status.
-
#status_connection ⇒ Object
User connection status.
-
#username ⇒ Object
User username.
-
#utc_offset ⇒ Object
User UTC offset.
Constructor Details
#initialize(data) ⇒ User
Returns a new instance of User.
14 15 16 |
# File 'lib/rocket_chat/user.rb', line 14 def initialize(data) @data = Util.stringify_hash_keys data end |
Instance Attribute Details
#data ⇒ Object (readonly)
Raw user data
9 10 11 |
# File 'lib/rocket_chat/user.rb', line 9 def data @data end |
Instance Method Details
#active? ⇒ Boolean
User active
64 65 66 |
# File 'lib/rocket_chat/user.rb', line 64 def active? data['active'] end |
#email ⇒ Object
User email
34 35 36 |
# File 'lib/rocket_chat/user.rb', line 34 def email emails.first && emails.first['address'] end |
#email_verified? ⇒ Boolean
User email verified
39 40 41 |
# File 'lib/rocket_chat/user.rb', line 39 def email_verified? emails.first && emails.first['verified'] end |
#emails ⇒ Object
User emails
29 30 31 |
# File 'lib/rocket_chat/user.rb', line 29 def emails data['emails'] || [] end |
#id ⇒ Object
User ID
19 20 21 |
# File 'lib/rocket_chat/user.rb', line 19 def id data['_id'] end |
#inspect ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/rocket_chat/user.rb', line 88 def inspect format( '#<%<class_name>s:0x%<object_id>p @id="%<id>s" @username="%<username>s" @active="%<active>s">', class_name: self.class.name, object_id: object_id, id: id, username: username, active: active? ) end |
#name ⇒ Object
User name
24 25 26 |
# File 'lib/rocket_chat/user.rb', line 24 def name data['name'] end |
#roles ⇒ Object
User roles
69 70 71 |
# File 'lib/rocket_chat/user.rb', line 69 def roles data['roles'] end |
#rooms ⇒ Object
User rooms
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/rocket_chat/user.rb', line 74 def rooms return [] unless data['rooms'].is_a? Array data['rooms'].map do |hash| # the users.info API returns the rooms data with the subscription ID as `_id` and room ID as `rid` if hash['rid'] hash['subscription_id'] = hash['_id'] hash['_id'] = hash['rid'] end RocketChat::Room.new hash end end |
#status ⇒ Object
User status
44 45 46 |
# File 'lib/rocket_chat/user.rb', line 44 def status data['status'] end |
#status_connection ⇒ Object
User connection status
49 50 51 |
# File 'lib/rocket_chat/user.rb', line 49 def status_connection data['statusConnection'] end |
#username ⇒ Object
User username
54 55 56 |
# File 'lib/rocket_chat/user.rb', line 54 def username data['username'] end |
#utc_offset ⇒ Object
User UTC offset
59 60 61 |
# File 'lib/rocket_chat/user.rb', line 59 def utc_offset data['utcOffset'] end |