Beispiel #1
0
def listItems():
    jwt_decoded, resp = jwtvalidator.checkAuthorization( "Api.Read" )
    if resp:
       return resp

    resp = Response( json.dumps(itemList), status=200, mimetype='application/json')
    return resp
Beispiel #2
0
def echoApi():
    jwt_decoded, resp = jwtvalidator.checkAuthorization()
    if resp:
        return resp
    expTime = datetime.datetime.fromtimestamp(jwt_decoded['exp']).isoformat()
    return "Hello " + jwt_decoded[
        'name'] + "! Your access token is valid until " + expTime
Beispiel #3
0
def deleteItem(id):
    jwt_decoded, resp = jwtvalidator.checkAuthorization( "Api.Write" )
    if resp:
       return resp

    for i in range (len(itemList)):
       if itemList[i]['id'] == id:
          del itemList[i]
          return restapihelper.generateItemRemovedResponse( id )

    return restapihelper.generateItemNotFoundResponse( id )
Beispiel #4
0
def getItem(id):
    jwt_decoded, resp = jwtvalidator.checkAuthorization( "Api.Read" )
    if resp:
       return resp

    result=[item for item in itemList if item['id'] == id]
    if len(result) > 0:
       resp = Response( json.dumps(result), status=200, mimetype='application/json')
    else:
       return restapihelper.generateItemNotFoundResponse( id )

    return resp
Beispiel #5
0
def updateItem(id):
    jwt_decoded, resp = jwtvalidator.checkAuthorization( "Api.Write" )
    if resp:
       return resp

    resp = restapihelper.validateContentType( 'application/json' )
    if resp:
       return resp

    resp = restapihelper.validateRequestBody()
    if resp:
       return resp

    appData = json.loads( request.data )
    for i in range (len(itemList)):
       if itemList[i]['id'] == id:
          itemList[i] = appData
          return restapihelper.generateItemUpdatedResponse( id )

    return restapihelper.generateItemNotFoundResponse( id )
Beispiel #6
0
def createItem(id):
    jwt_decoded, resp = jwtvalidator.checkAuthorization( "Api.Write" )
    if resp:
       return resp

    resp = restapihelper.validateContentType( 'application/json' )
    if resp:
       return resp

    resp = restapihelper.validateRequestBody()
    if resp:
       return resp

    result=[item for item in itemList if item['id'] == id]
    if len(result) > 0:
       return restapihelper.generateItemAlreadyExists( id )

    appData = json.loads( request.data )
    itemList.append( appData )
    return restapihelper.generateItemCreatedResponse( id )