Class: RocketChat::Realtime::Message

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

Overview

Abstract message model to send a method

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type = 'method', id = nil) ⇒ Message

Returns a new instance of Message.

Parameters:

  • type (String) (defaults to: 'method')

    message type

  • id (String) (defaults to: nil)

    unique id to identity command

Since:

  • 0.1.0



18
19
20
21
# File 'lib/rocket_chat/realtime/message.rb', line 18

def initialize(type = 'method', id = nil)
  @id = id || SecureRandom.uuid
  @type = type
end

Instance Attribute Details

#idObject (readonly)

Since:

  • 0.1.0



12
13
14
# File 'lib/rocket_chat/realtime/message.rb', line 12

def id
  @id
end

#typeObject (readonly)

Since:

  • 0.1.0



12
13
14
# File 'lib/rocket_chat/realtime/message.rb', line 12

def type
  @type
end

Instance Method Details

#bodyHash

Body

Returns:

  • (Hash)

    the message body

Since:

  • 0.1.0



26
27
28
# File 'lib/rocket_chat/realtime/message.rb', line 26

def body
  {}
end

#to_json(options = nil) ⇒ String

Convert to JSON

Returns:

  • (String)

    message json

Since:

  • 0.1.0



33
34
35
36
37
# File 'lib/rocket_chat/realtime/message.rb', line 33

def to_json(options = nil)
  body
    .merge(id: @id, msg: @type)
    .to_json(options)
end