changeset 301:e33b3a777f10

plugin xep-0060: added getEntry method
author Goffi <goffi@goffi.org>
date Mon, 21 Feb 2011 01:36:52 +0100
parents 233e6fce0b49
children 9f3a6cf91668
files src/plugins/plugin_xep_0060.py
diffstat 1 files changed, 25 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0060.py	Mon Feb 21 01:35:39 2011 +0100
+++ b/src/plugins/plugin_xep_0060.py	Mon Feb 21 01:36:52 2011 +0100
@@ -47,6 +47,17 @@
         self.host = host
         self.managedNodes=[]
         self.clients={}
+        """host.bridge.addMethod("getItems", ".communication", in_sign='ssa{ss}s', out_sign='as', method=self.getItems,
+                              async = True,
+                              doc = { 'summary':'retrieve items',
+                                      'param_0':'service: pubsub service',
+                                      'param_1':'node: node identifier',
+                                      'param_2':'\n'.join(['options: can be:',
+                                          '- max_items: see XEP-0060 #6.5.7',
+                                          '- sub_id: subscription identifier, see XEP-0060 #7.2.2.2']),
+                                      'param_3':'%(doc_profile)s',
+                                      'return':'array of raw XML (content of the items)'
+                                    })"""
 
     def getHandler(self, profile):
         self.clients[profile] = SatPubSubClient(self.host, self)
@@ -73,7 +84,20 @@
             raise Exception(err_mess)
         client.publish(service, nodeIdentifier, items, client.parent.jid) 
 
-
+    def getItems(self, service, node, max_items=None, sub_id=None, profile_key='@DEFAULT@'):
+        profile = self.host.memory.getProfileName(profile_key)
+        if not profile:
+            err_mess = _('Trying to get items with an unknown profile key [%s]') % profile_key
+            error(err_mess)
+            raise Exception(err_mess)
+        try:
+            client = self.clients[profile]
+        except KeyError:
+            err_mess = _('INTERNAL ERROR: no handler for required profile')
+            error(err_mess)
+            raise Exception(err_mess)
+        return client.items(service, node, max_items, sub_id, client.parent.jid)
+        
 class SatPubSubClient(pubsub.PubSubClient):
     implements(disco.IDisco)