Example #1
0
def delete_task(tasklist_id, id):
	"""
	DELETE /<tasklist_id>/tasks/<task_id> - Remove a Task from a TaskList.

	PARAMETERS:
		tasklist_id - Id of the tasklist
		task_id - Id of the task
	"""
	try:
		models.remove_task(id)
		return render_json('{"okay": "deleted"}')
	except TaskNotFoundException as e:
		return render_json('{"error": %s }', e.message), 404
Example #2
0
def create_task(tasklist_id):
	"""
	POST /<tasklist_id>/tasks - Create a task associating it to a tasklist

	PARAMETERS:
		tasklist_id - Id of existent TaskList
		model
			title - Title of the task
			completed - Status of the task
	"""
	task = request.json['model']
	if TaskValidator.valid(task):
		task = models.create_task(tasklist_id, task['title'], task['completed'])
		return render_json(to_json(task))
	else:
		return render_json('{"error": "Invalid task parameters"}'), 400
Example #3
0
def get_tasks(tasklist_id):
	"""
	GET /<tasklist_id>/tasks - Get all tasks that belogs to a tasklist

	PARAMETERS:
		tasklist_id - Id of tasklist
		token - Token given for authorization
	"""
	return render_json(to_json(models.get_tasks(tasklist_id)))
Example #4
0
def create_tasklist():
	"""
	POST /api/tasklists - Create a TaskList

	PARAMETERS:
		model
			tasklist_id - Id of tasklist
			password - Password to retrieve token
	"""
	task = request.json['model']
	try:
		if TaskListValidator.valid(task):
			tasklist = models.create_tasklist(task['tasklist_id'], task['password'])
			return render_json(to_json(tasklist))
		else:
			return render_json('{"error": "Invalid tasklist parameters"}'), 400
	except TaskListAlreadyExistsException, e:
		return render_json('{"error": "%s"}' % e.message), 409
Example #5
0
def authorize():
	"""
	POST /api/get_token - Authorize a client to use the api by giving a temporary token to access the API

	PARAMETERS:
		tasklist_id - Id of tasklist
		password - Password to retrieve token
	"""
	try:
		if models.authorize_user(request.json['tasklist_id'], request.json['password']):
			token = generate_uuid(request.json['tasklist_id']);
			cache.set('key' + request.json['tasklist_id'], token)
			
			json_str = '{"tasklist_id": "%s", "token": "%s"}' % (request.json['tasklist_id'], token)
			return render_json(json_str)
		else:
			return render_json('{"error": "Invalid credentials"}'), 401
	except TaskListNotFoundException, e:
		return render_json('{"error": "%s"}' % e.message), 404
Example #6
0
def update_task(tasklist_id, task_id):
	"""
	PUT /<tasklist_id>/tasks/<task_id> - Modify the status of a Task that belongs to a TaskList.

	PARAMETERS:
		tasklist_id - Id of tasklist
		task_id - Id of the task
		model
			title - Title of the task
			completed - Status of the task
	"""
	try:
		task = request.json['model']
		if TaskValidator.valid(task):
			task = models.update_task(task_id, task['title'], task['completed'])
			return render_json(to_json(task))
		else:
			return render_json('{"error": "Invalid parameters"}'), 400
	except TaskNotFoundException as e:
		return render_json('{"error": %s }', e.message), 404
Example #7
0
 def decorated_view(*args, **kwargs):
     cacheToken = cache.get('key' + kwargs.get('tasklist_id'))
     if not request.headers.get('X-Authorization') or cacheToken != request.headers.get('X-Authorization'):
         return render_json('{"error": "Authentication required"}'), 401
     return func(*args, **kwargs)
Example #8
0
 def decorated_view(*args, **kwargs):
     tasklist = models.get_tasklist(kwargs.get('tasklist_id'))
     if not tasklist:
         return render_json('{"error": "Tasklist not found"}'), 404
     return func(*args, **kwargs)