-
Notifications
You must be signed in to change notification settings - Fork 0
/
activity.go
116 lines (99 loc) · 3.04 KB
/
activity.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package backlog
import (
"encoding/json"
"path"
"strconv"
)
func getActivityList(get clientGet, spath string, options ...*QueryOption) ([]*Activity, error) {
validOptions := []queryType{queryActivityTypeIDs, queryMinID, queryMaxID, queryCount, queryOrder}
for _, option := range options {
if err := option.validate(validOptions); err != nil {
return nil, err
}
}
query := NewQueryParams()
for _, option := range options {
if err := option.set(query); err != nil {
return nil, err
}
}
resp, err := get(spath, query)
if err != nil {
return nil, err
}
defer resp.Body.Close()
v := []*Activity{}
if err := json.NewDecoder(resp.Body).Decode(&v); err != nil {
return nil, err
}
return v, nil
}
// ProjectActivityService has methods for activitys of the project.
type ProjectActivityService struct {
method *method
Option *ActivityOptionService
}
// List returns a list of activities in the project.
//
// This method can specify the options returned by methods in "*Client.Project.Activity.Option".
//
// Use the following methods:
// WithQueryActivityTypeIDs
// WithQueryMinID
// WithQueryMaxID
// WithQueryCount
// WithQueryOrder
//
// Backlog API docs: https://developer.nulab.com/docs/backlog/api/2/get-project-recent-updates
func (s *ProjectActivityService) List(projectIDOrKey string, options ...*QueryOption) ([]*Activity, error) {
if err := validateProjectIDOrKey(projectIDOrKey); err != nil {
return nil, err
}
spath := path.Join("projects", projectIDOrKey, "activities")
return getActivityList(s.method.Get, spath, options...)
}
// SpaceActivityService has methods for activitys in your space.
type SpaceActivityService struct {
method *method
Option *ActivityOptionService
}
// List returns a list of activities in your space.
//
// This method can specify the options returned by methods in "*Client.Space.Activity.Option".
//
// Use the following methods:
// WithQueryActivityTypeIDs
// WithQueryMinID
// WithQueryMaxID
// WithQueryCount
// WithQueryOrder
//
// Backlog API docs: https://developer.nulab.com/docs/backlog/api/2/get-recent-updates
func (s *SpaceActivityService) List(options ...*QueryOption) ([]*Activity, error) {
return getActivityList(s.method.Get, "space/activities", options...)
}
// UserActivityService has methods for user activitys.
type UserActivityService struct {
method *method
Option *ActivityOptionService
}
// List returns a list of user activities.
//
// This method can specify the options returned by methods in "*Client.User.Activity.Option".
//
// Use the following methods:
// WithQueryActivityTypeIDs
// WithQueryMinID
// WithQueryMaxID
// WithQueryCount
// WithQueryOrder
//
// Backlog API docs: https://developer.nulab.com/docs/backlog/api/2/get-user-recent-updates
func (s *UserActivityService) List(userID int, options ...*QueryOption) ([]*Activity, error) {
uID := UserID(userID)
if err := uID.validate(); err != nil {
return nil, err
}
spath := path.Join("users", strconv.Itoa(userID), "activities")
return getActivityList(s.method.Get, spath, options...)
}