Exemplo n.º 1
0
        /// <summary>
        /// Get all projects.
        /// </summary>
        /// <param name="client">The Asana client to use to send the request.</param>
        /// <returns>Returns the compact project records for some filtered set of projects. Use one or more request parameters to filter the projects returned.</returns>
        public static List <Project> GetAllProjects(Client client)
        {
            string resource = "projects/";
            var    request  = new AsanaRequest(client, Method.GET, resource);

            return(request.Execute <List <Project> >(client));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get all workspaces available to user.
        /// </summary>
        /// <param name="client">The Asana client to use to send the request.</param>
        /// <returns>Returns the compact records for all workspaces visible to the authorized user.</returns>
        public static List <Workspace> GetAllWorkspaces(Client client)
        {
            string resource = "workspaces/";
            var    request  = new AsanaRequest(client, Method.GET, resource);

            return(request.Execute <List <Workspace> >(client));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get all tags.
        /// </summary>
        /// <param name="client">The Asana client to use to send the request.</param>
        /// <returns>Returns the compact tag records for some filtered set of tags. Use one or more request parameters to filter the tags returned.</returns>
        public static List <Tag> GetAllTags(Client client)
        {
            string resource = "tags/";
            var    request  = new AsanaRequest(client, Method.GET, resource);

            return(request.Execute <List <Tag> >(client));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Create a new Asana project in a specified workspace.
        /// </summary>
        /// <param name="name">The name of the new project.</param>
        /// <param name="workspaceID">The workspace to create the project in.</param>
        /// <param name="description">(optional) The description of the project.</param>
        /// <returns>The newly-created Asana Project object.</returns>
        public static Project CreateProject(Client client, string name, string workspaceID, string description = null)
        {
            /// web requests can take a long time, so we validate data before POST and bail early if required
            if (String.IsNullOrEmpty(name) || string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException("Must supply a name.");
            }
            if (Helpers.Classes.CheckId(workspaceID) == false)
            {
                throw new ArgumentException("Must supply a valid workspace ID.");
            }


            var request = new AsanaRequest(client, Method.POST, "projects/");

            try
            {
                request.restRequest.AddParameter("workspace", workspaceID, ParameterType.GetOrPost);
                request.restRequest.AddParameter("name", name, ParameterType.GetOrPost);
                request.restRequest.AddParameter("notes", description, ParameterType.GetOrPost);
            }
            catch (NullReferenceException e)
            {
                throw new Exception("One or more of the supplied parameters was missing.");
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }

            return(request.Execute <Project>(client));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Get all projects in a specific workspace.
        /// </summary>
        /// <param name="client">The Asana client to use to send the request.</param>
        /// <param name="workspaceId">The id of the workspace whose projects to retrieve.</param>
        /// <returns>Returns the compact project records for all projects in the workspace.</returns>
        public static List <Project> GetByWorkspace(Client client, string workspaceId)
        {
            if (!Helpers.Classes.CheckId(workspaceId))
            {
                throw new ArgumentException("Invalid workspace id.");
            }
            string resource = "workspaces/" + workspaceId + "/projects/";
            var    request  = new AsanaRequest(client, Method.GET, resource);

            return(request.Execute <List <Project> >(client));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Get a specific Asana project.
        /// </summary>
        /// <param name="client">The Asana client to use to send the request.</param>
        /// <param name="projectId">The ID of the project to retrieve.</param>
        /// <returns>Returns the complete task record for a single project.</returns>
        public static Project GetById(Client client, string projectId)
        {
            if (!Helpers.Classes.CheckId(projectId))
            {
                throw new ArgumentException("Invalid project id.");
            }
            string resource = "projects/" + projectId;
            var    request  = new AsanaRequest(client, Method.GET, resource);

            return(request.Execute <Project>(client));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Get the details of a specific Asana user.
        /// </summary>
        /// <param name="client">The Asana client to use to send the request.</param>
        /// <param name="userId">The id of the user to retrieve.</param>
        /// <returns>The requested Asana user.</returns>
        public static User GetById(Client client, string userId)
        {
            if (!Helpers.Classes.CheckId(userId))
            {
                throw new ArgumentException("Supplied task id is invalid.");
            }
            string resource = "users/" + userId;
            var    request  = new AsanaRequest(client, Method.GET, resource);

            return(request.Execute <User>(client));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Get a specific Asana tag.
        /// </summary>
        /// <param name="client">The Asana client to use to send the request.</param>
        /// <param name="tagId">The ID of the tag to retrieve.</param>
        /// <returns>Returns the complete tag record for a single tag.</returns>
        public static Tag GetById(Client client, string tagId)
        {
            if (!Helpers.Classes.CheckId(tagId))
            {
                throw new ArgumentException("Invalid tag id.");
            }
            string resource = "tags/" + tagId;
            var    request  = new AsanaRequest(client, Method.GET, resource);

            return(request.Execute <Tag>(client));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Get all sections in a specific project.
        /// </summary>
        /// <param name="client">The Asana client to use to send the request.</param>
        /// <param name="projectId">The id of the project whose sections to retrieve.</param>
        /// <returns>Returns compact records for all sections in the specified project.</returns>
        public List <Section> GetSectionsByProject(Client client, string projectId)
        {
            if (!Helpers.Classes.CheckId(projectId))
            {
                throw new ArgumentException("Invalid project id.");
            }
            string resource = "projects/" + projectId + "/sections/";
            var    request  = new AsanaRequest(client, Method.GET, resource);

            return(request.Execute <List <Section> >(client));
        }
Exemplo n.º 10
0
        /// <summary>
        /// Get the subtasks of a specific Asana task.
        /// </summary>
        /// <param name="client">The Asana client to use to send the request.</param>
        /// <param name="taskId">The ID of the task whose subtasks to retrieve.</param>
        /// <returns>Returns a compact representation of all of the subtasks of a task.</returns>
        public static List <Task> GetSubtasksByTask(Client client, string taskId)
        {
            if (!Helpers.Classes.CheckId(taskId))
            {
                throw new ArgumentException("Invalid task id.");
            }
            string resource = "tasks/" + taskId + "/subtasks/";
            var    request  = new AsanaRequest(client, Method.GET, resource);

            return(request.Execute <List <Task> >(client));
        }
Exemplo n.º 11
0
        /// <summary>
        /// Get all projects in a specific workspace.
        /// </summary>
        /// <param name="client">The Asana client to use to send the request.</param>
        /// <param name="teamId">The id of the team whose projects to retrieve.</param>
        /// <returns>Returns the compact project records for all projects in the team.</returns>
        public static List <Project> GetByTeam(Client client, string teamId)
        {
            if (!Helpers.Classes.CheckId(teamId))
            {
                throw new ArgumentException("Invalid team id.");
            }
            string resource = "teams/" + teamId + "/projects/";
            var    request  = new AsanaRequest(client, Method.GET, resource);

            return(request.Execute <List <Project> >(client));
        }
Exemplo n.º 12
0
        /// <summary>
        /// Get all users.
        /// </summary>
        /// <param name="client">The Asana client to use to send the request.</param>
        /// <param name="workspaceId">(optional) The id of the workspace whose users to retrieve.</param>
        /// <returns>Returns the user records for all users in all workspaces and organizations accessible to the authenticated user. Accepts an optional workspace ID parameter.</returns>
        public static List <User> GetAllUsers(Client client, string workspaceId = null)
        {
            string resource = "";

            if (Helpers.Classes.CheckId(workspaceId))
            {
                resource = "workspaces/" + workspaceId + "/users/";
            }
            else
            {
                resource = "users/";
            }
            var request = new AsanaRequest(client, Method.GET, resource);

            return(request.Execute <List <User> >(client));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Get the details for the currently logged in Asana user, usually the owner of the token used.
        /// </summary>
        /// <param name="client">The Asana client to use to send the request.</param>
        /// <returns>The Asana current user.</returns>
        public static User GetBySession(Client client)
        {
            var request = new AsanaRequest(client, Method.GET, "users/me");

            return(request.Execute <User>(client));
        }
Exemplo n.º 14
0
        /// <summary>
        /// Create an Asana task by uploading an Asana Task object.
        /// </summary>
        /// <param name="task">The task to upload.</param>
        /// <returns>The createad task.</returns>
        public static Task CreateTask(Client client, Task task)
        {
            /// web requests can take a long time, so we validate data before POST and bail early if required
            if (task == null)
            {
                throw new ArgumentException("Must supply a valid task.");
            }
            if (task.Workspace == null)
            {
                throw new ArgumentException("Must specify a workspace when creating a task.");
            }
            if (Helpers.Classes.CheckId(task.Workspace.Id) == false)
            {
                throw new ArgumentException("Invalid workspace id.");
            }
            if (task.Projects == null)
            {
                throw new ArgumentException("Must specify a project when creating a task.");
            }
            task.Projects.ForEach(p =>
                                  { if (Helpers.Classes.CheckId(p.Id) == false)
                                    {
                                        throw new ArgumentException("Invalid project id.");
                                    }
                                  }
                                  );


            var request = new AsanaRequest(client, Method.POST, "tasks/");

            try
            {
                request.restRequest.AddParameter("workspaces", task.Workspace.Id, ParameterType.GetOrPost);
                request.restRequest.AddParameter("name", task.Name, ParameterType.GetOrPost);
                if (task.Projects.Any())
                {
                    var projects = string.Join(",", task.Projects.Select(p => p.Id).ToArray());
                    request.restRequest.AddParameter("projects", projects, ParameterType.GetOrPost);
                }
                if (task.Tags.Any())
                {
                    var tags = string.Join(",", task.Tags.Select(t => t.Id).ToArray());
                    request.restRequest.AddParameter("tags", tags, ParameterType.GetOrPost);
                }
                request.restRequest.AddParameter("notes", task.Notes, ParameterType.GetOrPost);
                if (task.Assignee != null)
                {
                    request.restRequest.AddParameter("assignee", task.Assignee.Id, ParameterType.GetOrPost);
                }
            }
            catch (NullReferenceException e)
            {
                throw new Exception("One or more of the supplied parameters was missing.");
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }

            return(request.Execute <Task>(client));
        }