From ae2213966919bfc424b555935910c4ce047141d4 Mon Sep 17 00:00:00 2001 From: Moritz Kiefer Date: Fri, 18 Jan 2013 12:53:57 +0100 Subject: [PATCH] Improvements to the documentation and style fixes --- .gitignore | 3 ++- diaspy/client.py | 7 ++++++- diaspy/models.py | 46 +++++++++++++++++++++++++++++++++---------- docs/source/conf.py | 2 +- docs/source/index.rst | 4 +--- 5 files changed, 46 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index c5edd07..269358f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *~ *.swp docs/build/* -*__pycache__/* +*/__pycache__/* +__pycache__/* .env diff --git a/diaspy/client.py b/diaspy/client.py index c21a6b4..b1ad81f 100644 --- a/diaspy/client.py +++ b/diaspy/client.py @@ -19,11 +19,16 @@ class Client: 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. diff --git a/diaspy/models.py b/diaspy/models.py index ea22b45..8da32a6 100644 --- a/diaspy/models.py +++ b/diaspy/models.py @@ -1,9 +1,30 @@ 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: @@ -33,10 +54,11 @@ class Post: 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): @@ -66,10 +88,14 @@ class Post: 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 @@ -82,8 +108,8 @@ class 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) diff --git a/docs/source/conf.py b/docs/source/conf.py index 7f47030..a523cd2 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -18,7 +18,7 @@ import sys, os # 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 ----------------------------------------------------- diff --git a/docs/source/index.rst b/docs/source/index.rst index 81902f3..3cc90e6 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -11,9 +11,7 @@ Contents: .. toctree:: :maxdepth: 2 -.. automodule:: diaspy - :members: - + modules Indices and tables ================== -- 2.25.1