我想爲我的網站使用他們的API獲取一些chartbeat.com統計信息。使用Python chartbeat egg很好,但對於Ruby來說,我很難過第一階段。最終,我的目標是拉動chartbeat quickstats數組(當前用戶,每秒速率等)並將其發送給石墨,並將整個過程守護進程。我對編程方法,理論和實踐有一個體面的理解,我只是用Ruby語法很綠,並且嘗試閱讀符號,方法(私有/公共),並且似乎無法讓Ruby和我的大腦玩好。我認爲這很可能是我的問題所在。嘗試使用gem調用方法時獲取符號轉換錯誤?
從我的理解,我不必做puts
或類似的東西。在c
上調用quickstats
方法應打印通過GEM從chartbeat API返回的任何內容。
圖表珠寶從https://github.com/ashaw/chartbeat。我的紅寶石是Ruby 1.9.3p362 (2012-12-25 revision 38607) [x86_64-darwin12]
。
我得到這個,當我運行我的腳本:
/opt/local/lib/ruby1.9/gems/1.9.1/gems/chartbeat-0.2.2/lib/chartbeat.rb:31:in `[]': can't convert Symbol into Integer (TypeError)
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/chartbeat-0.2.2/lib/chartbeat.rb:31:in `block in method_missing'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/chartbeat-0.2.2/lib/chartbeat.rb:30:in `each'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/chartbeat-0.2.2/lib/chartbeat.rb:30:in `method_missing'
from /Users/jed/Documents/workspace/chartbeat2graphite/c2b.rb:8:in `<main>'
的代碼是:
require 'chartbeat'
require 'graphite'
require 'daemonize'
c = Chartbeat.new(:apikey => "sadfklj09238402938" , :host => "lipsum.com")
c.quickstats :path => '/'
伊斯梅爾,謝謝你的幫助。如你所說,這是問題所在。 – jed