Module: DataModels
- Included in:
- ScClient
- Defined in:
- lib/socketclusterclient/data_models.rb
Overview
Module DataModels provides JSON format based serialized and deserialized objects that ensures tight coupling
Instance Method Summary collapse
-
#get_ack_object(error, data, cid) ⇒ Object
Returns a data model for an acknowledgment event.
-
#get_emit_ack_object(event, object, counter) ⇒ Object
Returns a data model for an emitter acknowledgment event.
-
#get_emit_object(event, object) ⇒ Object
Returns a data model for an emitter event.
-
#get_handshake_object(counter) ⇒ Object
Returns a data model for a handshake event.
-
#get_publish_object(channel, data, counter) ⇒ Object
Returns a data model for publish and publish with acknowledgment event.
-
#get_subscribe_object(channel, counter) ⇒ Object
Returns a data model for subscribe and subscribe with acknowledgment event.
-
#get_unsubscribe_object(channel, counter) ⇒ Object
Returns a data model for unsubscribe and unsubscribe with acknowledgment event.
Instance Method Details
#get_ack_object(error, data, cid) ⇒ Object
Returns a data model for an acknowledgment event
16 17 18 19 20 21 22 |
# File 'lib/socketclusterclient/data_models.rb', line 16 def get_ack_object(error, data, cid) OpenStruct.new( cid: cid, data: data, error: error ).to_h end |
#get_emit_ack_object(event, object, counter) ⇒ Object
Returns a data model for an emitter acknowledgment event
46 47 48 49 50 51 52 |
# File 'lib/socketclusterclient/data_models.rb', line 46 def get_emit_ack_object(event, object, counter) OpenStruct.new( event: event, data: object, c_id: counter ).to_h end |
#get_emit_object(event, object) ⇒ Object
Returns a data model for an emitter event
31 32 33 34 35 36 |
# File 'lib/socketclusterclient/data_models.rb', line 31 def get_emit_object(event, object) OpenStruct.new( event: event, data: object ).to_h end |
#get_handshake_object(counter) ⇒ Object
Returns a data model for a handshake event
60 61 62 63 64 65 66 67 68 |
# File 'lib/socketclusterclient/data_models.rb', line 60 def get_handshake_object(counter) OpenStruct.new( cid: counter, data: OpenStruct.new( authToken: @auth_token ).to_h, event: '#handshake' ).to_h end |
#get_publish_object(channel, data, counter) ⇒ Object
Returns a data model for publish and publish with acknowledgment event
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/socketclusterclient/data_models.rb', line 78 def get_publish_object(channel, data, counter) OpenStruct.new( cid: counter, data: OpenStruct.new( channel: channel, data: data ).to_h, event: '#publish' ).to_h end |
#get_subscribe_object(channel, counter) ⇒ Object
Returns a data model for subscribe and subscribe with acknowledgment event
96 97 98 99 100 101 102 103 104 |
# File 'lib/socketclusterclient/data_models.rb', line 96 def get_subscribe_object(channel, counter) OpenStruct.new( event: '#subscribe', data: OpenStruct.new( channel: channel ).to_h, cid: counter ).to_h end |
#get_unsubscribe_object(channel, counter) ⇒ Object
Returns a data model for unsubscribe and unsubscribe with acknowledgment event
113 114 115 116 117 118 119 |
# File 'lib/socketclusterclient/data_models.rb', line 113 def get_unsubscribe_object(channel, counter) OpenStruct.new( event: '#unsubscribe', data: channel, cid: counter ).to_h end |