<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: xmpp4r code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 18 May 2008 11:55:40 GMT</pubDate>
    <description>DZone Snippets: xmpp4r code</description>
    <item>
      <title>Using XMPP4R-Simple to check for activity.</title>
      <link>http://snippets.dzone.com/posts/show/5164</link>
      <description>Using XMPP4R--Simple these Ruby code snippets show a user's status change and any messages they may have sent you since the last time.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# user1 changes their status to away&lt;br /&gt;jabber.presence_updates do |friend, old_presence, new_presence|&lt;br /&gt;  puts "Received presence update from #{friend.to_s}: #{new_presence}"&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;# user1 sends the message "do you like Tofu?"&lt;br /&gt;jabber.received_messages do |message|&lt;br /&gt;  puts "Received message from #{message.from}: #{message.body}"&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Reference: http://xmpp4r-simple.rubyforge.org/</description>
      <pubDate>Fri, 22 Feb 2008 22:39:32 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5164</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Sending a message using XMPP and Ruby</title>
      <link>http://snippets.dzone.com/posts/show/5149</link>
      <description>This Ruby code shows how to send an instant message through &lt;a hre="http://en.wikipedia.org/wiki/Extensible_Messaging_and_Presence_Protocol"&gt;XMPP&lt;/a&gt; [wikipedia.org] using &lt;a href="http://home.gna.org/xmpp4r/"&gt;XMPP4R&lt;/a&gt; [gna.org]. Source code origin: &lt;a href="http://devblog.famundo.com/articles/2006/10/14/ruby-and-xmpp-jabber-part-2-logging-in-and-sending-simple-messages"&gt;Ruby and XMPP/Jabber Part 2: Logging in and sending simple messages&lt;/a&gt; [famundo.com].&lt;br /&gt;&lt;br /&gt;Preparation&lt;br /&gt; - Installed eJabberd on my Gentoo server&lt;br /&gt; - Created 2 user accounts using Pidgin Internet Messenger on my Ubuntu desktop.&lt;br /&gt; - Tested sending messages using Jabber Instant Messaging (Gabber) and Pidgin Internet Messenger.&lt;br /&gt;&lt;br /&gt;Installation&lt;br /&gt;&lt;code&gt;gem install xmpp4r&lt;/code&gt;&lt;br /&gt;What we will need&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'rubygems'&lt;br /&gt;require 'xmpp4r'&lt;br /&gt;include Jabber&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Logging in&lt;br /&gt;&lt;code&gt;&lt;br /&gt;jid = JID::new('yourname@yourdomain.com/Testing')&lt;br /&gt;password = 'yourpassword'&lt;br /&gt;cl = Client::new(jid)&lt;br /&gt;cl.connect&lt;br /&gt;cl.auth(password)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Sending a simple message&lt;br /&gt;&lt;code&gt;&lt;br /&gt;to = "user2@yourdomain.com"&lt;br /&gt;subject = "XMPP4R test"&lt;br /&gt;body = "Hi, this is my first try from XMPP4R!!!"&lt;br /&gt;m = Message::new(to, body).set_type(:normal).set_id('1').set_subject(subject)&lt;br /&gt;cl.send m&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;References: &lt;br /&gt; - &lt;a href="http://www.rubyinside.com/building-a-twitter-agent-with-ruby-and-rails-760.html"&gt;Building a Twitter Agent with Ruby and Rails&lt;/a&gt; [rubyinside.com]&lt;br /&gt; - http://gentoo-wiki.com/Ejabberd&lt;br /&gt;&lt;br /&gt;* update 15:45 18-Feb-08 *&lt;br /&gt;Here's a simpler example I found from &lt;a href="http://romeda.org/blog/2006/11/announcing-jabbersimple.html"&gt;Liminal Existence: Announcing Jabber::Simple&lt;/a&gt; [romeda.org]&lt;br /&gt;&lt;br /&gt;sudo gem install xmpp4r-simple&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'xmpp4r-simple'&lt;br /&gt;&lt;br /&gt;jabber = Jabber::Simple.new('yourname@yourdomain.com', 'yourpassword')&lt;br /&gt;jabber.deliver("user1@yourdomain.com", "Hey! I'm thinking of going Vegetarian - Any suggestions?")&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;see also: &lt;a href="http://www.rubyfleebie.com/im-integration-with-xmpp4r-part-2/"&gt;IM Integration With XMPP4r : Part 2&lt;/a&gt; [rubyfleebie.com]</description>
      <pubDate>Mon, 18 Feb 2008 10:39:34 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5149</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
  </channel>
</rss>
