From: Marek Marecki Date: Thu, 2 May 2013 08:04:06 +0000 (+0200) Subject: Changes regarding use of streams in diaspy/client.py X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=91ce08c020a85bead9113a8362f8478b9e96452f;p=diaspy.git Changes regarding use of streams in diaspy/client.py --- diff --git a/diaspy/client.py b/diaspy/client.py index 8eaab44..09e376d 100644 --- a/diaspy/client.py +++ b/diaspy/client.py @@ -43,6 +43,7 @@ class Client: def get_activity(self): """This function returns activity stream. + :returns: diaspy.streams.Activity """ activity = diaspy.streams.Activity(self.connection, 'activity.json') @@ -56,47 +57,58 @@ class Client: self.stream.update() return self.stream - def get_notifications(self): - """This functions returns a list of notifications. + def get_aspects(self): + """Returns /aspects stream. - :returns: list -- list of json formatted notifications + :returns: diaspy.streams.Aspects """ - r = self.connection.get('notifications.json') - - if r.status_code != 200: - raise Exception('wrong status code: {0}'.format(r.status_code)) - - notifications = r.json() - return notifications + return diaspy.streams.Aspects(self.connection) def get_mentions(self): - """This functions returns a list of - posts the current user is being mentioned in. + """Returns /mentions stream. - :returns: list -- list of Post objects + :returns: diaspy.streams.Mentions """ - r = self.connection.get('mentions.json') + return diaspy.streams.Mentions(self.connection) - if r.status_code != 200: - raise Exception('wrong status code: {0}'.format(r.status_code)) + def get_followed_tags(self): + """Returns followed tags stream. - mentions = r.json() - return [diaspy.models.Post(str(post['id']), self.connection) for post in mentions] + :returns: diaspy.streams.FollowedTags + """ + return diaspy.streams.FollowedTags(self.connection) - def get_tag(self, tag): + def get_tag(self, tag, stream=False): """This functions returns a list of posts containing the tag. :param tag: Name of the tag :type tag: str + :param stream: specify wheter you want a stream object (True) or + normal list (False) + :type stream: bool :returns: list -- list of Post objects """ - r = self.connection.get('tags/{0}.json'.format(tag)) + if stream: + r = self.connection.get('tags/{0}.json'.format(tag)) + if r.status_code != 200: + raise Exception('wrong status code: {0}'.format(r.status_code)) + tagged_posts = [diaspy.models.Post(str(post['id']), self.connection) for post in r.json()] + else: + tagged_posts = diaspy.streams.Generic(self.connection, location='tags/{0}.json'.format(tag)) + return tagged_posts + + def get_notifications(self): + """This functions returns a list of notifications. + + :returns: list -- list of json formatted notifications + """ + r = self.connection.get('notifications.json') if r.status_code != 200: raise Exception('wrong status code: {0}'.format(r.status_code)) - tagged_posts = r.json() - return [diaspy.models.Post(str(post['id']), self.connection) for post in tagged_posts] + notifications = r.json() + return notifications def get_mailbox(self): """This functions returns a list of messages found in the conversation.