-
Notifications
You must be signed in to change notification settings - Fork 89
How it works
jnak edited this page Aug 13, 2011
·
3 revisions
Call the setup method and pass in jid (with optional resource), pass, and optionally host and port:
setup '[email protected]/blather', 'blather', '127.0.0.1', 5222
or just
setup '[email protected]', 'blather'
Components are also possible, by omitting the node and [at]:
setup 'jabber.local', 'shared secret'
That's it. You could put this line in and run the code and you'd be connected to the server ready to go.
The first thing you'll probably want to handle is the ready event. It's really the only true event triggered by the library.
when_ready do
# Do startup stuff here
end
Stanzas to Handle will give a rundown of all the other handle-ables.
Guards are a feature borrowed from Erlang. They help keep code clean and concise by creating handlers specific to a stanza. For instance the following code could be refactored from this:
message do |msg|
if msg.chat? && msg.body == 'exit'
shutdown
elsif msg.chat? && msg.body
say m.from, "You said #{msg.body}"
end
end
to this:
message :chat?, :body => 'exit' do |m|
shutdown
end
message :chat?, :body do |m|
say m.from, "You said #{msg.body}"
end