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())
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())
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())
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)
def get(self, post_id): return jsonify(g.entity.posts.get_or_404(id=post_id))
def get(self): """Gets all posts""" return jsonify(g.entity.posts)
def put(self, follower_id): """Updates a following relationship.""" return jsonify( follow.update_follower(g.entity, follower_id, request.json))
def put(self, follower_id): """Updates a following relationship.""" return jsonify(follow.update_follower( g.entity, follower_id, request.json))
def description(): """Returns information about the server""" return jsonify({'description': __doc__, 'version': __version__})
def get(self, schema): """Get a single profile.""" return jsonify(g.entity.profiles.get_or_404(schema=schema))
def get(self): """Return the profiles belonging to the entity""" return jsonify({p.schema: p.to_json() for p in g.entity.profiles})
def post(self): """Starts following a user, defined by the post data""" return jsonify(follow.start_following(g.entity, request.json))
def get(self, follower_id): """Returns the json representation of a follower""" return jsonify(g.entity.followers.get_or_404(id=follower_id))
def description(): """Returns information about the server""" return jsonify({"description": __doc__, "version": __version__})