Class: AmfSocket::RpcMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/amf_socket/rpc_message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, params = {}) ⇒ RpcMessage

Returns a new instance of RpcMessage.

Raises:



7
8
9
10
11
12
13
14
# File 'lib/amf_socket/rpc_message.rb', line 7

def initialize(command, params = {})
  raise AmfSocket::InvalidArg.new('Command must be a String.') unless command.is_a?(String)
  raise AmfSocket::InvalidArg.new('Params must be a Hash.') unless params.is_a?(Hash)

  @command = command
  @params = params
  @message_id = SecureRandom.hex
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



3
4
5
# File 'lib/amf_socket/rpc_message.rb', line 3

def command
  @command
end

#message_idObject (readonly)

Returns the value of attribute message_id.



2
3
4
# File 'lib/amf_socket/rpc_message.rb', line 2

def message_id
  @message_id
end

#paramsObject (readonly)

Returns the value of attribute params.



4
5
6
# File 'lib/amf_socket/rpc_message.rb', line 4

def params
  @params
end

#sent_atObject (readonly)

Returns the value of attribute sent_at.



5
6
7
# File 'lib/amf_socket/rpc_message.rb', line 5

def sent_at
  @sent_at
end

Instance Method Details

#to_hashObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/amf_socket/rpc_message.rb', line 16

def to_hash
  object = {}

  object[:type] = 'rpcMessage'
  object[:message] = {}
  object[:message][:messageId] = message_id
  object[:message][:command] = command
  object[:message][:params] = params

  return object
end