From 4685fc310d0fa8fa4129f7e0cbfc2a4dda44e5c9 Mon Sep 17 00:00:00 2001 From: Moritz Kiefer Date: Fri, 15 Feb 2013 13:54:41 +0100 Subject: [PATCH] Add get_tag; pep8 fixes --- diaspy/client.py | 38 ++++++++++++++++++++++++++++++-------- diaspy/models.py | 1 - 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/diaspy/client.py b/diaspy/client.py index 79f6e3c..3d3ea26 100644 --- a/diaspy/client.py +++ b/diaspy/client.py @@ -3,6 +3,7 @@ import re import json import diaspy.models + class Client: """This is the client class to connect to diaspora. @@ -109,12 +110,11 @@ class Client: 'x-csrf-token': self.get_token(), 'x-file-name': filename} - r = self.session.post(self.pod + '/photos', params=params, data=data, headers=headers) + r = self.session.post(self.pod + '/photos', + params=params, data=data, headers=headers) return r - - def get_stream(self): """This functions returns a list of posts found in the stream. @@ -144,7 +144,6 @@ class Client: """ - data = {'authenticity_token': self.get_token()} r = self.session.get(self.pod + "/notifications.json") @@ -154,15 +153,14 @@ class Client: notifications = r.json() return notifications - def get_mentions(self): - """This functions returns a list of posts the current user is being mentioned in. + """This functions returns a list of + posts the current user is being mentioned in. :returns: list -- list of Post objects """ - data = {'authenticity_token': self.get_token()} r = self.session.get(self.pod + "/mentions.json") @@ -178,6 +176,30 @@ class Client: return posts + def get_tag(self, tag): + """This functions returns a list of posts containing the tag. + :param tag: Name of the tag + :type tag: str + + :returns: list -- list of Post objects + + """ + + data = {'authenticity_token': self.get_token()} + r = self.session.get(self.pod + '/tags/' + tag + '.json') + + if r.status_code != 200: + raise Exception('wrong status code: ' + str(r.status_code)) + + tagged_posts = r.json() + + posts = [] + + for post in tagged_posts: + posts.append(diaspy.models.Post(str(post['id']), self)) + + return posts + def add_user_to_aspect(self, user_id, aspect_id): """ this function adds a user to an aspect. @@ -242,7 +264,7 @@ class Client: data = {'authenticity_token': self.get_token()} r = self.session.delete(self.pod + '/aspects/' + aspect_id, - data=data ) + data=data) if r.status_code != 404: raise Exception('wrong status code: ' + str(r.status_code)) diff --git a/diaspy/models.py b/diaspy/models.py index 44f2762..b83de71 100644 --- a/diaspy/models.py +++ b/diaspy/models.py @@ -24,7 +24,6 @@ class Post: self._client = client self.post_id = post_id - def get_data(self): r = self._client.session.get(self._client.pod + '/posts/' + -- 2.25.1