XMPP4RXMPP/Jabber的Ruby類庫
XMPP4R是一個(gè)XMPP/Jabber的Ruby類庫。它的目標(biāo)是提供開發(fā)Jabber相關(guān)應(yīng)用程序或者Ruby腳本的完整框架。
安裝方法:gem install xmpp4r
示例代碼:
# Send a message to a friend, asking for authorization if necessary:
im = Jabber::Simple.new("[email protected]", "password")
im.deliver("[email protected]", "Hey there friend!")
# Get received messages and print them out to the console:
im.received_messages { |msg| puts msg.body if msg.type == :chat }
# Send an authorization request to a user:
im.add("[email protected]")
# Get presence updates from your friends, and print them out to the console:
# (admittedly, this one needs some work)
im.presence_updates { |update|
from = update[0].jid.strip.to_s
status = update[2].status
presence = update[2].show
puts "#{from} went #{presence}: #{status}"
end
# Remove a user from your contact list:
im.remove("[email protected]")
# See the Jabber::Simple documentation for more information.
評(píng)論
圖片
表情
