You can fetch tag suggestions using diaspy
authorMarek Marecki <marekjm@taistelu.com>
Fri, 6 Sep 2013 16:06:35 +0000 (18:06 +0200)
committerMarek Marecki <marekjm@taistelu.com>
Fri, 6 Sep 2013 16:06:35 +0000 (18:06 +0200)
Changelog.markdown
Makefile
diaspy/__init__.py
diaspy/connection.py
diaspy/models.py
diaspy/search.py

index 67d766beb601c7a50aca0300e7975dab38c03f19..53ddbd4b8b72abb196dd17c5fb0b654a86dbda96 100644 (file)
@@ -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`,
index 40cdd456f10a025d04110c77e5ac2e139427280a..1d37e63fd3c0bf6211b217c3ad19362c9e1fb57a 100644 (file)
--- 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
index dbc2b60e71a1e6cf3bf1e89f3e70bb1de0883369..b588f0456f312fbf24a234be0461f24569c78031 100644 (file)
@@ -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'
index e0d435230991168f848375d6d4dcb6840597dc3a..84d7d99dd96465830400989dca7f9a2562bb7027 100644 (file)
@@ -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.
index bcf7daeb6b461bb5ad2469a69d438798ee28e86e..75db85d5faf6d441973766c33cbe79a28dba8887 100644 (file)
@@ -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)
index 2022acae66945982edf0d22997b9adea2c086267..11f77c735052de799a389d72cd2bc6266148ff93 100644 (file)
@@ -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()]