Tag: xmpp4r-simple

Apresentando XMPP4R-Observable

Posted by – 08/09/2009

Há apenas alguns dias fiz uma apresentação no FISL10 sobre a utilização de XMPP PubSub com Ruby e sobre um fork de uma biblioteca popular à qual acrescentei os rudimentos do PubSub. Naquela mesma apresentação listei uma série de problemas que aquela abordagem tem e falei sobre um roadmap para o futuro…

Acontece que acabei me convencendo de que não posso utilizar o PubSub no lado XMPP da biblioteca e uma forma de periodical pooling no lado Ruby. Resolvi, então, substituir a biblioteca que havia forkado por uma versão Observable, preservando as coisas boas do XMPP4R-Simple. O resultado chamei de XMPP4R-Observable, e acabo de publicar no GitHub.

Uma boa parte do código está coberta por testes (e “roubei” alguns dos testes da própria XMPP4R-Simple)… pretendo cobrir o restante ao longo do tempo (contribuições são bem-vindas). Por hora, chamei esse primeiro release de versão 0.5.1 e acrescentei um .gemspec para gerar um .gem automaticamente… No entanto, o GitHub ainda não publicou o .gem… Quando publicar, para instalá-lo deve ser tão simples quanto:

bash# gem sources -a http://gems.github.com
bash# gem install spectra-xmpp4r-observable

Não deixem de reportar qualquer erro. Happy hacking.

Update 2009-09-13 10:29:00: Acabo de confirmar que o .gem foi publicado pelo GitHub.

Update 2009-10-10 20:21:00: O .gem do XMPP4R-Observable vai ser mantido no GemCutter, a partir de hoje.

PubSub with XMPP4R-Simple

Posted by – 18/03/2009

As I already told you, I am using XMPP4R-Simple in an internal project. For this, I’d have to add PubSub capabilities to it, and I did when I decided to get serious with git. Today I committed a version with integration of various patches by other forks I found on GitHub plus a lot of improvements on PubSub functions.

With this version it’s simple to use PubSub like this:

require 'xmpp4r-simple'
 
# Simple function just to parse an event
require 'time'
def parse_event(event)
  item = event.children[0]
  node = item.node
  time = nil; item.each_element("//published") { |e| time = Time.parse(e.text) }
  text = nil; item.each_element("//body") { |e| text = e.text }
  return { :item => item, :node => node, :time => time, :text => text }
end
 
# Create the clients
im1 = Jabber::Simple.new "im1@example.com", "password"
im2 = Jabber::Simple.new "im2@example.com", "password"
 
# im1 creates a node
im1.create_node("/some/node")
 
# im2 subscribe to that node
im2.pubsubscribe_to("/some/node")
 
# We'll start a simple thread to get the events coming from that node to im2
Thread.new { loop {
  sleep 1 while ! im2.received_events?
  im2.received_events { |event|
    h = parse_event(event)
    puts ">>> Got an event from node #{h[:node]} published at #{h[:time]} with text #{h[:text]}"
  }
}}
 
# Now im1 just publishes anything to that node.
im1.publish_atom_item("/some/node", "This is my node", "This is the content of my node")
 
# The thread should capture the event and run puts on the hash from parsing.

PubSub is great, isn’t it?

Alright! I surrender: Git rules!

Posted by – 05/02/2009

Everybody seems to be using git these days… I am not very found of “hypes”, as I told you before, but there’s been some time I’ve been evaluating git. I was happy with svk for quite a long time… Lately, though, I’ve been developing and extending a lot of ruby libraries, and all of them seem to be hosted at GitHub and using git… So, why not give it a serious try?

I chose a simple task on my TODO-list: to extend xmpp4r-simple to support XMPP PubSub, so I could use it in an internal project at my company. So I “cloned” its git repo and started developing. Not a really hard task, since all I had to do was use the underlying library (xmpp4r – not surprisingly also in GitHub) and mimic what Blaine’s done for the callbacks and it was ready (and working… although I still need to put more time on the test suite).

I am still exploring… It will take some time to migrate my stuff (and maybe a lot will remain in my company’s Subversion), but that’s what git-svn is for, isn’t it? Right now I am looking for ways to work with git-buildpackage and Debian git tools… Do you have some advice on that?