forked from educlos/testrail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject.go
71 lines (61 loc) · 2.26 KB
/
project.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package testrail
import (
"fmt"
"strconv"
)
// Project represents a Project
type Project struct {
Announcement string `json:"announcement"`
CompletedOn int `json:"completed_on"`
ID int `json:"id"`
IsCompleted bool `json:"is_completed"`
Name string `json:"name"`
ShowAnnouncement bool `json:"show_announcement"`
URL string `json:"url"`
}
// SendableProject represents a Project
// that can be created or updated via the ap
type SendableProject struct {
Name string `json:"name"`
Announcement string `json:"announcement,omitempty"`
ShowAnnouncement bool `json:"show_announcement,omitempty"`
SuiteMode int `json:"suite_mode,omitempty"`
}
// GetProject returns the existing project projectID
func (c *Client) GetProject(projectID int) (Project, error) {
returnProject := Project{}
err := c.sendRequest("GET", "get_project/"+strconv.Itoa(projectID), nil, &returnProject)
return returnProject, err
}
// GetProjects returns a list available projects
// can be filtered by completed status of the project
func (c *Client) GetProjects(isCompleted ...bool) ([]Project, error) {
uri := "get_projects"
if len(isCompleted) > 0 {
uri = uri + "&is_completed=" + btoitos(isCompleted[0])
}
returnProjects := []Project{}
err := c.sendRequest("GET", uri, nil, &returnProjects)
return returnProjects, err
}
// AddProject creates a new project and return its
func (c *Client) AddProject(newProject SendableProject) (Project, error) {
createdProject := Project{}
err := c.sendRequest("POST", "add_project", newProject, &createdProject)
return createdProject, err
}
// UpdateProject updates the existing project projectID and returns it
func (c *Client) UpdateProject(projectID int, updates SendableProject, isCompleted ...bool) (Project, error) {
updatedProject := Project{}
uri := "update_project/" + strconv.Itoa(projectID)
if len(isCompleted) > 0 {
uri = uri + "&is_completed=" + btoitos(isCompleted[0])
}
fmt.Println(uri)
err := c.sendRequest("POST", uri, updates, &updatedProject)
return updatedProject, err
}
// DeleteProject deletes the project projectID
func (c *Client) DeleteProject(projectID int) error {
return c.sendRequest("POST", "delete_project/"+strconv.Itoa(projectID), nil, nil)
}