Class: RocketChat::User

Inherits:
Object
  • Object
show all
Defined in:
lib/rocket_chat/user.rb

Overview

Rocket.Chat User

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ User

Returns a new instance of User.

Parameters:

  • data (Hash)

    Raw user data



14
15
16
# File 'lib/rocket_chat/user.rb', line 14

def initialize(data)
  @data = Util.stringify_hash_keys data
end

Instance Attribute Details

#dataObject (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

Returns:

  • (Boolean)


64
65
66
# File 'lib/rocket_chat/user.rb', line 64

def active?
  data['active']
end

#emailObject

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

Returns:

  • (Boolean)


39
40
41
# File 'lib/rocket_chat/user.rb', line 39

def email_verified?
  emails.first && emails.first['verified']
end

#emailsObject

User emails



29
30
31
# File 'lib/rocket_chat/user.rb', line 29

def emails
  data['emails'] || []
end

#idObject

User ID



19
20
21
# File 'lib/rocket_chat/user.rb', line 19

def id
  data['_id']
end

#inspectObject



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

#nameObject

User name



24
25
26
# File 'lib/rocket_chat/user.rb', line 24

def name
  data['name']
end

#rolesObject

User roles



69
70
71
# File 'lib/rocket_chat/user.rb', line 69

def roles
  data['roles']
end

#roomsObject

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

#statusObject

User status



44
45
46
# File 'lib/rocket_chat/user.rb', line 44

def status
  data['status']
end

#status_connectionObject

User connection status



49
50
51
# File 'lib/rocket_chat/user.rb', line 49

def status_connection
  data['statusConnection']
end

#usernameObject

User username



54
55
56
# File 'lib/rocket_chat/user.rb', line 54

def username
  data['username']
end

#utc_offsetObject

User UTC offset



59
60
61
# File 'lib/rocket_chat/user.rb', line 59

def utc_offset
  data['utcOffset']
end