Class: Syncano::Packets::Base
- Inherits:
-
Object
- Object
- Syncano::Packets::Base
- 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
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Class Method Summary collapse
-
.instantize_packet(data) ⇒ Syncano::Packets::Base
Proxy method for creating instance of proper subclass.
Instance Method Summary collapse
-
#auth? ⇒ TrueClass, FalseClass
Returns true if is an auth packet.
-
#call_response? ⇒ TrueClass, FalseClass
Returns true if is a call response packet.
-
#initialize(attributes) ⇒ Base
constructor
Constructor for Syncano::Packets::Base object.
-
#message? ⇒ TrueClass, FalseClass
Returns true if is a message packet.
-
#notification? ⇒ TrueClass, FalseClass
Returns true if is a notification packet.
-
#ping? ⇒ TrueClass, FalseClass
Returns true if is a ping packet.
Constructor Details
#initialize(attributes) ⇒ Base
Constructor for Syncano::Packets::Base object
10 11 12 13 14 |
# File 'lib/syncano/packets/base.rb', line 10 def initialize(attributes) super() self. = attributes[:timestamp] self.object = attributes[:object] end |
Instance Attribute Details
#object ⇒ Object
Returns the value of attribute object.
6 7 8 |
# File 'lib/syncano/packets/base.rb', line 6 def object @object end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
6 7 8 |
# File 'lib/syncano/packets/base.rb', line 6 def @timestamp end |
Class Method Details
.instantize_packet(data) ⇒ Syncano::Packets::Base
Proxy method for creating instance of proper subclass
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
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
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
55 56 57 |
# File 'lib/syncano/packets/base.rb', line 55 def false end |
#notification? ⇒ TrueClass, FalseClass
Returns true if is a notification packet
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
43 44 45 |
# File 'lib/syncano/packets/base.rb', line 43 def ping? false end |