#!/usr/bin/env python3
-class Post:
+class Post():
"""This class represents a post.
.. note::
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
"""
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
: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):
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)