/// <summary> /// Create a new Wunderlist task /// </summary> /// <returns></returns> public Wunderlist.DataModels.Task CreateTask(long listId, string title) { if (string.IsNullOrWhiteSpace(title) || listId == null || listId <= 0) { throw new ArgumentException("Invalid arguments"); } var url = this.HostName + "/tasks"; Wunderlist.DataModels.Task result = null; try { var postObject = new Dictionary <string, object>(); postObject.Add("list_id", listId); postObject.Add("title", title); var response = HttpHelper.DoPOST(url, postObject, this.RequestHeaders); result = JsonConvert.DeserializeObject <Wunderlist.DataModels.Task>(response); } catch (Exception e) { throw e; } return(result); }
/// <summary> /// Update the details of a task /// </summary> /// <returns></returns> public Wunderlist.DataModels.Task UpdateTask(Wunderlist.DataModels.Task task) { if (task == null || task.Id <= 0) { throw new ArgumentException("Invalid arguments"); } var currentTask = this.GetTask(task.Id); if (currentTask == null) { throw new Exception("Given task doesn't exist"); } var url = this.HostName + "/tasks/" + task.Id; Wunderlist.DataModels.Task result = null; try { var postObject = new Dictionary <string, object>(); postObject.Add("revision", currentTask.Revision); if (task.Title != currentTask.Title) { postObject.Add("title", task.Title); } if (task.AssigneeId > 0) { postObject.Add("assignee_id", task.AssigneeId); } if (task.AssignerId > 0) { postObject.Add("assigner_id", task.AssignerId); } if (!string.IsNullOrWhiteSpace(task.DueDate)) { postObject.Add("due_date", task.DueDate); } if (task.Starred) { postObject.Add("starred", task.Starred); } var response = HttpHelper.DoPATCH(url, postObject, this.RequestHeaders); result = JsonConvert.DeserializeObject <Wunderlist.DataModels.Task>(response); } catch (Exception e) { throw e; } return(result); }
/// <summary> /// Get details of a specific task /// </summary> /// <returns></returns> public Wunderlist.DataModels.Task GetTask(long taskId) { if (taskId == null || taskId <= 0) { throw new ArgumentException("Invalid task id"); } var url = this.HostName + "/tasks/" + taskId; Wunderlist.DataModels.Task result = null; try { var response = HttpHelper.DoGET(url, null, this.RequestHeaders); result = JsonConvert.DeserializeObject <Wunderlist.DataModels.Task>(response); } catch (Exception e) { throw e; } return(result); }