Friday, July 27, 2012

Sending ICQ messages via Jabber-to-ICQ transport (JRuby + Smack API)


Lets assume that you already have JRuby on your machine. To gain access to Java libraries distributed via Maven you need to install a special gem :


jruby -S gem install ruby-maven


Then you should install Smack API library:


jruby -S gem install mvn:org.igniterealtime.smack:smack


Please notice the special prefix "mvn:". You can also use it in Bundler's Gemfile to reference Java libraries once you have ruby-maven gem installed.


Now lets write a simple program to utilize the just installed library. Make sure you already have a valid Jabber and ICQ account. Also don't forget to register the latter via some Jabber-to-ICQ transport.


require 'java'
require 'rubygems'
require 'mvn:org.igniterealtime.smack:smack'

jabber_server = "jabber.dn.ua"
jabber_account_id = "my_jabber_id"
jabber_account_password = "**********"

icq_transport_server = "icq.jabber.dn.ua"
icq_account_id = "1234567890"

conn = org.jivesoftware.smack.XMPPConnection.new(jabber_server)
conn.connect
conn.login(jabber_account_id, jabber_account_password)

cm = conn.chat_manager

def self.processMessage(chat, message)
  puts message
end

chat = cm.create_chat("#{icq_account_id}@#{icq_transport_server}", self)
chat.send_message("Hello!")


To find more about Smack API check its page.

No comments: