/
videos_credits.go
131 lines (108 loc) · 3.34 KB
/
videos_credits.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
package vimeo
import "fmt"
type dataListCredit struct {
Data []*Credit `json:"data,omitempty"`
pagination
}
// Credit represents a creadit.
type Credit struct {
URI string `json:"uri,omitempty"`
Name string `json:"name,omitempty"`
Role string `json:"role,omitempty"`
User *User `json:"user,omitempty"`
Video *Video `json:"user,omitempty"`
}
// ListCreditOptions specifies the optional parameters to the ListCredit method.
type ListCreditOptions struct {
Query string `url:"query,omitempty"`
Sort string `url:"sort,omitempty"`
Direction string `url:"direction,omitempty"`
ListOptions
}
// CreditRequest represents a request to create/edit an creadit.
type CreditRequest struct {
Role string `json:"role,omitempty"`
Name string `json:"name,omitempty"`
Email string `json:"email,omitempty"`
UserURI string `json:"user_uri,omitempty"`
}
// ListCredit lists the credits.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/videos/%7Bvideo_id%7D/credits
func (s *VideosService) ListCredit(vid int, opt *ListCreditOptions) ([]*Credit, *Response, error) {
u := fmt.Sprintf("videos/%d/credits", 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
}
credits := &dataListCredit{}
resp, err := s.client.Do(req, credits)
if err != nil {
return nil, resp, err
}
resp.setPaging(credits)
return credits.Data, resp, err
}
// AddCredit add credit.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/videos/%7Bvideo_id%7D/credits
func (s *VideosService) AddCredit(vid int, r *CreditRequest) (*Credit, *Response, error) {
u := fmt.Sprintf("videos/%d/credits", vid)
req, err := s.client.NewRequest("POST", u, r)
if err != nil {
return nil, nil, err
}
credit := &Credit{}
resp, err := s.client.Do(req, credit)
if err != nil {
return nil, resp, err
}
return credit, resp, nil
}
// GetCredit get specific credit by ID.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/videos/%7Bvideo_id%7D/credits/%7Bcredit_id%7D
func (s *VideosService) GetCredit(vid int, cid int) (*Credit, *Response, error) {
u := fmt.Sprintf("videos/%d/credits/%d", vid, cid)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
credit := &Credit{}
resp, err := s.client.Do(req, credit)
if err != nil {
return nil, resp, err
}
return credit, resp, err
}
// EditCredit edit specific credit by ID.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/videos/%7Bvideo_id%7D/credits/%7Bcredit_id%7D
func (s *VideosService) EditCredit(vid int, cid int, r *CreditRequest) (*Credit, *Response, error) {
u := fmt.Sprintf("videos/%d/credits/%d", vid, cid)
req, err := s.client.NewRequest("PATCH", u, r)
if err != nil {
return nil, nil, err
}
credit := &Credit{}
resp, err := s.client.Do(req, credit)
if err != nil {
return nil, resp, err
}
return credit, resp, nil
}
// DeleteCredit delete specific credit by ID.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/videos/%7Bvideo_id%7D/credits/%7Bcredit_id%7D
func (s *VideosService) DeleteCredit(vid int, cid int) (*Response, error) {
u := fmt.Sprintf("videos/%d/credits/%d", vid, cid)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}