XMPP/Jabber的Ruby類庫 XMPP4R
XMPP4R是一個XMPP/Jabber的Ruby類庫。它的目標是提供開發Jabber相關應用程序或者Ruby腳本的完整框架。
- 完整面向對象
- 旨在XMPP協議兼容
- Threaded, events-based
- 良好的單元測試和文檔代碼
- Uses well-known and well-tested software like REXML, instead of reinventing the wheel
- Very easy to extend
安裝方法:gem install xmpp4r
示例代碼:
# Send a message to a friend, asking for authorization if necessary:
im = Jabber::Simple.new("user@example.com", "password")
im.deliver("friend@example.com", "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("friend@example.com")
# 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("unfriendly@example.com")
# See the Jabber::Simple documentation for more information.http://home.gna.org/xmpp4r/
本文由用戶 fmms 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!