/
videos_comments.go
181 lines (148 loc) · 4.66 KB
/
videos_comments.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
package vimeo
import "fmt"
type dataListComment struct {
Data []*Comment `json:"data,omitempty"`
pagination
}
// Comment represents a comment.
type Comment struct {
URI string `json:"uri,omitempty"`
Type string `json:"type,omitempty"`
Text string `json:"text,omitempty"`
CreatedOn string `json:"created_on,omitempty"`
User *User `json:"user,omitempty"`
ResourceKey string `json:"resource_key,omitempty"`
}
// ListCommentOptions specifies the optional parameters to the
// ListCommentOptions.VideoListComment method.
type ListCommentOptions struct {
Query string `url:"query,omitempty"`
Direction string `url:"direction,omitempty"`
ListOptions
}
// CommentRequest represents a request to create/edit an comment.
type CommentRequest struct {
Text string `json:"text,omitempty"`
}
// ListRepliesOptions specifies the optional parameters to the
// ListRepliesOptions.ListReplies method.
type ListRepliesOptions struct {
ListOptions
}
// ListComment lists the comments.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/videos/%7Bvideo_id%7D/comments
func (s *VideosService) ListComment(vid int, opt *ListCommentOptions) ([]*Comment, *Response, error) {
u := fmt.Sprintf("videos/%d/comments", vid)
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
}
comments := &dataListComment{}
resp, err := s.client.Do(req, comments)
if err != nil {
return nil, resp, err
}
resp.setPaging(comments)
return comments.Data, resp, err
}
// AddComment add comment.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/videos/%7Bvideo_id%7D/comments
func (s *VideosService) AddComment(vid int, r *CommentRequest) (*Comment, *Response, error) {
u := fmt.Sprintf("videos/%d/comments", vid)
req, err := s.client.NewRequest("POST", u, r)
if err != nil {
return nil, nil, err
}
comment := &Comment{}
resp, err := s.client.Do(req, comment)
if err != nil {
return nil, resp, err
}
return comment, resp, nil
}
// GetComment get specific comment by ID.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/videos/%7Bvideo_id%7D/comments/%7Bcomment_id%7D
func (s *VideosService) GetComment(vid int, cid int) (*Comment, *Response, error) {
u := fmt.Sprintf("videos/%d/comments/%d", vid, cid)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
comment := &Comment{}
resp, err := s.client.Do(req, comment)
if err != nil {
return nil, resp, err
}
return comment, resp, err
}
// EditComment edit specific comment by ID.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/videos/%7Bvideo_id%7D/comments/%7Bcomment_id%7D
func (s *VideosService) EditComment(vid int, cid int, r *CommentRequest) (*Comment, *Response, error) {
u := fmt.Sprintf("videos/%d/comments/%d", vid, cid)
req, err := s.client.NewRequest("PATCH", u, r)
if err != nil {
return nil, nil, err
}
comment := &Comment{}
resp, err := s.client.Do(req, comment)
if err != nil {
return nil, resp, err
}
return comment, resp, nil
}
// DeleteComment delete specific comment by name.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/videos/%7Bvideo_id%7D/comments/%7Bcomment_id%7D
func (s *VideosService) DeleteComment(vid int, cid int) (*Response, error) {
u := fmt.Sprintf("videos/%d/comments/%d", vid, cid)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}
// ListReplies lists the comment replies.
//
// https://developer.vimeo.com/api/playground/videos/%7Bvideo_id%7D/comments/%7Bcomment_id%7D/replies
func (s *VideosService) ListReplies(vid int, cid int, opt *ListRepliesOptions) ([]*Comment, *Response, error) {
u := fmt.Sprintf("videos/%d/comments/%d/replies", vid, cid)
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
}
replies := &dataListComment{}
resp, err := s.client.Do(req, replies)
if err != nil {
return nil, resp, err
}
resp.setPaging(replies)
return replies.Data, resp, err
}
// AddReplies add replies.
//
// https://developer.vimeo.com/api/playground/videos/%7Bvideo_id%7D/comments/%7Bcomment_id%7D/replies
func (s *VideosService) AddReplies(vid int, cid int, r *CommentRequest) (*Comment, *Response, error) {
u := fmt.Sprintf("videos/%d/comments/%d/replies", vid, cid)
req, err := s.client.NewRequest("POST", u, r)
if err != nil {
return nil, nil, err
}
replies := &Comment{}
resp, err := s.client.Do(req, replies)
if err != nil {
return nil, resp, err
}
return replies, resp, nil
}