/// <summary> /// Removes a member from a project in Pivotal /// </summary> /// <param name="user">The user to get the ApiToken from</param> /// <param name="project">The project to remove the person from</param> /// <param name="member">The member to remove</param> /// <returns>The member that was removed</returns> public static PivotalMembership RemoveMember(PivotalUser user, PivotalProject project, PivotalMembership member) { string url = String.Format("{0}/projects/{1}/memberships/{2}?token={3}", PivotalService.BaseUrl, project.Id.GetValueOrDefault(), member.Id.GetValueOrDefault(), user.ApiToken); XmlDocument response = PivotalService.SubmitData(url, null, ServiceMethod.DELETE); return(member); }
/// <summary> /// Removes a project in Pivotal (not sure this works) /// </summary> /// <param name="user">The user to get the ApiToken from</param> /// <param name="project">The project to remove</param> /// <returns>The project that was removed</returns> public static PivotalProject DeleteProject(PivotalUser user, PivotalProject project) { string url = String.Format("{0}/projects/{1}?token={2}", PivotalService.BaseUrl, project.Id.GetValueOrDefault(), user.ApiToken); XmlDocument response = PivotalService.SubmitData(url, null, ServiceMethod.DELETE); return(project); }
/// <summary> /// Fetches current projects from Pivot for a given user /// </summary> /// <param name="user">The user to get the ApiToken from</param> /// <returns>List of projects accessible to the user</returns> public static IList <PivotalProject> FetchProjects(PivotalUser user) { string url = String.Format("{0}/projects?token={1}", PivotalService.BaseUrl, user.ApiToken); XmlDocument xml = PivotalService.GetData(url); PivotalProjectList projectList = SerializationHelper.DeserializeFromXmlDocument <PivotalProjectList>(xml); return(projectList.Projects); }
/// <summary> /// Gets s single story for a project /// </summary> /// <param name="user">The user to get the ApiToken from</param> /// <param name="projectId">The id of the project to get stories for</param> /// <param name="storyId">The id of the story to get</param> /// <returns>the stories for the project</returns> public static PivotalStory FetchStory(PivotalUser user, int projectId, string storyId) { string url = String.Format("{0}/projects/{1}/story/{2}?token={3}", PivotalService.BaseUrl, projectId.ToString(), storyId, user.ApiToken); XmlDocument xmlDoc = PivotalService.GetData(url); PivotalStory story = SerializationHelper.DeserializeFromXmlDocument <PivotalStory>(xmlDoc); return(story); }
public ProjectController(PivotalService service, PivotalColumnBuilder columnBuilder) { Mapper.CreateMap <Project, ProjectViewModel>(); Mapper.CreateMap <Story, StoryViewModel>().ForMember(s => s.Owner, s => s.MapFrom(st => st.Owner ?? "Available")); _service = service; _columnBuilder = columnBuilder; }
/// <summary> /// Retrieves the membership information for a project /// </summary> /// <param name="user">The user to get the ApiToken from</param> /// <param name="project">The project to get membership info for</param> /// <returns>List of members in the project</returns> public static PivotalMembershipList FetchMembers(PivotalUser user, PivotalProject project) { string url = String.Format("{0}/projects/{1}/memberships?token={2}", PivotalService.BaseUrl, project.Id.ToString(), user.ApiToken); XmlDocument xml = PivotalService.GetData(url); PivotalMembershipList memberships = SerializationHelper.DeserializeFromXmlDocument <PivotalMembershipList>(xml); return(memberships); }
/// <summary> /// Retrieves the user's information, including the token, from Pivotal /// </summary> /// <param name="login">The user's login</param> /// <param name="password">The user's password</param> /// <returns>A Pivotal User containing the ApiToken for the user</returns> public static PivotalUser GetUserFromCredentials(string login, string password) { string url = String.Format("{0}/tokens/active", PivotalService.BaseUrlHttps); XmlDocument xmlDoc = PivotalService.GetDataWithCredentials(url, login, password); PivotalUser user = SerializationHelper.DeserializeFromXmlDocument <PivotalUser>(xmlDoc); return(user); }
/// <summary> /// Deletes a story from Pivotal /// </summary> /// <param name="user">The user to get the ApiToken from</param> /// <param name="projectId">The project id</param> /// <param name="story">The story id</param> /// <returns>The story that was deleted</returns> public static PivotalStory DeleteStory(PivotalUser user, string projectId, PivotalStory story) { string url = String.Format("{0}/projects/{1}/story/{2}?token={3}", PivotalService.BaseUrl, projectId, story.Id, user.ApiToken); XmlDocument xml = SerializationHelper.SerializeToXmlDocument <PivotalStory>(story); string storyXml = PivotalService.CleanXmlForSubmission(xml, "//story", ExcludeNodesOnSubmit, true); XmlDocument response = PivotalService.SubmitData(url, storyXml, ServiceMethod.DELETE); return(story); }
/// <summary> /// Adds a member to a project /// </summary> /// <param name="user">The user to get the ApiToken from</param> /// <param name="project">The project to get membership info for</param> /// <param name="member">The person and role to add to the project</param> /// <returns>The added member's identity</returns> public static PivotalMembership AddMember(PivotalUser user, PivotalProject project, PivotalMembership member) { string url = String.Format("{0}/projects/{1}/memberships?token={2}", PivotalService.BaseUrl, project.Id.ToString(), user.ApiToken); XmlDocument xml = SerializationHelper.SerializeToXmlDocument <PivotalMembership>(member); string memberXml = PivotalService.CleanXmlForSubmission(xml, "//membership", ExcludeNodesOnSubmit, true); XmlDocument response = PivotalService.SubmitData(url, memberXml, ServiceMethod.POST); return(SerializationHelper.DeserializeFromXmlDocument <PivotalMembership>(response)); }
/// <summary> /// Updates a project in Pivotal /// </summary> /// <param name="user">The user to get the ApiToken from (user will be owner of the project)</param> /// <param name="project">Project information to update</param> /// <returns>The updated project</returns> public static PivotalProject UpdateProject(PivotalUser user, PivotalProject project) { string url = String.Format("{0}/projects/{1}?token={2}", PivotalService.BaseUrl, project.Id.GetValueOrDefault(), user.ApiToken); XmlDocument xml = SerializationHelper.SerializeToXmlDocument <PivotalProject>(project); string projectXml = PivotalService.CleanXmlForSubmission(xml, "//project", ExcludeNodesOnSubmit, true); XmlDocument response = PivotalService.SubmitData(url, projectXml, ServiceMethod.PUT); return(SerializationHelper.DeserializeFromXmlDocument <PivotalProject>(response)); }
/// <summary> /// Adds a note (comment) to a story /// </summary> /// <param name="user">The user to get the ApiToken from</param> /// <param name="noteText">The text to add to the story</param> /// <returns>The text that was added</returns> public string AddNote(PivotalUser user, string noteText) { string url = String.Format("{0}/projects/{1}/stories/{2}?token={3}", PivotalService.BaseUrl, ProjectId, Id, user.ApiToken); string storyXml = String.Format("<note><text>{0}</text></note>", WebEncoding.UrlEncode(noteText)); XmlDocument response = PivotalService.SubmitData(url, storyXml, ServiceMethod.POST); return(noteText); }
public override void Given() { _repository = A.Fake <IProjectRepository>(); _project = Fixture.Build <Project>().With(p => p.Stories, Enumerable.Empty <Story>()).CreateAnonymous(); A.CallTo(() => _repository.GetProject(123)).Returns(_project); A.CallTo(_repository).WithReturnType <IEnumerable <Story> >().Returns(Fixture.CreateMany <Story>(3)); _service = new PivotalService(_repository); }
/// <summary> /// Deletes a task from a story /// </summary> /// <param name="user">The user to get the ApiToken from</param> /// <param name="projectId">The project id</param> /// <param name="storyId">The story id</param> /// <param name="task">The task to delete</param> /// <returns></returns> public static PivotalTask DeleteTask(PivotalUser user, int projectId, int storyId, PivotalTask task) { string url = String.Format("{0}/projects/{1}/story/{2}/task/{3}?token={4}", PivotalService.BaseUrl, projectId, storyId, task.TaskId.GetValueOrDefault().ToString(), user.ApiToken); XmlDocument xml = SerializationHelper.SerializeToXmlDocument <PivotalTask>(task); string taskXml = PivotalService.CleanXmlForSubmission(xml, "//task", ExcludeNodesOnSubmit, true); XmlDocument response = PivotalService.SubmitData(url, taskXml, ServiceMethod.DELETE); return(task); }
/// <summary> /// Adds a task to the story /// </summary> /// <param name="user">The user to get the ApiToken from</param> /// <param name="projectId">The project id</param> /// <param name="storyId">The story id</param> /// <param name="task">The task to add</param> /// <returns>The created task</returns> public static PivotalTask AddTask(PivotalUser user, int projectId, int storyId, PivotalTask task) { string url = String.Format("{0}/projects/{1}/stories/{2}/tasks?token={3}", PivotalService.BaseUrl, projectId, storyId, user.ApiToken); XmlDocument xml = SerializationHelper.SerializeToXmlDocument <PivotalTask>(task); string taskXml = PivotalService.CleanXmlForSubmission(xml, "//story", ExcludeNodesOnSubmit, true); XmlDocument response = PivotalService.SubmitData(url, taskXml, ServiceMethod.POST); return(SerializationHelper.DeserializeFromXmlDocument <PivotalTask>(response)); }
/// <summary> /// Fetches a single project from Pivotal and optionally retrieves the stories and sets them in the Stories property /// </summary> /// <param name="user">The user to get the ApiToken from</param> /// <param name="projectId">The id of the project to retrieve</param> /// <param name="loadStories">Whether to fetch stories and save them in the Stories property</param> /// <returns>project</returns> public static PivotalProject FetchProject(PivotalUser user, int projectId, bool loadStories) { string url = String.Format("{0}/projects/{1}?token={2}", PivotalService.BaseUrl, projectId.ToString(), user.ApiToken); XmlDocument xml = PivotalService.GetData(url); PivotalProject project = SerializationHelper.DeserializeFromXmlDocument <PivotalProject>(xml); if (loadStories) { project.LoadStories(user); } return(project); }
/// <summary> /// Retrieves tasks with an optional filter /// </summary> /// <param name="user">The user to get the ApiToken from</param> /// <param name="projectId">The project id</param> /// <param name="storyId">The story id</param> /// <param name="filter">Filter to pass to Pivotal</param> /// <returns></returns> public static IList <PivotalTask> FetchTasks(PivotalUser user, int projectId, int storyId, string filter) { string url = String.Format("{0}/projects/{1}/story/{2}/tasks?token={3}", PivotalService.BaseUrl, projectId, storyId, user.ApiToken); if (!string.IsNullOrEmpty(filter)) { url += "&" + filter; } XmlDocument xmlDoc = PivotalService.GetData(url); PivotalTaskList taskList = SerializationHelper.DeserializeFromXmlDocument <PivotalTaskList>(xmlDoc); return(taskList.Tasks); }
protected void ServiceReturnsProjectWithStories(Dictionary <string, Story> stories) { _stories = stories; var project = Fixture.Build <Project>() .With(x => x.Name, "project name") .With(x => x.Stories, _stories.Select(s => s.Value)) .CreateAnonymous(); _pivotalService = A.Fake <PivotalService>(); A.CallTo(_pivotalService).WithReturnType <Project>().Returns(project); }
/// <summary> /// Gets the stories for a project using a filter to limit the data returned /// </summary> /// <see cref="PivotalTrackerAPI.Util.PivotalFilterHelper"/> /// <param name="user">The user to get the ApiToken from</param> /// <param name="projectId">The id of the project to get stories for</param> /// <param name="filter">The filter to limit the data returned</param> /// <returns>the stories for the project</returns> public static IList <PivotalStory> FetchStories(PivotalUser user, int projectId, string filter) { string url = String.Format("{0}/projects/{1}/stories?token={2}", PivotalService.BaseUrl, projectId.ToString(), user.ApiToken); if (!string.IsNullOrEmpty(filter)) { url += "&" + filter; } XmlDocument xmlDoc = PivotalService.GetData(url); PivotalStoryList storyList = SerializationHelper.DeserializeFromXmlDocument <PivotalStoryList>(xmlDoc); return(storyList.Stories); }
/// <summary> /// Gets the stories for a project using a filter to limit the data returned /// </summary> /// <see cref="PivotalTrackerAPI.Util.PivotalFilterHelper"/> /// <remarks>See http://www.pivotaltracker.com/help/api?version=v3#get_iterations_with_limit_and_offset</remarks> /// <param name="user">The user to get the ApiToken from</param> /// <param name="projectId">The id of the project to get stories for</param> /// <param name="iterationGroup">The group of iterations to constrain the list to (use unknown or all to disregard this option)</param> /// <param name="limit">The maximum number of iterations to return</param> /// <param name="offset">The number of iterations to skip from the beginning of the result.</param> /// <returns>the stories grouped by iteration for the project</returns> public static IList <PivotalIteration> FetchIterations(PivotalUser user, int projectId, PivotalIterationGroup iterationGroup, Nullable <int> limit, Nullable <int> offset) { string groupSelector = ""; if (iterationGroup != PivotalIterationGroup.unknown && iterationGroup != PivotalIterationGroup.all) { groupSelector = "/" + iterationGroup.ToString(); } string url = String.Format("{0}/projects/{1}/iterations{2}?token={3}", PivotalService.BaseUrl, projectId.ToString(), groupSelector, user.ApiToken); if (limit.HasValue) { url += "&limit=" + limit.ToString(); } if (offset.HasValue) { url += "&offset=" + offset.ToString(); } XmlDocument xmlDoc = PivotalService.GetData(url); PivotalIterationList iterationList = SerializationHelper.DeserializeFromXmlDocument <PivotalIterationList>(xmlDoc); return(iterationList.Iterations); }
/// <summary> /// Adds a story to Pivotal /// </summary> /// <param name="user">The user to get the ApiToken from</param> /// <param name="projectId">The id of the project</param> /// <param name="story">The story to add</param> /// <param name="saveTasks">Controls whether any tasks associated with the story should also be saved.</param> /// <returns>The created story</returns> public static PivotalStory AddStory(PivotalUser user, int projectId, PivotalStory story, bool saveTasks) { string url = String.Format("{0}/projects/{1}/stories?token={2}", PivotalService.BaseUrl, projectId.ToString(), user.ApiToken); XmlDocument xml = SerializationHelper.SerializeToXmlDocument <PivotalStory>(story); string storyXml = PivotalService.CleanXmlForSubmission(xml, "//story", ExcludeNodesOnSubmit, true); XmlDocument response = PivotalService.SubmitData(url, storyXml, ServiceMethod.POST); PivotalStory savedStory = SerializationHelper.DeserializeFromXmlDocument <PivotalStory>(response); if (saveTasks) { foreach (PivotalTask task in story.Tasks) { if (task.TaskId.HasValue) { PivotalTask.UpdateTask(user, projectId, savedStory.Id.GetValueOrDefault(), task); } else { PivotalTask.AddTask(user, projectId, savedStory.Id.GetValueOrDefault(), task); } } } return(savedStory); }
/// <summary> /// Deletes a task from a story without requiring a task instance /// </summary> /// <param name="user">The user to get the ApiToken from</param> /// <param name="projectId">The project id</param> /// <param name="storyId">The story id</param> /// <param name="taskId">The task to delete</param> public static void DeleteTask(PivotalUser user, int projectId, int storyId, int taskId) { string url = String.Format("{0}/projects/{1}/story/{2}/task/{3}?token={4}", PivotalService.BaseUrl, projectId, storyId, taskId, user.ApiToken); XmlDocument response = PivotalService.SubmitData(url, null, ServiceMethod.DELETE); }