From cf6a800f9ed73d4003967afd1b60b20b3b7936cb Mon Sep 17 00:00:00 2001 From: Marek Marecki Date: Fri, 6 Sep 2013 18:06:35 +0200 Subject: [PATCH] You can fetch tag suggestions using diaspy --- Changelog.markdown | 5 +++++ Makefile | 5 +---- diaspy/__init__.py | 2 +- diaspy/connection.py | 2 +- diaspy/models.py | 2 +- diaspy/search.py | 23 +++++++++++++++++++---- 6 files changed, 28 insertions(+), 11 deletions(-) diff --git a/Changelog.markdown b/Changelog.markdown index 67d766b..53ddbd4 100644 --- a/Changelog.markdown +++ b/Changelog.markdown @@ -34,6 +34,11 @@ pods running on older versions. And the test suite was updated. Yay! +**`0.4.1-rc.2` (2013-09-06):** + +* __new__: `diaspy.search.Search.tags()` method for getting tag suggestions, + + **`0.4.1-rc.1` (2013-09-02):** * __new__: `__getitem__()` in `diaspy.models.Post`, diff --git a/Makefile b/Makefile index 40cdd45..1d37e63 100644 --- a/Makefile +++ b/Makefile @@ -10,10 +10,7 @@ test-python2: python2 -m unittest --verbose --catch --failfast tests.py clean: - rm -rv diaspy/__pycache__/ - rm -rv diaspy/*.pyc - rm -rv ./__pycache__/ - rm -rv *.pyc + rm -rv ./{diaspy/,}__pycache__/ install: python setup.py install diff --git a/diaspy/__init__.py b/diaspy/__init__.py index dbc2b60..b588f04 100644 --- a/diaspy/__init__.py +++ b/diaspy/__init__.py @@ -8,4 +8,4 @@ import diaspy.notifications as notifications import diaspy.settings as settings -__version__ = '0.4.1-rc.1' +__version__ = '0.4.1-rc.2' diff --git a/diaspy/connection.py b/diaspy/connection.py index e0d4352..84d7d99 100644 --- a/diaspy/connection.py +++ b/diaspy/connection.py @@ -52,7 +52,7 @@ class Connection(): repr(connection) instead of calling a specified method. """ - return self._token + return self._fetchtoken() def get(self, string, headers={}, params={}, direct=False): """This method gets data from session. diff --git a/diaspy/models.py b/diaspy/models.py index bcf7dae..75db85d 100644 --- a/diaspy/models.py +++ b/diaspy/models.py @@ -135,7 +135,7 @@ class Aspect(): :param user_id: user to remove from aspect :type user: int """ - data = {'authenticity_token': self._connection.get_token(), + data = {'authenticity_token': repr(self._connection), 'aspect_id': self.id, 'person_id': user_id} request = self.connection.delete('aspect_memberships/{0}.json'.format(self.id), data=data) diff --git a/diaspy/search.py b/diaspy/search.py index 2022aca..11f77c7 100644 --- a/diaspy/search.py +++ b/diaspy/search.py @@ -4,6 +4,9 @@ """ +from diaspy import errors + + class Search(): """This object is used for searching for content on Diaspora*. """ @@ -26,8 +29,20 @@ class Search(): data of found users. """ request = self._connection.get('people.json', params={'q': query, 'utf-8': '%u2713'}) - if request.status_code == 200: - result = request.json() - else: + if request.status_code != 200: + raise errors.SearchError('wrong status code: {0}'.format(request.status_code)) + return request.json() + + def tags(self, query, limit=10): + """Retrieve tag suggestions. + + :param query: query used to search + :type query: str + :param limit: maxmal number of suggestions returned + :type limit: int + """ + params = {'q': query, 'limit': limit} + request = self._connection.get('tags', params=params, headers={'x-csrf-token': repr(self._connection)}) + if request.status_code != 200: raise errors.SearchError('wrong status code: {0}'.format(request.status_code)) - return result + return [i['name'] for i in request.json()] -- 2.25.1