class Restforce::Concerns::Streaming::ReplayExtension
Public Class Methods
new(replay_handlers)
click to toggle source
# File lib/restforce/concerns/streaming.rb, line 61 def initialize(replay_handlers) @replay_handlers = replay_handlers end
Public Instance Methods
incoming(message, callback)
click to toggle source
# File lib/restforce/concerns/streaming.rb, line 65 def incoming(message, callback) callback.call(message).tap do channel = message.fetch('channel') replay_id = message.fetch('data', {}).fetch('event', {})['replayId'] handler = @replay_handlers[channel] if !replay_id.nil? && !handler.nil? && handler.respond_to?(:[]=) # remember the last replay_id for this channel handler[channel] = replay_id end end end
outgoing(message, callback)
click to toggle source
# File lib/restforce/concerns/streaming.rb, line 78 def outgoing(message, callback) # Leave non-subscribe messages alone return callback.call(message) unless message['channel'] == '/meta/subscribe' channel = message['subscription'] # Set the replay value for the channel message['ext'] ||= {} message['ext']['replay'] = { channel => replay_id(channel) } # Carry on and send the message to the server callback.call message end
Private Instance Methods
replay_id(channel)
click to toggle source
# File lib/restforce/concerns/streaming.rb, line 96 def replay_id(channel) handler = @replay_handlers[channel] if handler.respond_to?(:[]) && !handler.is_a?(Integer) # Ask for the latest replayId for this channel handler[channel] else # Just pass it along handler end end