I'm playing with SleekXMPP. All is fine but I can't find the
documentation for the XEP-0060 (PubSub) plugin.
Are there some example snippets or something else ?
Thanks !
Sandro Munda
<munda....@gmail.com>
As client or as server?
Stefan
Sandro Munda
<munda....@gmail.com>
xmpp = sleekxmpp.ClientXMPP('your@full/jid', 'yourpass')
xmpp.registerPlugin('xep_0030') # Service Discovery
xmpp.registerPlugin('xep_0060') # PubSub
if xmpp.connect():
xmpp.process(threaded=True)
else:
sys.exit(1)
node = 'some node'
raw = xmpp.plugin["xep_0030"].get_items('disco.componentjid', node,
block=True)
str(raw['disco_items'])
raw = xmpp.plugin["xep_0060"].get_items('pubsub.componentjid', node,
block=True)
print str(raw['pubsub']['items'])
Does that help a bit?
Stefan
Thanks for your answer. I try to play with your snippet. But it's
strange that there's no more documentation. :-(
However, examples are always better, so here is a small pubsub client example. This still need some polish, but it will soon end up in the Sleek examples directory.
Usage:
# List available nodes
python pubsub_client.py -j your_jid -p yourpass pubsub.example.com nodes
# Create a new node, called 'node_name'
python pubsub_client.py -j your_jid -p yourpass pubsub.example.com create node_name
# Delete a node named 'node_name'
python pubsub_client.py -j your_jid -p yourpass pubsub.example.com delete node_name
# Purge all items from the node 'node_name'
python pubsub_client.py -j your_jid -p yourpass pubsub.example.com purge node_name
# Publish an item to a node 'node_name'
# NOTE: this will wrap 'someitemcontent' in a <test xmlns="test" /> wrapper.
python pubsub_client.py -j your_jid -p yourpass pubsub.example.com publish node_name someitemcontent
# Retrieve all items from the node 'node_name'
python pubsub_client.py -j your_jid -p yourpass pubsub.example.com get node_name
# Retrieve a single item from the node 'node_name' with id 'item_id'
python pubsub_client.py -j your_jid -p yourpass pubsub.example.com get node_name item_id
# Retract an item with id 'item_id' from node 'node_name'
python pubsub_client.py -j your_jid -p yourpass pubsub.example.com retract node_name item_id
# Subscribe to a node 'node_name'
python pubsub_client.py -j your_jid -p yourpass pubsub.example.com subscribe node_name
# Unsubscribe from the node 'node_name'
python pubsub_client.py -j your_jid -p yourpass pubsub.example.com unsubscribe node_name
You can run pubsub_events.py -j yourjid -p yourpass in a second terminal and watch the pubsub events come in as you play with the client.
-- Lance