lib/slack-rtmapi/client.rb in slack-rtmapi-1.0.0.rc2 vs lib/slack-rtmapi/client.rb in slack-rtmapi-1.0.0.rc3
- old
+ new
@@ -23,11 +23,11 @@
end
VALID = [:open, :message, :error]
def on(type, &block)
unless VALID.include? type
- raise ArgumentError.new "Client#on(type) takes on type of #{VALID.inspect}"
+ raise ArgumentError.new "Client#on accept one of #{VALID.inspect}"
end
@callbacks ||= {}
@callbacks[type] = block
end
@@ -40,33 +40,22 @@
# This init has been delayed because the SSL handshake is a blocking and
# expensive call
def init
return if @has_been_init
- puts "begin init. Init SSL"
-
@socket = init_socket(@socket)
@socket.connect # costly and blocking !
- puts "end connect. Init wrapper"
-
internalWrapper = (Struct.new :url, :socket do
def write(*args)
- puts 'write called'
self.socket.write(*args)
end
end).new @url.to_s, @socket
- puts 'end wrapper. Init driver'
-
# this, also, is costly and blocking
@driver = WebSocket::Driver.client internalWrapper
-
- puts "end driver. Init callbacks"
-
@driver.on :open do
- puts "connected !"
@connected = true
unless @callbacks[:open].nil?
@callbacks[:open].call
end
end
@@ -74,35 +63,27 @@
@driver.on :error do |event|
@connected = false
unless @callbacks[:error].nil?
@callbacks[:error].call
end
- raise event
end
@driver.on :message do |event|
data = JSON.parse event.data
unless @callbacks[:message].nil?
@callbacks[:message].call data
end
end
-
- puts "end callbacks. Starting driver"
-
@driver.start
-
- puts 'end init'
-
@has_been_init = true
end
def connected?
@connected || false
end
# All the polling work is done here
def inner_loop
- putc '.'
return if @stop
data = @socket.readpartial 4096
return if data.nil? or data.empty?
@driver.parse data