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`,
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
import diaspy.settings as settings
-__version__ = '0.4.1-rc.1'
+__version__ = '0.4.1-rc.2'
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.
: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)
"""
+from diaspy import errors
+
+
class Search():
"""This object is used for searching for content on Diaspora*.
"""
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()]