Module: Restforce::Concerns::Streaming
- Included in:
- Data::Client
- Defined in:
- lib/restforce/concerns/streaming.rb
Defined Under Namespace
Classes: ReplayExtension
Instance Method Summary collapse
-
#faye ⇒ Object
Public: Faye client to use for subscribing to PushTopics.
-
#legacy_subscribe(topics, options = {}) ⇒ Object
(also: #subscribe)
Public: Subscribe to a PushTopic.
- #replay_handlers ⇒ Object
-
#subscription(channels, options = {}) ⇒ Object
Public: Subscribe to one or more Streaming API channels.
Instance Method Details
#faye ⇒ Object
Public: Faye client to use for subscribing to PushTopics
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/restforce/concerns/streaming.rb', line 33 def faye unless [:instance_url] raise 'Instance URL missing. Call .authenticate! first.' end url = "#{[:instance_url]}/cometd/#{[:api_version]}" @faye ||= Faye::Client.new(url).tap do |client| client.set_header 'Authorization', "OAuth #{[:oauth_token]}" client.bind 'transport:down' do Restforce.log "[COMETD DOWN]" client.set_header 'Authorization', "OAuth #{authenticate!.access_token}" end client.bind 'transport:up' do Restforce.log "[COMETD UP]" end client.add_extension ReplayExtension.new(replay_handlers) end end |
#legacy_subscribe(topics, options = {}) ⇒ Object Also known as: subscribe
Public: Subscribe to a PushTopic
topics - The name of the PushTopic channel(s) to subscribe to. block - A block to run when a new message is received.
Returns a Faye::Subscription
12 13 14 15 |
# File 'lib/restforce/concerns/streaming.rb', line 12 def legacy_subscribe(topics, = {}, &) topics = Array(topics).map { |channel| "/topic/#{channel}" } subscription(topics, , &) end |
#replay_handlers ⇒ Object
56 57 58 |
# File 'lib/restforce/concerns/streaming.rb', line 56 def replay_handlers @_replay_handlers ||= {} end |
#subscription(channels, options = {}) ⇒ Object
Public: Subscribe to one or more Streaming API channels
channels - The name of the Streaming API (cometD) channel(s) to subscribe to. block - A block to run when a new message is received.
Returns a Faye::Subscription
24 25 26 27 28 29 30 |
# File 'lib/restforce/concerns/streaming.rb', line 24 def subscription(channels, = {}, &) one_or_more_channels = Array(channels) one_or_more_channels.each do |channel| replay_handlers[channel] = [:replay] end faye.subscribe(one_or_more_channels, &) end |