Exemple #1
0
 def put(self, schema):
     """Update a profile."""
     try:
         profile = g.entity.profiles.get(schema=schema)
         profile.update_values(request.json)
     except Profile.DoesNotExist:
         profile = Profile(entity=g.entity, schema=schema, **request.json)
     return jsonify(profile.save())
Exemple #2
0
    def post(self):
        """Create a new profile of the specified type.
        
        This is specific to pytentd, and is similar to PUT /profile/<schema>.

        TODO: Document this!
        TODO: This doesn't appear to be covered by any tests
        """
        if not 'schema' in request.json:
            raise APIBadRequest("A profile schema is required.")
        
        return jsonify(Profile(entity=g.entity, **request.json).save())
Exemple #3
0
    def put(self, post_id):
        post = g.entity.posts.get_or_404(id=post_id)

        # TODO: Posts have more attributes than this

        if 'content' in request.json:
            post.content = request.json['content']
        if 'schema' in request.json:
            post.schema = request.json['schema']

        # TODO: Versioning.

        return jsonify(post.save())
Exemple #4
0
    def put(self, post_id):
        post = g.entity.posts.get_or_404(id=post_id)

        # TODO: Posts have more attributes than this

        if 'content' in request.json:
            post.content = request.json['content']
        if 'schema' in request.json:
            post.schema = request.json['schema']

        # TODO: Versioning.

        return jsonify(post.save())
Exemple #5
0
    def post(self):
        """ Used by apps to create a new post.

        Used by other servers to notify of a mention from a non-followed
        entity.

        TODO: Separate between apps creating a new post and a notification
        from a non-followed entity.
        """
        new_post = Post()
        new_post.entity = g.entity
        new_post.schema = request.json['schema']
        new_post.content = request.json['content']

        new_post.save()

        # TODO: Do this asynchronously?
        for to_notify in g.entity.followers:
            notification_link = follow.get_notification_link(to_notify)
            requests.post(notification_link, data=jsonify(new_post.to_json()))
            # TODO: Handle failed notifications somehow

        return jsonify(new_post)
Exemple #6
0
    def post(self):
        """ Used by apps to create a new post.

        Used by other servers to notify of a mention from a non-followed
        entity.

        TODO: Separate between apps creating a new post and a notification
        from a non-followed entity.
        """
        new_post = Post()
        new_post.entity = g.entity
        new_post.schema = request.json['schema']
        new_post.content = request.json['content']

        new_post.save()

        # TODO: Do this asynchronously?
        for to_notify in g.entity.followers:
            notification_link = follow.get_notification_link(to_notify)
            requests.post(notification_link, data=jsonify(new_post.to_json()))
            # TODO: Handle failed notifications somehow

        return jsonify(new_post)
Exemple #7
0
 def get(self, post_id):
     return jsonify(g.entity.posts.get_or_404(id=post_id))
Exemple #8
0
 def get(self):
     """Gets all posts"""
     return jsonify(g.entity.posts)
Exemple #9
0
 def put(self, follower_id):
     """Updates a following relationship."""
     return jsonify(
         follow.update_follower(g.entity, follower_id, request.json))
Exemple #10
0
 def put(self, follower_id):
     """Updates a following relationship."""
     return jsonify(follow.update_follower(
         g.entity, follower_id, request.json))
Exemple #11
0
def description():
    """Returns information about the server"""
    return jsonify({'description': __doc__, 'version': __version__})
Exemple #12
0
 def get(self, schema):
     """Get a single profile."""
     return jsonify(g.entity.profiles.get_or_404(schema=schema))
Exemple #13
0
 def get(self):
     """Return the profiles belonging to the entity"""
     return jsonify({p.schema: p.to_json() for p in g.entity.profiles})
Exemple #14
0
 def get(self, post_id):
     return jsonify(g.entity.posts.get_or_404(id=post_id))
Exemple #15
0
 def post(self):
     """Starts following a user, defined by the post data"""
     return jsonify(follow.start_following(g.entity, request.json))
Exemple #16
0
 def post(self):
     """Starts following a user, defined by the post data"""
     return jsonify(follow.start_following(g.entity, request.json))
Exemple #17
0
 def get(self, follower_id):
     """Returns the json representation of a follower"""
     return jsonify(g.entity.followers.get_or_404(id=follower_id))
Exemple #18
0
 def get(self, follower_id):
     """Returns the json representation of a follower"""
     return jsonify(g.entity.followers.get_or_404(id=follower_id))
Exemple #19
0
def description():
    """Returns information about the server"""
    return jsonify({"description": __doc__, "version": __version__})
Exemple #20
0
 def get(self):
     """Gets all posts"""
     return jsonify(g.entity.posts)