/// <summary> /// This endpoint is used to create a new file-related task for a user. /// </summary> /// <param name="task">An object representing task to be created</param> /// <returns></returns> public async Task <TaskDetails> CreateTask(NewTask task) { if (task == null) { throw new ArgumentNullException(nameof(task)); } if (string.IsNullOrWhiteSpace(task.Task)) { throw new ArgumentException(nameof(task.Task) + " is required.", nameof(task)); } if (string.IsNullOrWhiteSpace(task.File)) { throw new ArgumentException(nameof(task.File) + " is required.", nameof(task)); } if (task.Assignees == null || task.Assignees.Count == 0) { throw new ArgumentException("At least one " + nameof(task.Assignees) + " ID is required.", nameof(task)); } var uriBuilder = BuildUri(TasksMethod); var httpRequest = new HttpRequestMessage(HttpMethod.Post, uriBuilder.Uri) { Content = new StringContent(MapTaskForRequest(task), Encoding.UTF8, "application/json") }; var serviceHandler = new ServiceHandler <TaskResponse>(httpClient); var response = await serviceHandler.SendRequestAsync(httpRequest).ConfigureAwait(false); return(TasksHelper.MapTaskResponseToTaskDetails(response.Data)); }
/// <summary> /// This endpoint is used to edit a specific task. /// </summary> /// <param name="task">Required. The text of the task.</param> /// <param name="assignees">Required. ID of an assignee of the task. Only one assignee is allowed now, although /// technically, it is placed in the array structure. The reason is that in the future, more than one /// assignee might be allowed for a task.</param> /// <param name="dueDate">Optional. Due date of the task. In case the dueDate is not specified in this PUT call, /// it will be set to null.</param> /// <returns></returns> public async Task <TaskDetails> UpdateTask(string taskId, string task, List <long> assignees, DateTime?dueDate = null) { if (string.IsNullOrWhiteSpace(taskId)) { throw new ArgumentNullException(nameof(taskId)); } var taskUpdates = new NewTask() { Task = task, Assignees = assignees, DueDate = dueDate }; var uriBuilder = BuildUri(TasksMethod + "/" + taskId); var httpRequest = new HttpRequestMessage(HttpMethod.Put, uriBuilder.Uri) { Content = new StringContent(MapTaskForRequest(taskUpdates), Encoding.UTF8, "application/json") }; var serviceHandler = new ServiceHandler <TaskResponse>(httpClient); var response = await serviceHandler.SendRequestAsync(httpRequest).ConfigureAwait(false); return(TasksHelper.MapTaskResponseToTaskDetails(response.Data)); }
private string MapTaskForRequest(NewTask task) { var builder = new StringBuilder(); builder .Append("{") .AppendFormat("\"task\" : \"{0}\",", task.Task) .AppendFormat("\"assignees\" : [{0}]", string.Join(",", task.Assignees.Select(a => "{\"id\":" + a + "}"))); if (!string.IsNullOrEmpty(task.File)) { builder.AppendFormat(", \"file\" : {{\"groupId\":\"{0}\"}}", task.File); } if (task.DueDate.HasValue) { builder.AppendFormat(", \"dueDate\": \"{0:yyyy-MM-dd}\"", task.DueDate); } builder.Append("}"); return(builder.ToString()); }