Exemplo n.º 1
0
        /// <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));
        }
Exemplo n.º 2
0
        /// <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));
        }
Exemplo n.º 3
0
        /// <summary>
        /// This endpoint is used to list all tasks for a given file, or all tasks created by (or assigned to) the user
        /// issuing the API request. Currently, even Administrators can not list all of the tasks for the domain or
        /// tasks "created by" or "assigned to" other users.
        /// </summary>
        /// <param name="groupId">Optional. Persistent ID of a file for which you want to see the tasks. One (or more) of the
        /// three parameters has to be provided: groupId, assigneeId or assignorId.</param>
        /// <param name="assigneeId">Optional. ID of a user the tasks are assigned to. Only ID of the user issuing the API
        /// request is currently permitted. One (or more) of the three parameters has to be provided: groupId,
        /// assigneeId or assignorId.</param>
        /// <param name="assignorId">Optional. ID of a user who created the tasks you want to see. Only ID of the user issuing
        /// the API request is currently permitted. One (or more) of the three parameters has to be provided: groupId,
        /// assigneeId or assignorId.</param>
        /// <param name="limit">Optional. Maximum number of results to return. When the limit is set to 0, the request can be
        /// used to receive the total number of available results (based on the totalCount parameter). The maximum
        /// value of the limit is 50. The default value for the limit is 50 as well.</param>
        /// <param name="offset">Optional. A zero-based index which can be used with the limit to paginate the list of tasks.
        /// Offset defaults to 0.</param>
        /// <param name="sortBy">Optional. Specifies how to sort the results.</param>
        /// <param name="sortDirection">Optional. Specifies how the results should be sorted.</param>
        /// <returns></returns>
        public async Task <TasksList> ListTasks(
            string groupId              = null,
            long?assigneeId             = null,
            long?assignorId             = null,
            int?limit                   = null,
            int?offset                  = null,
            string sortBy               = null,
            SortDirection sortDirection = SortDirection.Ascending)
        {
            if (limit < 0 || limit > 50)
            {
                throw new ArgumentOutOfRangeException(nameof(limit), "Non-negative integers between 0 and 50.");
            }

            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(offset));
            }

            var sortValues = new[] { "creationDate", "dueDate" };

            if (!string.IsNullOrWhiteSpace(sortBy) && !sortValues.Contains(sortBy))
            {
                throw new ArgumentException(nameof(sortBy), "Possible values: " + string.Join(", ", sortValues));
            }

            if (string.IsNullOrWhiteSpace(groupId) && !assigneeId.HasValue && !assignorId.HasValue)
            {
                throw new ArgumentNullException(
                          nameof(groupId),
                          string.Format(
                              "Supply one (or more) of the three parameters: {0}, {1} or {2}.",
                              nameof(groupId),
                              nameof(assigneeId),
                              nameof(assignorId)));
            }

            var httpRequest = new HttpRequestMessage(
                HttpMethod.Get,
                ListTasksRequestUri(
                    TasksMethod,
                    groupId,
                    assigneeId,
                    assignorId,
                    limit,
                    offset,
                    sortBy,
                    sortDirection));

            var serviceHandler = new ServiceHandler <TasksListResponse>(httpClient);
            var response       = await serviceHandler.SendRequestAsync(httpRequest).ConfigureAwait(false);

            return(TasksHelper.MapTasksListResponse(response.Data));
        }
Exemplo n.º 4
0
        /// <summary>
        /// This endpoint is used to get the details for a specific task.
        /// </summary>
        /// <param name="taskId">The id of the task.</param>
        /// <returns></returns>
        public async Task <TaskDetails> GetTaskDetails(string taskId)
        {
            if (string.IsNullOrWhiteSpace(taskId))
            {
                throw new ArgumentNullException(nameof(taskId));
            }

            var uriBuilder  = BuildUri(TasksMethod + "/" + taskId);
            var httpRequest = new HttpRequestMessage(HttpMethod.Get, uriBuilder.Uri);

            var serviceHandler = new ServiceHandler <TaskResponse>(httpClient);
            var response       = await serviceHandler.SendRequestAsync(httpRequest).ConfigureAwait(false);

            return(TasksHelper.MapTaskResponseToTaskDetails(response.Data));
        }