Module: Restforce::Client::Streaming

Included in:
Restforce::Client
Defined in:
lib/restforce/client/streaming.rb

Instance Method Summary collapse

Instance Method Details

#fayeObject

Public: Faye client to use for subscribing to PushTopics



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/restforce/client/streaming.rb', line 16

def faye
  raise 'Instance URL missing. Call .authenticate! first.' unless @options[:instance_url]
  @faye ||= Faye::Client.new("#{@options[:instance_url]}/cometd/#{@options[:api_version]}").tap do |client|
    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
  end
end

#subscribe(channel, &block) ⇒ Object

Public: Subscribe to a PushTopic

channel - The name of the PushTopic channel to subscribe to. block - A block to run when a new message is received.

Returns a Faye::Subscription



11
12
13
# File 'lib/restforce/client/streaming.rb', line 11

def subscribe(channel, &block)
  faye.subscribe "/topic/#{channel}", &block
end