Skip to content

Instantly share code, notes, and snippets.

@hamin
Created March 21, 2011 21:50
Show Gist options
  • Save hamin/880291 to your computer and use it in GitHub Desktop.
Save hamin/880291 to your computer and use it in GitHub Desktop.
A convenience lib for dealing with PubSub with XMPP4R
require "xmpp4r"
require "xmpp4r/pubsub"
module PubSubAble
include Jabber
def anon_connect_to_server(anonymous_user,host,port)
jid = Jabber::JID.new("#{anonymous_user}@#{host}")
client = Client.new(jid)
client.connect(host,port)
client.auth_anonymous
client
end
def auth_connect_to_server(authenticated_user,password,host,port)
jid = Jabber::JID.new("#{authenticated_user}@#{host}")
client = Client.new(jid)
client.connect(host,port)
client.auth(password)
client
end
def ping_server(client)
pres = Presence.new
client.send(pres)
end
def create_node(node_name,client,pubsub_jid,opts={})
pubsub_service = PubSub::ServiceHelper.new(client, pubsub_jid)
pubsub_service.create_node(node_name)
end
def subscribe_to_node(node_name,client,pubsub_jid)
pubsub_service = PubSub::ServiceHelper.new(client, pubsub_jid)
pubsub_service.subscribe_to(node_name)
end
def send_message_to_node(node_name,client,pubsub_jid,message_content)
item = Jabber::PubSub::Item.new
message = Jabber::Message.new(nil,message_content)
item.add(message)
pubsub_service = PubSub::ServiceHelper.new(client, pubsub_jid)
pubsub_service.publish_item_to(node_name,item)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment