def delete_variable(self, request):
     variable = Variable.get_by_id(request.id)
     if not variable:
         raise endpoints.NotFoundException(
           "The variable ID: " + str(request.id) + " doesn't exist")
     variable.key.delete()
     return message_types.VoidMessage()
 def get_variable(self, request):
     variable = Variable.get_by_id(request.id)
     if not variable:
         raise endpoints.NotFoundException(
           "The variable ID: " + str(request.id) + " doesn't exist")
     return VariableListResponse(
         variables=[VariableApiHelper().to_message(variable)])
 def update_variable(self, request):
     variable = Variable.get_by_id(request.id)
     if not variable:
         raise endpoints.NotFoundException(
           "The variable ID: " + str(request.id) + " doesn't exist")
     updated_variable = Variable.update(
         variable,
         request.name,
         request.tipo,
         request.keywords,
         request.description,
         request.definitions
         )
     if not updated_variable:
         raise endpoints.BadRequestException('Something went wrong')
     return VariableListResponse(
         variables=[VariableApiHelper().to_message(variable)])
 def create_variable(self, request):
     if not(request.name and request.tipo):
         raise endpoints.BadRequestException('name and type are required')
     variable = Variable.create(
         request.name,
         request.tipo,
         request.keywords,
         request.description,
         request.definitions
         )
     if not variable:
         raise endpoints.InternalServerErrorException('Something went wrong')
     return VariableListResponse(
         variables=[VariableApiHelper().to_message(variable)])
 def get_variables(self, request):
     variables = Variable.get_all()
     return VariableListResponse(
         variables=[VariableApiHelper().to_message(variable) for variable in variables if variables])