Class: Syncano::Packets::Base

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

Overview

Base class for representing packets used in communication with the Sync Server

Direct Known Subclasses

Auth, Call, CallResponse, Error, Message, Notification, Ping

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Base

Constructor for Syncano::Packets::Base object

Parameters:

  • attributes (Hash)


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

def initialize(attributes)
  super()
  self.timestamp = attributes[:timestamp]
  self.object = attributes[:object]
end

Instance Attribute Details

#objectObject

Returns the value of attribute object.



6
7
8
# File 'lib/syncano/packets/base.rb', line 6

def object
  @object
end

#timestampObject

Returns the value of attribute timestamp.



6
7
8
# File 'lib/syncano/packets/base.rb', line 6

def timestamp
  @timestamp
end

Class Method Details

.instantize_packet(data) ⇒ Syncano::Packets::Base

Proxy method for creating instance of proper subclass

Parameters:

  • data (Hash)

Returns:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/syncano/packets/base.rb', line 19

def self.instantize_packet(data)
  mapping = {
    auth: ::Syncano::Packets::Auth,
    call: ::Syncano::Packets::Call,
    callresponse: ::Syncano::Packets::CallResponse,
    error: ::Syncano::Packets::Error,
    message: ::Syncano::Packets::Message,
    new: ::Syncano::Packets::Notification,
    change: ::Syncano::Packets::Notification,
    delete: ::Syncano::Packets::Notification,
    ping: ::Syncano::Packets::Ping
  }

  mapping[data[:type].to_sym].new(data)
end

Instance Method Details

#auth?TrueClass, FalseClass

Returns true if is an auth packet

Returns:

  • (TrueClass, FalseClass)


61
62
63
# File 'lib/syncano/packets/base.rb', line 61

def auth?
  false
end

#call_response?TrueClass, FalseClass

Returns true if is a call response packet

Returns:

  • (TrueClass, FalseClass)


49
50
51
# File 'lib/syncano/packets/base.rb', line 49

def call_response?
  false
end

#message?TrueClass, FalseClass

Returns true if is a message packet

Returns:

  • (TrueClass, FalseClass)


55
56
57
# File 'lib/syncano/packets/base.rb', line 55

def message?
  false
end

#notification?TrueClass, FalseClass

Returns true if is a notification packet

Returns:

  • (TrueClass, FalseClass)


37
38
39
# File 'lib/syncano/packets/base.rb', line 37

def notification?
  false
end

#ping?TrueClass, FalseClass

Returns true if is a ping packet

Returns:

  • (TrueClass, FalseClass)


43
44
45
# File 'lib/syncano/packets/base.rb', line 43

def ping?
  false
end