-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathwatching.go
More file actions
196 lines (161 loc) · 5.85 KB
/
watching.go
File metadata and controls
196 lines (161 loc) · 5.85 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package backlog
import (
"context"
"fmt"
)
// Watching : -
type Watching struct {
ID *int `json:"id,omitempty"`
ResourceAlreadyRead *bool `json:"resourceAlreadyRead,omitempty"`
Note *string `json:"note,omitempty"`
Type *string `json:"type,omitempty"`
Issue *Issue `json:"issue,omitempty"`
LastContentUpdated *Timestamp `json:"lastContentUpdated,omitempty"`
Created *Timestamp `json:"created,omitempty"`
Updated *Timestamp `json:"updated,omitempty"`
}
// GetUserWatchings returns the list of user's watchings
func (c *Client) GetUserWatchings(userID int) ([]*Watching, error) {
return c.GetUserWatchingsContext(context.Background(), userID)
}
// GetUserWatchingsContext returns the list of user's watchings with context
func (c *Client) GetUserWatchingsContext(ctx context.Context, userID int) ([]*Watching, error) {
u := fmt.Sprintf("/api/v2/users/%v/watchings", userID)
req, err := c.NewRequest("GET", u, nil)
if err != nil {
return nil, err
}
var watchings []*Watching
if err := c.Do(ctx, req, &watchings); err != nil {
return nil, err
}
return watchings, nil
}
// GetUserWatchingsCount returns the count of user's watchings
func (c *Client) GetUserWatchingsCount(userID int, opts *GetUserWatchingsCountOptions) (int, error) {
return c.GetUserWatchingsCountContext(context.Background(), userID, opts)
}
// GetUserWatchingsCountContext returns the count of user's watchings with context
func (c *Client) GetUserWatchingsCountContext(ctx context.Context, userID int, opts *GetUserWatchingsCountOptions) (int, error) {
u := fmt.Sprintf("/api/v2/users/%v/watchings/count", userID)
u, err := c.AddOptions(u, opts)
if err != nil {
return 0, err
}
req, err := c.NewRequest("GET", u, nil)
if err != nil {
return 0, err
}
r := new(p)
if err := c.Do(ctx, req, &r); err != nil {
return 0, err
}
return r.Count, nil
}
// GetWatching returns a watching
func (c *Client) GetWatching(watchingID int) (*Watching, error) {
return c.GetWatchingContext(context.Background(), watchingID)
}
// GetWatchingContext returns a watching with context
func (c *Client) GetWatchingContext(ctx context.Context, watchingID int) (*Watching, error) {
u := fmt.Sprintf("/api/v2/watchings/%v", watchingID)
req, err := c.NewRequest("GET", u, nil)
if err != nil {
return nil, err
}
watching := new(Watching)
if err := c.Do(ctx, req, &watching); err != nil {
return nil, err
}
return watching, nil
}
// CreateWatching creates a watching
func (c *Client) CreateWatching(input *CreateWatchingInput) (*Watching, error) {
return c.CreateWatchingContext(context.Background(), input)
}
// CreateWatchingContext creates a watching with Context
func (c *Client) CreateWatchingContext(ctx context.Context, input *CreateWatchingInput) (*Watching, error) {
u := "/api/v2/watchings"
req, err := c.NewRequest("POST", u, input)
if err != nil {
return nil, err
}
watching := new(Watching)
if err := c.Do(ctx, req, &watching); err != nil {
return nil, err
}
return watching, nil
}
// UpdateWatching updates a watching
func (c *Client) UpdateWatching(watchingID int, input *UpdateWatchingInput) (*Watching, error) {
return c.UpdateWatchingContext(context.Background(), watchingID, input)
}
// UpdateWatchingContext updates a watching with Context
func (c *Client) UpdateWatchingContext(ctx context.Context, watchingID int, input *UpdateWatchingInput) (*Watching, error) {
u := fmt.Sprintf("/api/v2/watchings/%v", watchingID)
req, err := c.NewRequest("PATCH", u, input)
if err != nil {
return nil, err
}
watching := new(Watching)
if err := c.Do(ctx, req, &watching); err != nil {
return nil, err
}
return watching, nil
}
// DeleteWatching deletes a watching
func (c *Client) DeleteWatching(watchingID int) (*Watching, error) {
return c.DeleteWatchingContext(context.Background(), watchingID)
}
// DeleteWatchingContext deletes a watching with Context
func (c *Client) DeleteWatchingContext(ctx context.Context, watchingID int) (*Watching, error) {
u := fmt.Sprintf("/api/v2/watchings/%v", watchingID)
req, err := c.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
watching := new(Watching)
if err := c.Do(ctx, req, &watching); err != nil {
return nil, err
}
return watching, nil
}
// MarkAsReadWatching marks a watching as read
func (c *Client) MarkAsReadWatching(watchingID int) error {
return c.MarkAsReadWatchingContext(context.Background(), watchingID)
}
// MarkAsReadWatchingContext marks a watching as read with Context
func (c *Client) MarkAsReadWatchingContext(ctx context.Context, watchingID int) error {
u := fmt.Sprintf("/api/v2/watchings/%v/markAsRead", watchingID)
req, err := c.NewRequest("POST", u, nil)
if err != nil {
return err
}
if err := c.Do(ctx, req, nil); err != nil {
return err
}
return nil
}
// GetUserWatchingsOptions specifies parameters to the GetUserWatchings method.
type GetUserWatchingsOptions struct {
Order *Order `url:"order,omitempty"`
Sort *string `url:"sort,omitempty"`
Count *int `url:"count,omitempty"`
Offset *int `url:"offset,omitempty"`
ResourceAlreadyRead *bool `url:"resourceAlreadyRead,omitempty"`
IssueIDs []int `url:"issueId[],omitempty"`
}
// GetUserWatchingsCountOptions specifies parameters to the GetUserWatchingsCount method.
type GetUserWatchingsCountOptions struct {
ResourceAlreadyRead *bool `url:"resourceAlreadyRead,omitempty"`
AlreadyRead *bool `url:"alreadyRead,omitempty"`
}
// CreateWatchingInput specifies parameters to the CreateWatching method.
type CreateWatchingInput struct {
IssueIDOrKey *string `json:"issueIdOrKey"`
Note *string `json:"note,omitempty"`
}
// UpdateWatchingInput specifies parameters to the UpdateWatching method.
type UpdateWatchingInput struct {
Note *string `json:"note,omitempty"`
}