self.session = requests.Session()
def get_token(self):
+ """This function gets a token needed for authentication in most cases
+
+ :returns: string -- token used to authenticate
+
+ """
+
r = self.session.get(self.pod + "/stream")
token = self._token_regex.search(r.text).group(1)
return token
-
def login(self, username, password):
"""This function is used to connect to the pod and log in.
import requests
+
+
class Post:
+ """This class represents a post.
+
+ .. note::
+ Remember that you need to have access to the post.
+
+ :params post_id: id or guid of the post
+ :type post_id: str
+ :params client: client object used to authenticate
+ :type client: Client
+
+ .. note::
+ The login function of the client should be called,
+ before calling any of the post functions.
+
+ """
def __init__(self, post_id, client):
+
self._client = client
- r = self._client.session.get(self._client.pod + '/posts/' + post_id + '.json')
+ r = self._client.session.get(self._client.pod +
+ '/posts/' +
+ post_id +
+ '.json')
if r.status_code == 200:
self.data = r.json()
else:
data = {'authenticity_token': self._client.get_token()}
- r = self._client.session.delete(self._client.pod + '/posts/' +
+ r = self._client.session.delete(self._client.pod + '/posts/' +
str(self.data['id']) +
'/likes/' +
- str(self.data['interactions']['likes'][0]['id']),
+ str(self.data['interactions']
+ ['likes'][0]['id']),
data=data)
def reshare(self):
data = {'text': text,
'authenticity_token': self._client.get_token()}
- r = self._client.session.post(self._client.pod + '/posts/' + str(self.data['id']) + '/comments', data=data)
+ r = self._client.session.post(self._client.pod +
+ '/posts/' +
+ str(self.data['id']) +
+ '/comments',
+ data=data)
return r.json()
-
+
def rmcomment(self, comment_id):
"""This function removes a comment from a post
data = {'authenticity_token': self._client.get_token()}
- r = self._client.session.delete(self._client.pod + '/posts/' +
- str(self.data['id']) +
- '/comments/' +
- comment_id,
- data=data)
+ r = self._client.session.delete(self._client.pod + '/posts/' +
+ str(self.data['id']) +
+ '/comments/' +
+ comment_id,
+ data=data)
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))
-sys.path.insert(0, os.path.abspath(os.path.join(os.pardir, os.pardir)))
+sys.path.insert(0, os.path.abspath(os.path.join(os.pardir, os.pardir, 'diaspy')))
# -- General configuration -----------------------------------------------------