comparison src/plugins/plugin_xep_0277.py @ 465:78e67a59d51d

plugin groupblog: added getLastGroupBlogs method
author Goffi <goffi@goffi.org>
date Sat, 24 Mar 2012 17:48:12 +0100
parents cf005701624b
children c97640c90a94
comparison
equal deleted inserted replaced
464:794f60e2da27 465:78e67a59d51d
73 method=self.setMicroblogAccess, 73 method=self.setMicroblogAccess,
74 async = True, 74 async = True,
75 doc = { 75 doc = {
76 }) 76 })
77 77
78 def _item2mbdata(self, item): 78 def item2mbdata(self, item):
79 """Convert an XML Item to microblog data used in bridge API 79 """Convert an XML Item to microblog data used in bridge API
80 @param item: domish.Element of microblog item 80 @param item: domish.Element of microblog item
81 @return: microblog data (dictionary)""" 81 @return: microblog data (dictionary)"""
82 try: 82 try:
83 entry_elt = filter (lambda x:x.name == "entry", item.children)[0] 83 entry_elt = filter (lambda x:x.name == "entry", item.children)[0]
108 ##end workaround Jappix 108 ##end workaround Jappix
109 return microblog_data 109 return microblog_data
110 110
111 def microblogCB(self, itemsEvent, profile): 111 def microblogCB(self, itemsEvent, profile):
112 for item in itemsEvent.items: 112 for item in itemsEvent.items:
113 microblog_data = self._item2mbdata(item) 113 microblog_data = self.item2mbdata(item)
114 self.host.bridge.personalEvent(itemsEvent.sender.full(), "MICROBLOG", microblog_data, profile) 114 self.host.bridge.personalEvent(itemsEvent.sender.full(), "MICROBLOG", microblog_data, profile)
115 115
116 def data2entry(self, data, profile): 116 def data2entry(self, data, profile):
117 """Convert a data dict to en entry usable to create an item 117 """Convert a data dict to en entry usable to create an item
118 @param data: data dict as given by bridge method 118 @param data: data dict as given by bridge method
147 return 0 147 return 0
148 148
149 def getLastMicroblogs(self, pub_jid, max_items=10, profile_key='@DEFAULT@', callback=None, errback=None): 149 def getLastMicroblogs(self, pub_jid, max_items=10, profile_key='@DEFAULT@', callback=None, errback=None):
150 """Get the last published microblogs 150 """Get the last published microblogs
151 @param pub_jid: jid of the publisher 151 @param pub_jid: jid of the publisher
152 @param max_items: how many microblogs we wants to get 152 @param max_items: how many microblogs we want to get
153 @param profile_key: profile key 153 @param profile_key: profile key
154 @param callback: used for the async answer 154 @param callback: used for the async answer
155 @param errback: used for the async answer 155 @param errback: used for the async answer
156 """ 156 """
157 assert(callback) 157 assert(callback)
158 d = self.host.plugins["XEP-0060"].getItems(jid.JID(pub_jid), NS_MICROBLOG, max_items=max_items, profile_key=profile_key) 158 d = self.host.plugins["XEP-0060"].getItems(jid.JID(pub_jid), NS_MICROBLOG, max_items=max_items, profile_key=profile_key)
159 d.addCallbacks(lambda items: callback(map(self._item2mbdata, items)), errback) 159 d.addCallbacks(lambda items: callback(map(self.item2mbdata, items)), errback)
160 160
161 def setMicroblogAccess(self, access="presence", profile_key='@DEFAULT@', callback=None, errback=None): 161 def setMicroblogAccess(self, access="presence", profile_key='@DEFAULT@', callback=None, errback=None):
162 """Create a microblog node on PEP with given access 162 """Create a microblog node on PEP with given access
163 If the node already exists, it change options 163 If the node already exists, it change options
164 @param access: Node access model, according to xep-0060 #4.5 164 @param access: Node access model, according to xep-0060 #4.5