-
Notifications
You must be signed in to change notification settings - Fork 42
/
section.go
76 lines (66 loc) · 2.49 KB
/
section.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
72
73
74
75
76
package testrail
import "strconv"
// Section represents a Test Suite Section
type Section struct {
Depth int `json:"depth"`
Description string `json:"description"`
DisplayOrder int `json:"display_order"`
ID int `json:"id"`
ParentID int `json:"parent_id"`
Name string `json:"name"`
SuiteID int `json:"suite_id"`
}
// SendableSection represents a Test Suite Section
// that can be created via the api
type SendableSection struct {
Description string `json:"description,omitempty"`
SuiteID int `json:"suite_id,omitempty"`
ParentID int `json:"parent_id,omitempty"`
Name string `json:"name"`
}
// UpdatableSection represents a Test Suite Section
// that can be updated via the api
type UpdatableSection struct {
Description string `json:"description,omitempty"`
Name string `json:"name,omitempty"`
}
// GetSection returns the section sectionID
func (c *Client) GetSection(sectionID int) (Section, error) {
returnSection := Section{}
err := c.sendRequest("GET", "get_section/"+strconv.Itoa(sectionID), nil, &returnSection)
return returnSection, err
}
// GetSections returns the list of sections of projectID
// present in suite suiteID, if specified
func (c *Client) GetSections(projectID int, suiteID ...int) ([]Section, error) {
returnSection := struct {
Sections []Section `json:"section"`
}{}
uri := "get_sections/" + strconv.Itoa(projectID)
if len(suiteID) > 0 {
uri = uri + "&suite_id=" + strconv.Itoa(suiteID[0])
}
var err error
if c.useBetaApi {
err = c.sendRequestBeta("GET", uri, nil, &returnSection, "sections")
} else {
err = c.sendRequest("GET", uri, nil, &returnSection)
}
return returnSection.Sections, err
}
// AddSection creates a new section on projectID and returns it
func (c *Client) AddSection(projectID int, newSection SendableSection) (Section, error) {
createdSection := Section{}
err := c.sendRequest("POST", "add_section/"+strconv.Itoa(projectID), newSection, &createdSection)
return createdSection, err
}
// UpdateSection updates the section sectionID and returns it
func (c *Client) UpdateSection(sectionID int, update UpdatableSection) (Section, error) {
updatedSection := Section{}
err := c.sendRequest("POST", "update_section/"+strconv.Itoa(sectionID), update, &updatedSection)
return updatedSection, err
}
// DeleteSection deletes the section sectionID
func (c *Client) DeleteSection(sectionID int) error {
return c.sendRequest("POST", "delete_section/"+strconv.Itoa(sectionID), nil, nil)
}