Class: RocketChat::Room

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

Overview

Rocket.Chat Room

Constant Summary collapse

TYPES =
{
  'c' => 'public',
  'p' => 'private',
  'd' => 'IM'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Room

Returns a new instance of Room.

Parameters:

  • data (Hash)

    Raw user data



20
21
22
# File 'lib/rocket_chat/room.rb', line 20

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/room.rb', line 9

def data
  @data
end

Instance Method Details

#created_atObject



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

def created_at
  data['ts']
end

#descriptionObject



51
52
53
# File 'lib/rocket_chat/room.rb', line 51

def description
  data['description']
end

#idObject

Channel ID



25
26
27
# File 'lib/rocket_chat/room.rb', line 25

def id
  data['_id']
end

#inspectObject



85
86
87
88
89
90
91
92
93
94
# File 'lib/rocket_chat/room.rb', line 85

def inspect
  format(
    '#<%<class_name>s:0x%<object_id>p @id="%<id>s" @name="%<name>s" @type="%<type>s">',
    class_name: self.class.name,
    object_id: object_id,
    id: id,
    name: name,
    type: type
  )
end

#last_messageObject

Last message timestamp



71
72
73
# File 'lib/rocket_chat/room.rb', line 71

def last_message
  data['lm']
end

#last_updateObject



43
44
45
# File 'lib/rocket_chat/room.rb', line 43

def last_update
  data['_updatedAt']
end

#membersObject

Channel members



56
57
58
# File 'lib/rocket_chat/room.rb', line 56

def members
  data['usernames'] || []
end

#message_countObject

Message count



66
67
68
# File 'lib/rocket_chat/room.rb', line 66

def message_count
  data['msgs']
end

#nameObject

Channel name



30
31
32
# File 'lib/rocket_chat/room.rb', line 30

def name
  data['name']
end

#ownerObject

Channel owner



35
36
37
# File 'lib/rocket_chat/room.rb', line 35

def owner
  data['u']
end

#read_onlyObject

Read-only status



61
62
63
# File 'lib/rocket_chat/room.rb', line 61

def read_only
  data['ro']
end

#system_messagesObject

System messages (user left, got invited, room renamed, etc)



81
82
83
# File 'lib/rocket_chat/room.rb', line 81

def system_messages
  data['sysMes']
end

#topicObject



47
48
49
# File 'lib/rocket_chat/room.rb', line 47

def topic
  data['topic']
end

#typeObject

Channel type



76
77
78
# File 'lib/rocket_chat/room.rb', line 76

def type
  TYPES[data['t']] || data['t']
end