Exemple #1
0
 def open(self):
     """Open a new session and log in with given username and password."""
     response = get_service('Login').request(
         username=self.username, password=self.password)
     try:
         self.user_id = response['user_id']
     except KeyError:
         messages = listify(response['messages'])
         raise LoginFailed(*messages)
Exemple #2
0
    def add_friend(self, friend_id):
        """Adds a new friend connection to this user.

        Arguments:
        friend_id -- The user id of the friend being requested.

        """
        service = get_service('AddFriends')
        result = service.request(user_id=self.user_id, friend_id=friend_id)
        return result
Exemple #3
0
    def reject_friend_request(self, friend_id):
        """Rejects a friend request.

        Arguments:
        friend_id -- User id of the friend whose request this user is rejecting

        """
        service = get_service('RejectFriendRequest')
        result = service.request(user_id=self.user_id, friend_id=friend_id)
        return result
Exemple #4
0
    def remove_friend(self, friend_id):
        """Removes a friend connection.

        Arguments:
        friend_id -- The user id of the friend being broken up with.

        """
        service = get_service('RemoveFriends')
        result = service.request(user_id=self.user_id, friend_id=friend_id)
        try:
            return result['result']
        except TypeError:
            return None
Exemple #5
0
def create(username, password, email):
    """Create a new user.

    Returns the user id of the new user, if everything goes well.

    Arguments:
    username -- The desired username. Must be unique in the system. Length
                4-20 characters.
    password -- User's password.
    email -- User's email address.

    Exceptions:
    ValueError -- Given parameters were invalid.

    """
    register_service = get_service('Register')
    response = register_service.request(
        username=username, password=password, email=email)

    if 'messages' in response:
        messages = listify(response['messages'])
        raise ValueError(*messages)

    return response['user_id']
Exemple #6
0
 def close(self):
     """Close the current session and log out."""
     get_service('Logout').request(user_id=self.user_id)
     self.user_id = None