From: Marek Marecki Date: Sun, 26 May 2013 16:01:54 +0000 (+0200) Subject: Fixed bug aspect deletion, initial development for contacts X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=dd0a4d9f0ed15b2f436f99710b28e9c991821c89;p=diaspy.git Fixed bug aspect deletion, initial development for contacts --- diff --git a/diaspy/models.py b/diaspy/models.py index bedd1ee..b5a7d50 100644 --- a/diaspy/models.py +++ b/diaspy/models.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 -class Post: +class Post(): """This class represents a post. .. note:: diff --git a/diaspy/people.py b/diaspy/people.py index 1c33ee6..8e0199d 100644 --- a/diaspy/people.py +++ b/diaspy/people.py @@ -16,8 +16,8 @@ class User: When creating new User() one can pass either guid or handle as an optional parameter. GUID takes precedence over handle. """ - self.data = {} - self.stream = [] + data = {} + stream = [] def __init__(self, connection, guid='', handle=''): self._connection = connection @@ -80,3 +80,22 @@ class User: """ request = self._connection.get('people/{0}.json'.format(guid)) self._postproc(request) + + +class Contacts(): + """This class represents user's list of contacts. + """ + def __init__(self, connection): + self._connection = connection + + def get_only_sharing(self): + """Returns contacts who are only sharing with you. + + :returns: list + """ + params = {'set':'only_sharing'} + request = self._connection.get('contacts.json', params=params) + if request.status_code != 200: + raise Exception('status code {0}: cannot get contacts'.format(request.status_code)) + contacts = [User(user['guid']) for user in request.json()] + return contacts diff --git a/diaspy/streams.py b/diaspy/streams.py index 50d7b6f..770afc6 100644 --- a/diaspy/streams.py +++ b/diaspy/streams.py @@ -283,11 +283,11 @@ class Aspects(Generic): :type name: str """ if aspect_id == -1 and name: aspect_id = self.getAspectID(name) - data = {'authenticity_token': self._connection.get_token()} - request = self._connection.delete('aspects/{}'.format(aspect_id), - data=data) - if request.status_code not in [404, 500]: - raise Exception('wrong status code: {0}'.format(request.status_code)) + data = {'_method':'delete', + 'authenticity_token': self._connection.get_token()} + request = self._connection.post('aspects/{0}'.format(aspect_id), data=data) + if request.status_code not in [200, 302, 500]: + raise Exception('wrong status code: {0}: cannot remove aspect'.format(request.status_code)) class Commented(Generic): diff --git a/tests.py b/tests.py index 6e1184b..d3b16e4 100644 --- a/tests.py +++ b/tests.py @@ -174,6 +174,14 @@ class UserTests(unittest.TestCase): self.assertEqual(type(user.stream), diaspy.streams.Outer) +class ContactsTest(unittest.TestCase): + def testGetOnlySharing(self): + contacts = diaspy.people.Contacts(test_connection) + only_sharing = contacts.get_only_sharing() + for i in only_sharing: + self.assertEqual(diaspy.people.User, type(i)) + + class PostTests(unittest.TestCase): def testStringConversion(self): s = diaspy.streams.Stream(test_connection)