/
users.go
706 lines (588 loc) · 18.6 KB
/
users.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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
package vimeo
import (
"fmt"
"os"
"time"
)
// UsersService handles communication with the users related
// methods of the Vimeo API.
//
// Vimeo API docs: https://developer.vimeo.com/api/endpoints/users
type UsersService service
type dataListUser struct {
Data []*User `json:"data"`
pagination
}
// WebSite represents a web site.
type WebSite struct {
Name string `json:"name,omitempty"`
Link string `json:"link,omitempty"`
Description string `json:"description,omitempty"`
}
// User represents a user.
type User struct {
URI string `json:"uri,omitempty"`
Name string `json:"name,omitempty"`
Link string `json:"link,omitempty"`
Location string `json:"location,omitempty"`
Bio string `json:"bio,omitempty"`
CreatedTime time.Time `json:"created_time,omitempty"`
Account string `json:"account,omitempty"`
Pictures *Pictures `json:"pictures,omitempty"`
WebSites []*WebSite `json:"websites,omitempty"`
ContentFilter []string `json:"content_filter,omitempty"`
ResourceKey string `json:"resource_key,omitempty"`
}
// ListUserOptions specifies the optional parameters to the
// ListUser method.
type ListUserOptions struct {
Query string `url:"query,omitempty"`
Filter string `url:"filter,omitempty"`
ListOptions
}
// UserRequest represents a request to create/edit an user.
type UserRequest struct {
Name string `json:"name,omitempty"`
Location string `json:"location,omitempty"`
Bio string `json:"bio,omitempty"`
}
func listUser(c *Client, url string, opt *ListUserOptions) ([]*User, *Response, error) {
u, err := addOptions(url, opt)
if err != nil {
return nil, nil, err
}
req, err := c.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
users := &dataListUser{}
resp, err := c.Do(req, users)
if err != nil {
return nil, resp, err
}
resp.setPaging(users)
return users.Data, resp, err
}
// Search users.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/channels/%7Bchannel_id%7D/users
func (s *UsersService) Search(opt *ListUserOptions) ([]*User, *Response, error) {
users, resp, err := listUser(s.client, "users", opt)
return users, resp, err
}
// Get show one user.
// Passing the empty string will authenticated user.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/users/%7Buser_id%7D
func (s *UsersService) Get(uid string) (*User, *Response, error) {
var u string
if uid == "" {
u = "me"
} else {
u = fmt.Sprintf("users/%s", uid)
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
user := &User{}
resp, err := s.client.Do(req, user)
if err != nil {
return nil, resp, err
}
return user, resp, err
}
// Edit one user.
// Passing the empty string will edit authenticated user.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/users/%7Buser_id%7D
func (s *UsersService) Edit(uid string, r *UserRequest) (*User, *Response, error) {
var u string
if uid == "" {
u = "me"
} else {
u = fmt.Sprintf("users/%s", uid)
}
req, err := s.client.NewRequest("PATCH", u, r)
if err != nil {
return nil, nil, err
}
user := &User{}
resp, err := s.client.Do(req, user)
if err != nil {
return nil, resp, err
}
return user, resp, nil
}
// ListAppearance all videos a user is credited in.
// Passing the empty string will edit authenticated user.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/users/%7Buser_id%7D/appearances
func (s *UsersService) ListAppearance(uid string, opt *ListVideoOptions) ([]*Video, *Response, error) {
var u string
if uid == "" {
u = "me/appearances"
} else {
u = fmt.Sprintf("users/%s/appearances", uid)
}
videos, resp, err := listVideo(s.client, u, opt)
return videos, resp, err
}
// ListCategory list the subscribed category for user.
// Passing the empty string will edit authenticated user.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/users/%7Buser_id%7D/categories
func (s *UsersService) ListCategory(uid string, opt *ListCategoryOptions) ([]*Category, *Response, error) {
var u string
if uid == "" {
u = "me/categories"
} else {
u = fmt.Sprintf("users/%s/categories", uid)
}
categories, resp, err := listCategory(s.client, u, opt)
return categories, resp, err
}
// SubscribeCategory subscribe category user.
// Passing the empty string will edit authenticated user.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/users/%7Buser_id%7D/categories/%7Bcategory%7D
func (s *UsersService) SubscribeCategory(uid string, cat string) (*Response, error) {
var u string
if uid == "" {
u = fmt.Sprintf("me/categories/%s", cat)
} else {
u = fmt.Sprintf("users/%s/categories/%s", uid, cat)
}
req, err := s.client.NewRequest("PUT", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// UnsubscribeCategory unsubscribe category current user.
// Passing the empty string will edit authenticated user.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/users/%7Buser_id%7D/categories/%7Bcategory%7D
func (s *UsersService) UnsubscribeCategory(uid string, cat string) (*Response, error) {
var u string
if uid == "" {
u = fmt.Sprintf("me/categories/%s", cat)
} else {
u = fmt.Sprintf("users/%s/categories/%s", uid, cat)
}
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// ListChannel list the subscribed channel for user.
// Passing the empty string will edit authenticated user.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/users/%7Buser_id%7D/channels
func (s *UsersService) ListChannel(uid string, opt *ListChannelOptions) ([]*Channel, *Response, error) {
var u string
if uid == "" {
u = "me/channels"
} else {
u = fmt.Sprintf("users/%s/channels", uid)
}
categories, resp, err := listChannel(s.client, u, opt)
return categories, resp, err
}
// SubscribeChannel subscribe channel user.
// Passing the empty string will edit authenticated user.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/users/%7Buser_id%7D/channels/%7Bchannel_id%7D
func (s *UsersService) SubscribeChannel(uid string, ch string) (*Response, error) {
var u string
if uid == "" {
u = fmt.Sprintf("me/channels/%s", ch)
} else {
u = fmt.Sprintf("users/%s/channels/%s", uid, ch)
}
req, err := s.client.NewRequest("PUT", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// UnsubscribeChannel unsubscribe channel user.
// Passing the empty string will edit authenticated user.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/users/%7Buser_id%7D/channels/%7Bchannel_id%7D
func (s *UsersService) UnsubscribeChannel(uid string, ch string) (*Response, error) {
var u string
if uid == "" {
u = fmt.Sprintf("me/channels/%s", ch)
} else {
u = fmt.Sprintf("users/%s/channels/%s", uid, ch)
}
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
type dataListFeed struct {
Data []*Feed `json:"data"`
pagination
}
// Feed represents a feed.
type Feed struct {
URI string `json:"uri,omitempty"`
Clip *Video `json:"clip,omitempty"`
}
// ListFeedOptions specifies the optional parameters to the
// Feed method.
type ListFeedOptions struct {
ListOptions
}
// Feed lists the feed for an user.
// Passing the empty string will edit authenticated user.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/users/%7Buser_id%7D/feed
func (s *UsersService) Feed(uid string, opt *ListFeedOptions) ([]*Feed, *Response, error) {
var u string
if uid == "" {
u = "me/feed"
} else {
u = fmt.Sprintf("users/%s/feed", uid)
}
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
feed := &dataListFeed{}
resp, err := s.client.Do(req, feed)
if err != nil {
return nil, resp, err
}
resp.setPaging(feed)
return feed.Data, resp, err
}
// ListFollower lists the followers.
// Passing the empty string will edit authenticated user.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/users/%7Buser_id%7D/followers
func (s *UsersService) ListFollower(uid string, opt *ListUserOptions) ([]*User, *Response, error) {
var u string
if uid == "" {
u = "me/followers"
} else {
u = fmt.Sprintf("users/%s/followers", uid)
}
users, resp, err := listUser(s.client, u, opt)
return users, resp, err
}
// ListFollowed lists the following.
// Passing the empty string will edit authenticated user.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/users/%7Buser_id%7D/following
func (s *UsersService) ListFollowed(uid string, opt *ListUserOptions) ([]*User, *Response, error) {
var u string
if uid == "" {
u = "me/following"
} else {
u = fmt.Sprintf("users/%s/following", uid)
}
users, resp, err := listUser(s.client, u, opt)
return users, resp, err
}
// FollowUser follow a user.
// Passing the empty string will edit authenticated user.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/users/%7Buser_id%7D/following/%7Bfollow_user_id%7D
func (s *UsersService) FollowUser(uid string, fid string) (*Response, error) {
var u string
if uid == "" {
u = fmt.Sprintf("me/following/%s", fid)
} else {
u = fmt.Sprintf("users/%s/following/%s", uid, fid)
}
req, err := s.client.NewRequest("PUT", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// UnfollowUser unfollow a user.
// Passing the empty string will edit authenticated user.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/users/%7Buser_id%7D/following/%7Bfollow_user_id%7D
func (s *UsersService) UnfollowUser(uid string, fid string) (*Response, error) {
var u string
if uid == "" {
u = fmt.Sprintf("me/following/%s", fid)
} else {
u = fmt.Sprintf("users/%s/following/%s", uid, fid)
}
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// ListGroup lists all joined groups.
// Passing the empty string will edit authenticated user.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/users/%7Buser_id%7D/groups
func (s *UsersService) ListGroup(uid string, opt *ListGroupOptions) ([]*Group, *Response, error) {
var u string
if uid == "" {
u = "me/groups"
} else {
u = fmt.Sprintf("users/%s/groups", uid)
}
groups, resp, err := listGroup(s.client, u, opt)
return groups, resp, err
}
// JoinGroup join user to group.
// Passing the empty string will edit authenticated user.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/users/%7Buser_id%7D/groups/%7Bgroup_id%7D
func (s *UsersService) JoinGroup(uid string, gid string) (*Response, error) {
var u string
if uid == "" {
u = fmt.Sprintf("me/groups/%s", gid)
} else {
u = fmt.Sprintf("users/%s/groups/%s", uid, gid)
}
req, err := s.client.NewRequest("PUT", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// LeaveGroup leaved user from group.
// Passing the empty string will edit authenticated user.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/users/%7Buser_id%7D/groups/%7Bgroup_id%7D
func (s *UsersService) LeaveGroup(uid string, gid string) (*Response, error) {
var u string
if uid == "" {
u = fmt.Sprintf("me/groups/%s", gid)
} else {
u = fmt.Sprintf("users/%s/groups/%s", uid, gid)
}
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// ListLikedVideo all liked videos.
// Passing the empty string will edit authenticated user.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/users/%7Buser_id%7D/likes
func (s *UsersService) ListLikedVideo(uid string, opt *ListVideoOptions) ([]*Video, *Response, error) {
var u string
if uid == "" {
u = "me/likes"
} else {
u = fmt.Sprintf("users/%s/likes", uid)
}
videos, resp, err := listVideo(s.client, u, opt)
return videos, resp, err
}
// LikeVideo like one video.
// Passing the empty string will edit authenticated user.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/users/%7Buser_id%7D/likes/%7Bvideo_id%7D
func (s *UsersService) LikeVideo(uid string, vid int) (*Response, error) {
var u string
if uid == "" {
u = fmt.Sprintf("me/likes/%d", vid)
} else {
u = fmt.Sprintf("users/%s/likes/%d", uid, vid)
}
req, err := s.client.NewRequest("PUT", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// UnlikeVideo unlike one video.
// Passing the empty string will edit authenticated user.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/users/%7Buser_id%7D/likes/%7Bvideo_id%7D
func (s *UsersService) UnlikeVideo(uid string, vid int) (*Response, error) {
var u string
if uid == "" {
u = fmt.Sprintf("me/likes/%d", vid)
} else {
u = fmt.Sprintf("users/%s/likes/%d", uid, vid)
}
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// RemovePortrait removed specific a portrait.
// Passing the empty string will edit authenticated user.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/users/%7Buser_id%7D/pictures/%7Bportraitset_id%7D
func (s *UsersService) RemovePortrait(uid string, pid string) (*Response, error) {
var u string
if uid == "" {
u = fmt.Sprintf("me/pictures/%s", pid)
} else {
u = fmt.Sprintf("users/%s/pictures/%s", uid, pid)
}
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// ListVideo lists the video for user.
// Passing the empty string will edit authenticated user.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/users/%7Buser_id%7D/videos
func (s *UsersService) ListVideo(uid string, opt *ListVideoOptions) ([]*Video, *Response, error) {
var u string
if uid == "" {
u = "me/videos?fields=uri,name"
} else {
u = fmt.Sprintf("users/%s/videos", uid)
}
videos, resp, err := listVideo(s.client, u, opt)
return videos, resp, err
}
// GetVideo get specific video by video ID.
// Passing the empty string will edit authenticated user.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/users/%7Buser_id%7D/videos
func (s *UsersService) GetVideo(uid string, vid int) (*Video, *Response, error) {
var u string
if uid == "" {
u = fmt.Sprintf("me/videos/%d", vid)
} else {
u = fmt.Sprintf("users/%s/videos/%d", uid, vid)
}
video, resp, err := getVideo(s.client, u)
return video, resp, err
}
// UploadVideo upload video file.
// Passing the empty string will edit authenticated user.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/users/%7Buser_id%7D/videos
func (s *UsersService) UploadVideo(uid string, file *os.File) (*Video, *Response, error) {
var u string
if uid == "" {
u = "me/videos"
} else {
u = fmt.Sprintf("users/%s/videos", uid)
}
video, resp, err := uploadVideo(s.client, "POST", u, file)
return video, resp, err
}
// UploadVideo upload video by url.
// Passing the empty string will edit authenticated user.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/users/%7Buser_id%7D/videos
func (s *UsersService) UploadVideoByURL(uid string, videoURL string) (*Video, *Response, error) {
var u string
if uid == "" {
u = "me/videos"
} else {
u = fmt.Sprintf("users/%s/videos", uid)
}
video, resp, err := uploadVideoByURL(s.client, u, videoURL)
return video, resp, err
}
// WatchLaterListVideo lists the video.
// Passing the empty string will edit authenticated user.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/users/%7Buser_id%7D/watchlater
func (s *UsersService) WatchLaterListVideo(uid string, opt *ListVideoOptions) ([]*Video, *Response, error) {
var u string
if uid == "" {
u = "me/watchlater"
} else {
u = fmt.Sprintf("users/%s/watchlater", uid)
}
videos, resp, err := listVideo(s.client, u, opt)
return videos, resp, err
}
// WatchLaterGetVideo get specific video by video ID.
// Passing the empty string will edit authenticated user.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/users/%7Buser_id%7D/watchlater/%7Bvideo_id%7D
func (s *UsersService) WatchLaterGetVideo(uid string, vid int) (*Video, *Response, error) {
var u string
if uid == "" {
u = fmt.Sprintf("me/watchlater/%d", vid)
} else {
u = fmt.Sprintf("users/%s/watchlater/%d", uid, vid)
}
video, resp, err := getVideo(s.client, u)
return video, resp, err
}
// WatchLaterAddVideo add video to watch later list.
// Passing the empty string will edit authenticated user.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/users/%7Buser_id%7D/watchlater/%7Bvideo_id%7D
func (s *UsersService) WatchLaterAddVideo(uid string, vid int) (*Response, error) {
var u string
if uid == "" {
u = fmt.Sprintf("me/watchlater/%d", vid)
} else {
u = fmt.Sprintf("users/%s/watchlater/%d", uid, vid)
}
req, err := s.client.NewRequest("PUT", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// WatchLaterDeleteVideo delete video from watch later list.
// Passing the empty string will edit authenticated user.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/users/%7Buser_id%7D/watchlater/%7Bvideo_id%7D
func (s *UsersService) WatchLaterDeleteVideo(uid string, vid int) (*Response, error) {
var u string
if uid == "" {
u = fmt.Sprintf("me/watchlater/%d", vid)
} else {
u = fmt.Sprintf("users/%s/watchlater/%d", uid, vid)
}
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// WatchedListVideo lists the video.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/me/watched/videos
func (s *UsersService) WatchedListVideo(uid string, opt *ListVideoOptions) ([]*Video, *Response, error) {
videos, resp, err := listVideo(s.client, "me/watched/videos", opt)
return videos, resp, err
}
// ClearWatchedList delete all video from watch history.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/me/watchlater/%7Bvideo_id%7D
func (s *UsersService) ClearWatchedList(uid string) (*Response, error) {
req, err := s.client.NewRequest("DELETE", "me/watched/videos", nil)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// WatchedDeleteVideo delete specific video from watch history.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/me/watched/videos/%7Bvideo_id%7D
func (s *UsersService) WatchedDeleteVideo(uid string, vid int) (*Response, error) {
u := fmt.Sprintf("me/watched/videos/%d", vid)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}