import json
import diaspy.models
+
class Client:
"""This is the client class to connect to diaspora.
'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.
"""
-
data = {'authenticity_token': self.get_token()}
r = self.session.get(self.pod + "/notifications.json")
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")
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.
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))