class AppHandler(object): ''' Handler for retrieving information about a specific app. Also allows app information to be updated, or for an app to be deleted. Only the creator can access and modify the app information. ''' @public_api_auth def GET(self, app_id, auth_user=None, auth_app_id=None): ''' Return a JSON object containing information about the specific app. ''' try: app_id = ObjectId(app_id) except Exception, e: logging.error(e) return error_response(400, 'Not a valid app id') try: app = App.collection.find_one({'_id': app_id, 'deleted': False}) if not app: message = 'App does not exist' logging.warn(message) return error_response(404, message) if not app.user_can_update(auth_user): message = 'App cannot be accessed by the user' logging.warn(message) return error_response(403, message) formatted_dict = app.formatted_dict() return encode_json(formatted_dict) except Exception, e: logging.error(e) return error_response(500, 'Server Error')
def GET(self, app_id, auth_user=None, auth_app_id=None): ''' Return a JSON object containing information about the specific app. ''' try: app_id = ObjectId(app_id) except Exception, e: logging.error(e) return error_response(400, 'Not a valid app id')
def DELETE(self, app_id, auth_user=None, auth_app_id=None): ''' Delete the given app, and returns a JSON object containing a success notification. ''' try: app_id = ObjectId(app_id) except Exception, e: return error_response(400, 'Not a valid app id')
def PUT(self, app_id, auth_user=None, auth_app_id=None): ''' Update the given app, and returns a JSON object containing the new timestamp. ''' try: app_id = ObjectId(app_id) except Exception, e: logging.error(e) return error_response(400, 'Not a valid app id')
def GET(self, auth_user=None, auth_app_id=None): ''' Return JSON array of basic app info. Only returns apps created by the authenticated user. ''' try: spec = {'deleted': False, 'creator': auth_user._id} apps = App.collection.find(spec) formatted_apps = [app.formatted_dict() for app in apps] return encode_json(formatted_apps) except Exception, e: logging.error(e) return error_response(500)
def POST(self, auth_user=None, auth_app_id=None): ''' Create a new app and return a JSON object containing the new app information. ''' params = web.input(data=None) try: if params.data: data = decode_json(params.data) else: data = decode_json(web.ctx.data) App.validate(data) except Exception, e: logging.error(e) return error_response(400, 'Data did not pass validation')
def GET(self, auth_user=None, auth_app_id=None): ''' Return JSON array of basic app info. Only returns apps created by the authenticated user. ''' try: spec = { 'deleted': False, 'creator': auth_user._id } apps = App.collection.find(spec) formatted_apps = [app.formatted_dict() for app in apps] return encode_json(formatted_apps) except Exception, e: logging.error(e) return error_response(500)
else: data = decode_json(web.ctx.data) App.validate(data) except Exception, e: logging.error(e) return error_response(400, 'Data did not pass validation') try: app = App(data) app.set_creator(auth_user) app.save() formatted_dict = app.formatted_dict() return encode_json(formatted_dict) except Exception, e: logging.error(e) return error_response(500) class AppHandler(object): ''' Handler for retrieving information about a specific app. Also allows app information to be updated, or for an app to be deleted. Only the creator can access and modify the app information. ''' @public_api_auth def GET(self, app_id, auth_user=None, auth_app_id=None): ''' Return a JSON object containing information about the specific app. ''' try:
else: data = decode_json(web.ctx.data) App.validate(data) except Exception, e: logging.error(e) return error_response(400, 'Data did not pass validation') try: app = App(data) app.set_creator(auth_user) app.save() formatted_dict = app.formatted_dict() return encode_json(formatted_dict) except Exception, e: logging.error(e) return error_response(500) class AppHandler(object): ''' Handler for retrieving information about a specific app. Also allows app information to be updated, or for an app to be deleted. Only the creator can access and modify the app information. ''' @public_api_auth def GET(self, app_id, auth_user=None, auth_app_id=None): ''' Return a JSON object containing information about the specific app. ''' try: app_id = ObjectId(app_id)