Пример #1
0
def gettoken():

    content = request.get_json()

    if content is None:
        return JSONResponse(BadRequest)

    if len(content) == 2 and "username" in content and "password" in content:
        login_result = api_lib.GetToken(
            content["username"], content["password"])
        return JSONResponse(login_result)
    else:
        return JSONResponse(BadRequest)
Пример #2
0
def getcheckouts():

    content = request.get_json()

    if len(content) == 2 and "year" in content and "month" in content and not request.headers.get("Authorization") is None:
        try:
            authorization_token = request.headers.get(
                "Authorization").split("Bearer ")[1]
            if len(authorization_token) != 288:
                raise ValueError("Token not the right length")
        except:
            return JSONResponse(BadRequest)

        checkouts_result = api_lib.GetCheckouts(
            authorization_token, content["year"], content["month"])
        return JSONResponse(checkouts_result)
    else:
        return JSONResponse(BadRequest)
Пример #3
0
def setmenus():

    content = request.get_json()

    if len(content) == 1 and "choices" in content and not request.headers.get("Authorization") is None:
        try:
            authorization_token = request.headers.get(
                "Authorization").split("Bearer ")[1]
            if len(authorization_token) != 288:
                raise ValueError("Token not the right length")
        except:
            return JSONResponse(BadRequest)

        menus_result = api_lib.SetMenus(
            authorization_token, content["choices"])
        return JSONResponse(menus_result)

    else:
        return JSONResponse(BadRequest)
Пример #4
0
def teapot():
    return JSONResponse(ImATeapot)
Пример #5
0
def getcoffee():
    parsed_ua = parse(request.headers.get("User-Agent"))
    if parsed_ua.is_pc or parsed_ua.is_tablet or parsed_ua.is_mobile:
        return HTMLGetCoffee()
    else:
        return JSONResponse(GetCoffee)
Пример #6
0
def handler(e):
    return JSONResponse({"error": True, "status_code": 404, "message": "Not found"})
Пример #7
0
def version():
    return JSONResponse(About())