'aspect_id': self.id,
'person_id': user_id}
- request = self.connection.delete('aspect_memberships/42.json', data=data)
+ request = self.connection.delete('aspect_memberships/{0}.json'.format(self.id), data=data)
if request.status_code != 200:
raise Exception('wrong status code: {0}'.format(request.status_code))
return request.json()
+
+
+class Notifications():
+ """This class represents notifications of a user.
+ """
+ def __init__(self, connection):
+ self._connection = connection
+
+ def get(self):
+ """Returns list of notifications.
+ """
+ request = self._connection.get('notifications.json')
+
+ if r.status_code != 200:
+ raise Exception('status code: {0}: cannot retreive notifications'.format(r.status_code))
+
+ notifications = request.json()
+ return notifications
import re
from diaspy.streams import Outer
+from diaspy.models import Aspect
class User:
def __init__(self, connection):
self._connection = connection
- def get_only_sharing(self):
- """Returns contacts who are only sharing with you.
+ def add(self, user_id, aspect_ids):
+ """Add user to aspects of given ids.
- :returns: list
+ :param user_id: user guid
+ :type user_id: str
+ :param aspect_ids: list of aspect ids
+ :type aspect_ids: 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
+ for aid in aspect_ids:
+ Aspect(self._connection, aid).addUser(user_id)
- def get_all(self):
- """Returns list of all contacts.
+ def remove(self, user_id, aspect_ids):
+ """Remove user from aspects of given ids.
- :returns: list
+ :param user_id: user guid
+ :type user_id: str
+ :param aspect_ids: list of aspect ids
+ :type aspect_ids: list
"""
- params = {'set': 'all'}
- 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
+ for aid in aspect_ids:
+ Aspect(self._connection, aid).removeUser(user_id)
- def get(self):
+ def get(self, set=''):
"""Returns list of user contacts.
+ Contact is a User() who is in one or more of user's
+ aspects.
+
+ By default, it will return list of users who are in logged
+ user aspects.
+ If `set` is `all` it will also include users who only share
+ with logged user and are not in his/hers aspects.
+ If `set` is `only_sharing` it will return users who are only
+ sharing with logged user and ARE NOT in his/hers aspects.
+
+ :param set: if passed could be 'all' or 'only_sharing'
+ :type set: str
"""
- request = self._connection.get('contacts.json')
+ params = {}
+ if set: params['set'] = set
+
+ 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()]
import json
import time
-from diaspy.models import Post
+from diaspy.models import Post, Aspect
"""Docstrings for this module are taken from:
https://gist.github.com/MrZYX/01c93096c30dc44caf71
Status code 422 is accepted because it is returned by D* when
you try to add aspect already present on your aspect list.
- :returns: id of created aspect
+ :returns: Aspect() object of just created aspect
"""
data = {'authenticity_token': self._connection.get_token(),
'aspect[name]': aspect_name,
raise Exception('wrong status code: {0}'.format(request.status_code))
id = self.getAspectID(aspect_name)
- return id
+ return Aspect(self._connection, id)
def remove(self, aspect_id=-1, name=''):
"""This method removes an aspect.
* `stream`, `diaspy.streams.Outer`, stream of the user (provides all methods of generic stream);
+====
+
+
+#### `Contacts()` object
+
+This is object abstracting list of user's contacts.
+It may be slightly confusing to use and reading just docs could be not enough.
+
+The only method of this object is `get()` and its only parameter is `set` which
+is optional (defaults to empty string).
+If called without specifying `set` `get()` will return list of users (`User()` objects)
+who are in your aspects.
+
+Optional `set` parameter can be either `all` or `only_sharing`.
+If passed as `only_sharing` it will return only users who are not in your aspects but who share
+with you - which means that you are in their aspects.
+If passed as `all` it will return list of *all* your contacts - those who are in your aspects and
+those who are not.
+
+
+To sum up: people *who you share with* are *in* your aspects. People *who share with you* have you in
+their aspects. These two states can be mixed.
+
+
----
###### Manual for `diaspy`, written by Marek Marecki