diff --git a/CHANGELOG.md b/CHANGELOG.md index d80a466..d1989d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ * Added the capability to change password. * Corrected a bug into `pwdhash`: it accepted an argument, but pulled data from the form instead of processing it. Now it uses the argument. * Schema changes: added column `telegram` to `UserProfile` table. To update schema, execute the script `migrate_0_6_to_0_7.py` -* Adding public API. Each of the API endpoints take a mandatory query string argument: the access token, generated by a separate endpoint at `/get_access_token` and stored into the client. All API routes start with `/api/V1`. Added endpoints `feed` and `create`. +* Adding public API. Each of the API endpoints take a mandatory query string argument: the access token, generated by a separate endpoint at `/get_access_token` and stored into the client. All API routes start with `/api/V1`. Added endpoints `feed`, `create` and `profile_info`. ## 0.6.0 diff --git a/app/api.py b/app/api.py index 523281d..1393ce9 100644 --- a/app/api.py +++ b/app/api.py @@ -1,5 +1,5 @@ from flask import Blueprint, jsonify, request -import sys, datetime +import sys, datetime, re from functools import wraps from .models import User, Message from .utils import check_access_token, Visibility @@ -94,3 +94,26 @@ def create(self): push_notification('mention', mention_user, user=user.id) except User.DoesNotExist: pass + +@bp.route('/profile_info/', methods=['GET']) +@validate_access +def profile_info(self, userid): + if userid == 'self': + user = self + elif userid.isdigit(): + user = User[id] + else: + raise ValueError('userid should be an integer or "self"') + profile = user.profile + return { + "user": { + "id": user.id, + "username": user.username, + "full_name": profile.full_name, + "biography": profile.biography, + "website": profile.website, + "generation": profile.year, + "instagram": profile.instagram, + "facebook": profile.facebook, + } + }