def delete(self, ): print "Delete operation of resource: robotApp" try: response = RobotappImpl.delete() except KeyError as inst: return NotFoundError(inst.args[0] + " not found") else: return Successful('Successful operation')
def get(self, ): print "Retrieve operation of resource: robotApp" try: response = RobotappImpl.get() except KeyError as inst: return NotFoundError(inst.args[0] + " not found") else: js = response.json_serializer() return Successful("Successful operation", json_dumps(js))
def put(self, ): print "Update operation of resource: robotApp" # pass commands to another robot try: resendCommand(request.data) # resend command to R4 except Exception: pass json_struct = request.get_json() #json parser. try: existing_object = RobotappImpl.get() except KeyError as inst: if inst.args[0] != '': return NotFoundError(inst.args[0] + " not found") new_object = create_instance(robotApp, json_struct) if isinstance(new_object, BadRequestError): return new_object elif isinstance(new_object, NotFoundError): return new_object else: try: RobotappImpl.put(new_object) js = new_object.json_serializer() except KeyError as inst: return NotFoundError(inst.args[0] + " not found") else: existing_object = modify_instance(existing_object, json_struct) if isinstance(existing_object, BadRequestError): return existing_object elif isinstance(existing_object, NotFoundError): return existing_object else: try: RobotappImpl.put(existing_object) js = existing_object.json_serializer() except KeyError as inst: return NotFoundError(inst.args[0] + " not found") return Successful("Successful operation", json_dumps(js))
def post(self, ): print "Create operation of resource: robotApp" try: response = RobotappImpl.get() except KeyError as inst: if inst.args[0] != '': return NotFoundError(inst.args[0] + " not found") json_struct = request.get_json() #json parser. new_object = create_instance(robotApp, json_struct) if isinstance(new_object, BadRequestError): return new_object elif isinstance(new_object, NotFoundError): return new_object else: try: RobotappImpl.post(new_object) js = new_object.json_serializer() except KeyError as inst: return NotFoundError(inst.args[0] + " not found") else: return BadRequestError( "Object already exists. For updates use PUT.") return Successful("Successful operation", json_dumps(js))