__author__ = 'Aran' from flask import Blueprint import json from GithubAPI.GithubAPI import GitHubAPI_Keys from google.appengine.ext import db import requests import datetime from flask import Flask, request, render_template, redirect, abort, Response from flask.ext.github import GitHub from flask.ext.cors import CORS, cross_origin from flask.ext.autodoc import Autodoc # DB Models from models.User import User #Validation Utils Libs from SE_API.Validation_Utils import * from SE_API.Respones_Utils import * user_routes = Blueprint("user_routes", __name__) auto = Autodoc() @user_routes.route('/api/users/getUserByToken/', methods=["GET"]) @auto.doc() def getUserByToken(token): """ >This Call will return a user by a given token
Route Parameters
- seToken: 'seToken'

Payload
- NONE

Response
200 - JSON Example:
{
'username': 'DarkLord',
'name': 'Darth Vader',
'email': 'darkLord@death.planet,
'isLecturer': 'True',
'seToken': 'xxxxxx-xxxxx-xxxxx-xxxxxx',
'avatar_url': 'http://location.git.com/somthing'
'isFirstLogin': False,
'campuses_id_list': ['JCA','JCB','JCC'],
'classes_id_list': ['a','b','c']
}

403 - No User Found """ query = User.all() query.filter("seToken = ", token) for u in query.run(limit=5): return Response(response=u.to_JSON(), status=200, mimetype="application/json") # Real response! return bad_request("No User Found") @user_routes.route('/api/users/updateUser/', methods=["GET"]) @auto.doc() def updateUser(token): """ >This Call will update user details
Route Parameters
- seToken: 'seToken'

Payload
- JSON Object, Example:
{
'name': 'Campus name',
'isLecturer': '@campus.ac.com',
}

Response
200 - User updated
400 - Bad Request """ if not request.data: return bad_request() try: payload = json.loads(request.data) except Exception as e: return bad_request(e) user = get_user_by_token(token) if user is None: return bad_request("Not a user!") try: user.name = payload['user'] except Exception: pass try: user.isLecturer = payload['isLecturer'] except Exception: pass return ok("User updated") @user_routes.route('/api/users/help') def documentation(): return auto.html()