-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
wiki.go
379 lines (315 loc) · 11 KB
/
wiki.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
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
package backlog
import (
"context"
"fmt"
"io"
)
// Wiki : wiki
type Wiki struct {
ID *int `json:"id,omitempty"`
ProjectID *int `json:"projectId,omitempty"`
Name *string `json:"name,omitempty"`
Content *string `json:"content,omitempty"`
Tags []*Tag `json:"tags,omitempty"`
Attachments []*Attachment `json:"attachments,omitempty"`
SharedFiles []*SharedFile `json:"sharedFiles,omitempty"`
Stars []*Star `json:"stars,omitempty"`
CreatedUser *User `json:"createdUser,omitempty"`
Created *Timestamp `json:"created,omitempty"`
UpdatedUser *User `json:"updatedUser,omitempty"`
Updated *Timestamp `json:"updated,omitempty"`
}
// Tag : tag
type Tag struct {
ID *int `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
}
// Attachment : attachment of wiki
type Attachment struct {
ID *int `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
Size *int `json:"size,omitempty"`
CreatedUser *User `json:"createdUser,omitempty"`
Created *Timestamp `json:"created,omitempty"`
}
// SharedFile : shared file of wiki
type SharedFile struct {
ID *int `json:"id,omitempty"`
Type *string `json:"type,omitempty"`
Dir *string `json:"dir,omitempty"`
Name *string `json:"name,omitempty"`
Size *int `json:"size,omitempty"`
CreatedUser *User `json:"createdUser,omitempty"`
Created *Timestamp `json:"created,omitempty"`
UpdatedUser *User `json:"updatedUser,omitempty"`
Updated *Timestamp `json:"updated,omitempty"`
}
// Star : star of wiki
type Star struct {
ID *int `json:"id,omitempty"`
Comment *string `json:"comment,omitempty"`
URL *string `json:"url,omitempty"`
Title *string `json:"title,omitempty"`
Presenter *User `json:"presenter,omitempty"`
Created *Timestamp `json:"created,omitempty"`
}
// Page : wiki page information
type Page struct {
Count *int `json:"count,omitempty"`
}
// RecentlyViewedWiki : recently viewed wiki
type RecentlyViewedWiki struct {
Page *Wiki `json:"page"`
Updated *Timestamp `json:"updated"`
}
// GetMyRecentlyViewedWikis returns the list of wikis I recently viewed
func (c *Client) GetMyRecentlyViewedWikis(opts *GetMyRecentlyViewedWikisOptions) ([]*RecentlyViewedWiki, error) {
return c.GetMyRecentlyViewedWikisContext(context.Background(), opts)
}
// GetMyRecentlyViewedWikisContext returns the list of wikis I recently viewed with context
func (c *Client) GetMyRecentlyViewedWikisContext(ctx context.Context, opts *GetMyRecentlyViewedWikisOptions) ([]*RecentlyViewedWiki, error) {
u, err := c.AddOptions("/api/v2/users/myself/recentlyViewedWikis", opts)
if err != nil {
return nil, err
}
req, err := c.NewRequest("GET", u, nil)
if err != nil {
return nil, err
}
var recentlyViewedWikis []*RecentlyViewedWiki
if err := c.Do(ctx, req, &recentlyViewedWikis); err != nil {
return nil, err
}
return recentlyViewedWikis, nil
}
// GetWikis returns the list of wikis
func (c *Client) GetWikis(opts *GetWikisOptions) ([]*Wiki, error) {
return c.GetWikisContext(context.Background(), opts)
}
// GetWikisContext returns the list of wikis
func (c *Client) GetWikisContext(ctx context.Context, opts *GetWikisOptions) ([]*Wiki, error) {
u, err := c.AddOptions("/api/v2/wikis", opts)
if err != nil {
return nil, err
}
req, err := c.NewRequest("GET", u, nil)
if err != nil {
return nil, err
}
wikis := []*Wiki{}
if err := c.Do(ctx, req, &wikis); err != nil {
return nil, err
}
return wikis, nil
}
// GetWikiCount returns the number of wikis
func (c *Client) GetWikiCount(opts *GetWikiCountOptions) (int, error) {
return c.GetWikiCountContext(context.Background(), opts)
}
// GetWikiCountContext returns the number of wikis
func (c *Client) GetWikiCountContext(ctx context.Context, opts *GetWikiCountOptions) (int, error) {
u, err := c.AddOptions("/api/v2/wikis/count", opts)
if err != nil {
return 0, err
}
req, err := c.NewRequest("GET", u, nil)
if err != nil {
return 0, err
}
page := new(Page)
if err := c.Do(ctx, req, &page); err != nil {
return 0, err
}
return *page.Count, nil
}
// GetWikiTags returns the tags of wikis
func (c *Client) GetWikiTags(opts *GetWikiTagsOptions) ([]*Tag, error) {
return c.GetWikiTagsContext(context.Background(), opts)
}
// GetWikiTagsContext returns the tags of wikis
func (c *Client) GetWikiTagsContext(ctx context.Context, opts *GetWikiTagsOptions) ([]*Tag, error) {
u, err := c.AddOptions("/api/v2/wikis/tags", opts)
if err != nil {
return nil, err
}
req, err := c.NewRequest("GET", u, nil)
if err != nil {
return nil, err
}
tags := []*Tag{}
if err := c.Do(ctx, req, &tags); err != nil {
return nil, err
}
return tags, nil
}
// GetWiki returns wiki by id
func (c *Client) GetWiki(wikiID int) (*Wiki, error) {
return c.GetWikiContext(context.Background(), wikiID)
}
// GetWikiContext returns wiki by id
func (c *Client) GetWikiContext(ctx context.Context, wikiID int) (*Wiki, error) {
u := fmt.Sprintf("/api/v2/wikis/%v", wikiID)
req, err := c.NewRequest("GET", u, nil)
if err != nil {
return nil, err
}
wiki := new(Wiki)
if err := c.Do(ctx, req, &wiki); err != nil {
return nil, err
}
return wiki, nil
}
// CreateWiki creates a wiki
func (c *Client) CreateWiki(input *CreateWikiInput) (*Wiki, error) {
return c.CreateWikiContext(context.Background(), input)
}
// CreateWikiContext creates a wiki with Context
func (c *Client) CreateWikiContext(ctx context.Context, input *CreateWikiInput) (*Wiki, error) {
u := "/api/v2/wikis"
req, err := c.NewRequest("POST", u, input)
if err != nil {
return nil, err
}
wiki := new(Wiki)
if err := c.Do(ctx, req, &wiki); err != nil {
return nil, err
}
return wiki, nil
}
// UpdateWiki updates a wiki
func (c *Client) UpdateWiki(wikiID int, input *UpdateWikiInput) (*Wiki, error) {
return c.UpdateWikiContext(context.Background(), wikiID, input)
}
// UpdateWikiContext updates a wiki with Context
func (c *Client) UpdateWikiContext(ctx context.Context, wikiID int, input *UpdateWikiInput) (*Wiki, error) {
u := fmt.Sprintf("/api/v2/wikis/%v", wikiID)
req, err := c.NewRequest("PATCH", u, input)
if err != nil {
return nil, err
}
wiki := new(Wiki)
if err := c.Do(ctx, req, &wiki); err != nil {
return nil, err
}
return wiki, nil
}
// DeleteWiki deletes a wiki
func (c *Client) DeleteWiki(wikiID int) (*Wiki, error) {
return c.DeleteWikiContext(context.Background(), wikiID)
}
// DeleteWikiContext deletes a wiki with Context
func (c *Client) DeleteWikiContext(ctx context.Context, wikiID int) (*Wiki, error) {
u := fmt.Sprintf("/api/v2/wikis/%v", wikiID)
req, err := c.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
wiki := new(Wiki)
if err := c.Do(ctx, req, &wiki); err != nil {
return nil, err
}
return wiki, nil
}
// GetWikiAttachments returns attachements of a wiki
func (c *Client) GetWikiAttachments(wikiID int) ([]*Attachment, error) {
return c.GetWikiAttachmentsContext(context.Background(), wikiID)
}
// GetWikiAttachmentsContext returns attachements of a wiki with context
func (c *Client) GetWikiAttachmentsContext(ctx context.Context, wikiID int) ([]*Attachment, error) {
u := fmt.Sprintf("/api/v2/wikis/%v/attachments", wikiID)
req, err := c.NewRequest("GET", u, nil)
if err != nil {
return nil, err
}
attachments := []*Attachment{}
if err := c.Do(ctx, req, &attachments); err != nil {
return nil, err
}
return attachments, nil
}
// GetWikiAttachmentContent writes the content to writer
func (c *Client) GetWikiAttachmentContent(wikiID, attachmentID int, w io.Writer) error {
return c.GetWikiAttachmentContentContext(context.Background(), wikiID, attachmentID, w)
}
// GetWikiAttachmentContentContext writes the content to writer
func (c *Client) GetWikiAttachmentContentContext(ctx context.Context, wikiID, attachmentID int, w io.Writer) error {
u := fmt.Sprintf("/api/v2/wikis/%v/attachments/%v", wikiID, attachmentID)
req, err := c.NewRequest("GET", u, nil)
if err != nil {
return err
}
if err := c.Do(ctx, req, w); err != nil {
return err
}
return nil
}
// AddAttachmentToWiki adds attachments to a wiki
func (c *Client) AddAttachmentToWiki(wikiID int, input *AddAttachmentToWikiInput) ([]*Attachment, error) {
return c.AddAttachmentToWikiContext(context.Background(), wikiID, input)
}
// AddAttachmentToWikiContext adds attachments to a wiki with context
func (c *Client) AddAttachmentToWikiContext(ctx context.Context, wikiID int, input *AddAttachmentToWikiInput) ([]*Attachment, error) {
u := fmt.Sprintf("/api/v2/wikis/%v/attachments", wikiID)
req, err := c.NewRequest("POST", u, input)
if err != nil {
return nil, err
}
attachments := []*Attachment{}
if err := c.Do(ctx, req, &attachments); err != nil {
return nil, err
}
return attachments, nil
}
// DeleteAttachmentInWiki deletes a attachment in a wiki
func (c *Client) DeleteAttachmentInWiki(wikiID, attachmentID int) (*Attachment, error) {
return c.DeleteAttachmentInWikiContext(context.Background(), wikiID, attachmentID)
}
// DeleteAttachmentInWikiContext deletes a attachment in a wiki with context
func (c *Client) DeleteAttachmentInWikiContext(ctx context.Context, wikiID, attachmentID int) (*Attachment, error) {
u := fmt.Sprintf("/api/v2/wikis/%v/attachments/%v", wikiID, attachmentID)
req, err := c.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
attachment := new(Attachment)
if err := c.Do(ctx, req, &attachment); err != nil {
return nil, err
}
return attachment, nil
}
// GetMyRecentlyViewedWikisOptions specifies parameters to the GetMyRecentlyViewedWikis method.
type GetMyRecentlyViewedWikisOptions struct {
Order Order `url:"order,omitempty"`
Offset *int `url:"offset,omitempty"`
Count *int `url:"count,omitempty"`
}
// GetWikisOptions specifies parameters to the GetWikis method.
type GetWikisOptions struct {
ProjectIDOrKey interface{} `url:"projectIdOrKey"`
Keyword *string `url:"keyword,omitempty"`
}
// GetWikiCountOptions specifies parameters to the GetWikiCount method.
type GetWikiCountOptions struct {
ProjectIDOrKey interface{} `url:"projectIdOrKey,omitempty"`
}
// GetWikiTagsOptions specifies parameters to the GetWikiTags method.
type GetWikiTagsOptions struct {
ProjectIDOrKey interface{} `url:"projectIdOrKey,omitempty"`
}
// CreateWikiInput contains all the parameters necessary (including the optional ones) for a CreateWiki() request.
type CreateWikiInput struct {
ProjectID *int `json:"projectId"`
Name *string `json:"name"`
Content *string `json:"content"`
MailNotify *bool `json:"mailNotify,omitempty"`
}
// UpdateWikiInput contains all the parameters necessary (including the optional ones) for a UpdateWiki() request.
type UpdateWikiInput struct {
Name *string `json:"name"`
Content *string `json:"content"`
MailNotify *bool `json:"mailNotify,omitempty"`
}
// AddAttachmentToWikiInput contains all the parameters necessary (including the optional ones) for a AddAttachmentToWiki() request.
type AddAttachmentToWikiInput struct {
AttachmentIDs []int `json:"attachmentId"`
}