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
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
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 )
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
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 )
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 )