Class: Travis::Client::Listener::Socket
- Inherits:
-
PusherClient::Socket
- Object
- PusherClient::Socket
- Travis::Client::Listener::Socket
- Defined in:
- lib/travis/client/listener.rb
Instance Attribute Summary collapse
-
#session ⇒ Object
Returns the value of attribute session.
-
#signatures ⇒ Object
Returns the value of attribute signatures.
Instance Method Summary collapse
- #fetch_auth(*channels) ⇒ Object
- #get_private_auth(channel) ⇒ Object
- #handle_error(data) ⇒ Object
-
#initialize(application_key, options = {}) ⇒ Socket
constructor
A new instance of Socket.
- #reconnect(delay = nil) ⇒ Object
- #subscribe_all ⇒ Object
Constructor Details
#initialize(application_key, options = {}) ⇒ Socket
Returns a new instance of Socket.
16 17 18 19 20 21 22 23 24 |
# File 'lib/travis/client/listener.rb', line 16 def initialize(application_key, = {}) @session = .fetch(:session) @signatures = {} super bind('pusher:error') do |data| handle_error(data) end end |
Instance Attribute Details
#session ⇒ Object
Returns the value of attribute session.
15 16 17 |
# File 'lib/travis/client/listener.rb', line 15 def session @session end |
#signatures ⇒ Object
Returns the value of attribute signatures.
15 16 17 |
# File 'lib/travis/client/listener.rb', line 15 def signatures @signatures end |
Instance Method Details
#fetch_auth(*channels) ⇒ Object
32 33 34 35 |
# File 'lib/travis/client/listener.rb', line 32 def fetch_auth(*channels) channels.select! { |c| signatures[c].nil? if c.start_with? 'private-' } signatures.merge! session.post_raw('/pusher/auth', :channels => channels, :socket_id => socket_id)['channels'] if channels.any? end |
#get_private_auth(channel) ⇒ Object
37 38 39 40 |
# File 'lib/travis/client/listener.rb', line 37 def get_private_auth(channel) fetch_auth(channel.name) signatures[channel.name] end |
#handle_error(data) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/travis/client/listener.rb', line 42 def handle_error(data) code, = data["code"], data["message"] if data.is_a? Hash ||= data.inspect case code when 4100 then reconnect(1) when 4200, 4201, 4202 then reconnect else raise Travis::Client::Error, "Pusher error: %s (code: %p)" % [, code] end end |
#reconnect(delay = nil) ⇒ Object
53 54 55 56 57 |
# File 'lib/travis/client/listener.rb', line 53 def reconnect(delay = nil) disconnect if connected sleep delay if delay and delay > 0 connect end |
#subscribe_all ⇒ Object
26 27 28 29 30 |
# File 'lib/travis/client/listener.rb', line 26 def subscribe_all # bulk auth on connect fetch_auth(*channels.channels.keys) super end |