コード例 #1
0
        /// <summary>
        /// Creates a new project with the given name and description.
        /// </summary>
        /// <param name="projectName">The name of the project to create.</param>
        /// <param name="projectDescription">The description of the project to create.</param>
        /// <returns>The Project ID of the project that was created.</returns>
        public string CreateProject(string projectName, string projectDescription = Constants.DefaultCreatedProjectDescription)
        {
            // Get Site ID for the site we'll create a project in and use it to construct endpoint uri.
            var uri = Endpoints.GetCreateProjectUri(baseUri, GetSiteId());

            // Construct payload.
            tsRequest requestPayload = new tsRequest
            {
                Item = new projectType
                {
                    name        = projectName,
                    description = projectDescription
                }
            };

            // Issue request.
            var        errorMessage = String.Format("Failed to create project '{0}' on site '{1}'", projectName, siteName);
            ApiRequest request      = new ApiRequest(uri, HttpMethod.Post, GetAuthToken(), headers: null, body: requestPayload.SerializeBody());
            tsResponse response     = request.IssueRequest(errorMessage);

            // Return ID of created project.
            projectType createdProject = response.GetProject();

            return(createdProject.id);
        }
コード例 #2
0
        /// <summary>
        /// Retrieves the project details for a given project id.
        /// </summary>
        /// <param name="projectId">The ID of the project to query.</param>
        /// <returns>Project details associated with a given project id, or null if no match is found.</returns>
        public projectType GetProjectById(string projectId)
        {
            Uri uri = Endpoints.GetUpdateProjectUri(baseUri, GetSiteId(), projectId);

            // Construct payload.
            tsRequest requestPayload = new tsRequest {
                Item = new projectType()
            };

            // Issue request.
            var        errorMessage = String.Format("Failed to retrieve project details for project '{0}' in site '{1}'", projectId, siteName);
            ApiRequest request      = new ApiRequest(uri, HttpMethod.Put, GetAuthToken(), headers: null, body: requestPayload.SerializeBody());
            tsResponse response     = request.IssueRequest(errorMessage);

            return(response.GetProject());
        }