Class: PusherListener::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/pusher_listener/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
# File 'lib/pusher_listener/client.rb', line 7

def initialize(options)
  @key = options.fetch(:key)
  @secret = options.fetch(:secret)
  @encrypted = options.fetch(:encrypted)
end

Instance Method Details

#start(will_loop = true) ⇒ Object



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

def start(will_loop=true)
  socket.bind('pusher:connection_established',
              &method(:log_connection_established))

  socket.bind('pusher:error', &method(:handle_error))

  socket.connect(true)

  loop { sleep 1 } if will_loop
end

#when(channel_name, event_name, &block) ⇒ Object



13
14
15
# File 'lib/pusher_listener/client.rb', line 13

def when(channel_name, event_name, &block)
  socket[channel_name].bind(event_name, &block)
end