-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_version.go
76 lines (63 loc) · 1.92 KB
/
api_version.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 redmine
import (
"encoding/json"
"fmt"
)
type Version struct {
ID int `json:"id"`
Project IdName `json:"project"`
Name string `json:"name"`
Description string `json:"description"`
Status string `json:"status"`
DueDate *string `json:"due_date"`
Sharing string `json:"sharing"`
WikiPageTitle string `json:"wiki_page_title"`
EstimatedHours *float64 `json:"estimated_hours"`
SpentHours float64 `json:"spent_hours"`
CustomFields []CustomField `json:"custom_fields"`
CreatedOn string `json:"created_on"`
UpdatedOn string `json:"updated_on"`
}
func (c *Client) GetVersionByID(id int, opts ...ReqOption) (*Version, error) {
endpoint := fmt.Sprintf("/versions/%d.json", id)
o := reqOptions(opts...)
respBodyBytes, err := c.getRequest(endpoint, o.query)
if err != nil {
return nil, err
}
resp := struct {
Version Version `json:"version"`
}{}
if err := json.Unmarshal(respBodyBytes, &resp); err != nil {
return nil, fmt.Errorf("json unmarshal error: %v", err)
}
return &resp.Version, nil
}
func (c *Client) GetProjectVersions(project string, opts ...ReqOption) ([]*Version, error) {
endpoint := fmt.Sprintf("/projects/%s/versions.json", project)
if project == "" {
return nil, fmt.Errorf("`project` is empty")
}
o := reqOptions(opts...)
items := []*Version{}
filter := &listFilter{query: o.query}
respBodyBytes, err := c.getRequest(endpoint, filter.encode())
if err != nil {
return nil, err
}
resp := struct {
listResponseAttrs
Versions []*Version `json:"versions"`
}{}
if err := json.Unmarshal(respBodyBytes, &resp); err != nil {
return nil, fmt.Errorf("json unmarshal error: %v", err)
}
for _, item := range resp.Versions {
items = append(items, item)
if o.limit > 0 && len(items) >= o.limit {
goto end
}
}
end:
return items, nil
}