Class: Streamforce::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/streamforce/message.rb

Instance Method Summary collapse

Constructor Details

#initialize(payload) ⇒ Message

Returns a new instance of Message.



2
3
4
# File 'lib/streamforce/message.rb', line 2

def initialize(payload)
  @payload = payload
end

Instance Method Details

#channelObject



18
19
20
# File 'lib/streamforce/message.rb', line 18

def channel
  @payload["channel"]
end

#channel_nameObject



26
27
28
# File 'lib/streamforce/message.rb', line 26

def channel_name
  channel.split("/")[2]
end

#channel_typeObject



22
23
24
# File 'lib/streamforce/message.rb', line 22

def channel_type
  channel.split("/")[1]
end

#client_idObject



6
7
8
# File 'lib/streamforce/message.rb', line 6

def client_id
  @payload["clientId"]
end

#dataObject



34
35
36
# File 'lib/streamforce/message.rb', line 34

def data
  @payload["data"]
end

#error_messageObject



58
59
60
# File 'lib/streamforce/message.rb', line 58

def error_message
  @payload["error"]
end

#idObject



10
11
12
# File 'lib/streamforce/message.rb', line 10

def id
  @payload["id"]
end

#no_replay?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/streamforce/message.rb', line 54

def no_replay?
  replay_id.nil? || replay_id == -1
end

#replay_available_messages?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/streamforce/message.rb', line 50

def replay_available_messages?
  replay_id == -2
end

#replay_from_message?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/streamforce/message.rb', line 46

def replay_from_message?
  replay_id && replay_id != -1 && replay_id != -2
end

#replay_idObject



14
15
16
# File 'lib/streamforce/message.rb', line 14

def replay_id
  @payload.dig "ext", "replay", subscription
end

#subscriptionObject



38
39
40
# File 'lib/streamforce/message.rb', line 38

def subscription
  @payload["subscription"]
end

#subscription?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/streamforce/message.rb', line 42

def subscription?
  channel == "/meta/subscribe"
end

#success?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/streamforce/message.rb', line 30

def success?
  @payload["successful"]
end