forked from xplodwild/go-redmine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathissue_priorities.go
41 lines (36 loc) · 863 Bytes
/
issue_priorities.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
package redmine
import (
"encoding/json"
"errors"
"strings"
)
type issuePrioritiesResult struct {
IssuePriorities []IssuePriority `json:"issue_priorities"`
}
type IssuePriority struct {
Id int `json:"id"`
Name string `json:"name"`
IsDefault bool `json:"is_default"`
}
func (c *Client) IssuePriorities() ([]IssuePriority, error) {
res, err := c.Get(c.endpoint + "/enumerations/issue_priorities.json?key=" + c.apikey + c.getPaginationClause())
if err != nil {
return nil, err
}
defer res.Body.Close()
decoder := json.NewDecoder(res.Body)
var r issuePrioritiesResult
if res.StatusCode != 200 {
var er ErrorsResult
err = decoder.Decode(&er)
if err == nil {
err = errors.New(strings.Join(er.Errors, "\n"))
}
} else {
err = decoder.Decode(&r)
}
if err != nil {
return nil, err
}
return r.IssuePriorities, nil
}