From: Marek Marecki Date: Wed, 5 Jun 2013 19:43:39 +0000 (+0200) Subject: Some stuff done X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=d589deff8d03a8b20d91f922c8c06c800a82867b;p=diaspy.git Some stuff done --- diff --git a/diaspy/models.py b/diaspy/models.py index b5a7d50..5d39226 100644 --- a/diaspy/models.py +++ b/diaspy/models.py @@ -172,8 +172,26 @@ class Aspect(): '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 diff --git a/diaspy/people.py b/diaspy/people.py index a5c2546..79e2582 100644 --- a/diaspy/people.py +++ b/diaspy/people.py @@ -1,5 +1,6 @@ import re from diaspy.streams import Outer +from diaspy.models import Aspect class User: @@ -88,34 +89,47 @@ class Contacts(): 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()] diff --git a/diaspy/streams.py b/diaspy/streams.py index 4e5d78e..64d5c84 100644 --- a/diaspy/streams.py +++ b/diaspy/streams.py @@ -1,6 +1,6 @@ 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 @@ -255,7 +255,7 @@ class Aspects(Generic): 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, @@ -266,7 +266,7 @@ class Aspects(Generic): 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. diff --git a/manual/people.mdown b/manual/people.mdown index 75e5be5..e4563d6 100644 --- a/manual/people.mdown +++ b/manual/people.mdown @@ -43,6 +43,30 @@ Also `User()` object contains a stream for this user. * `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