2013-11-09 29 views
0

我正在使用Turntabler,這是一個用於與turntable.fm進行交互的Ruby gem。我創造了這個簡單的「Hello World」程序:使用Turntabler獲取消息「調試 - :連接失敗:連接未打開」

require 'turntabler' 
require_relative 'config.rb' 

config = KevbotConfiguration.load_config # Reads a YAML file 

Turntabler.run(config[:email], config[:password], :room => config[:room], :reconnect => true, :reconnect_wait => 30) do 
    on :user_spoke do |message| 
    # Respond to "/hello" command 
    if (message.content =~ /^\/hello$/) 
     room.say("Hey! How are you @#{message.sender.name}?") 
    end 
    end 
end 

當我運行這個程序時,出現此消息:

$ ruby src/main.rb 
D, [2013-11-09T15:57:17.602019 #10407] DEBUG -- : Connection failed: Connection is not open 
D, [2013-11-09T15:57:47.634282 #10407] DEBUG -- : Attempting to reconnect 
D, [2013-11-09T15:57:47.719336 #10407] DEBUG -- : Connection failed: Connection is not open 
D, [2013-11-09T15:58:17.744107 #10407] DEBUG -- : Attempting to reconnect 
D, [2013-11-09T15:58:17.828378 #10407] DEBUG -- : Connection failed: Connection is not open 
D, [2013-11-09T15:58:47.854309 #10407] DEBUG -- : Attempting to reconnect 
# etc. 

我能做些什麼來解決這個問題?


編輯:這是config.rb內容:

module KevbotConfiguration 
    require 'yaml' 

    def self.load_config 
     return YAML.load_file('config.yaml') 
    end 
end 

回答

0

因爲我是從YAML讀取config哈希值直,我不得不使用字符串來訪問哈希值而不是符號:

Turntabler.run(config['email'], config['password'], :room => config['room'] #...


更一般地說,發生的情況是我的電子郵件,密碼和房間沒有正確傳遞給Turntabler.run。在我的情況下,以錯誤的方式訪問散列元素導致三個參數傳遞nil