Class: Syncano::Packets::Call

Inherits:
Base
  • Object
show all
Defined in:
lib/syncano/packets/call.rb

Overview

Class representing call packets used in communication with the Sync Server

Instance Attribute Summary collapse

Attributes inherited from Base

#object, #timestamp

Instance Method Summary collapse

Methods inherited from Base

#auth?, #call_response?, instantize_packet, #message?, #notification?, #ping?

Constructor Details

#initialize(attributes) ⇒ Call

Constructor for Syncano::Packets::Call object

Parameters:

  • attributes (Hash)


9
10
11
12
13
14
15
# File 'lib/syncano/packets/call.rb', line 9

def initialize(attributes)
  super(attributes)
  self.resource_name = attributes[:resource_name]
  self.method_name = attributes[:method_name]
  self.data = attributes[:data]
  self.message_id = attributes[:message_id] || rand(10**12)
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



5
6
7
# File 'lib/syncano/packets/call.rb', line 5

def data
  @data
end

#message_idObject

Returns the value of attribute message_id.



5
6
7
# File 'lib/syncano/packets/call.rb', line 5

def message_id
  @message_id
end

#method_nameObject

Returns the value of attribute method_name.



5
6
7
# File 'lib/syncano/packets/call.rb', line 5

def method_name
  @method_name
end

#resource_nameObject

Returns the value of attribute resource_name.



5
6
7
# File 'lib/syncano/packets/call.rb', line 5

def resource_name
  @resource_name
end

Instance Method Details

#as_json(options = {}) ⇒ Hash

Overwritten method for preparing hash for json serialization

Parameters:

  • options (Hash) (defaults to: {})

Returns:

  • (Hash)


20
21
22
23
24
25
26
27
# File 'lib/syncano/packets/call.rb', line 20

def as_json(options = {})
  {
    type: 'call',
    method: "#{resource_name}.#{method_name}",
    params: data,
    message_id: message_id.to_s
  }
end