/
videos_pictures.go
134 lines (110 loc) · 3.72 KB
/
videos_pictures.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
package vimeo
import "fmt"
type dataListPictures struct {
Data []*Pictures `json:"data,omitempty"`
pagination
}
// Pictures internal object provides access to pictures.
type Pictures struct {
URI string `json:"uri,omitempty"`
Active bool `json:"active"`
Type string `json:"type,omitempty"`
Sizes []*PictureSize `json:"sizes,omitempty"`
ResourceKey string `json:"resource_key,omitempty"`
}
// PictureSize internal object provides access to picture size.
type PictureSize struct {
Width int `json:"width,omitempty"`
Height int `json:"height,omitempty"`
Link string `json:"link,omitempty"`
LinkWithPlayButton string `json:"link_with_play_button,omitempty"`
}
// Header internal object provides access to header pictures.
type Header struct {
URI string `json:"uri,omitempty"`
Active bool `json:"active"`
Type string `json:"type,omitempty"`
Sizes []*PictureSize `json:"sizes,omitempty"`
ResourceKey string `json:"resource_key,omitempty"`
}
// PicturesRequest represents a request to create/edit an pictures.
type PicturesRequest struct {
Time float32 `json:"time,omitempty"`
Active bool `json:"active,omitempty"`
}
// ListPictures lists thumbnails.
//
// https://developer.vimeo.com/api/playground/videos/%7Bvideo_id%7D/pictures
func (s *VideosService) ListPictures(vid int) ([]*Pictures, *Response, error) {
u := fmt.Sprintf("videos/%d/pictures", vid)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
pictures := &dataListPictures{}
resp, err := s.client.Do(req, pictures)
if err != nil {
return nil, resp, err
}
resp.setPaging(pictures)
return pictures.Data, resp, err
}
// CreatePictures create a thumbnail.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/videos/%7Bvideo_id%7D/pictures
func (s *VideosService) CreatePictures(vid int, r *PicturesRequest) (*Pictures, *Response, error) {
u := fmt.Sprintf("videos/%d/pictures", vid)
req, err := s.client.NewRequest("POST", u, r)
if err != nil {
return nil, nil, err
}
pictures := &Pictures{}
resp, err := s.client.Do(req, pictures)
if err != nil {
return nil, resp, err
}
return pictures, resp, nil
}
// GetPictures get one thumbnail.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/videos/%7Bvideo_id%7D/pictures
func (s *VideosService) GetPictures(vid int, pid int) (*Pictures, *Response, error) {
u := fmt.Sprintf("videos/%d/pictures/%d", vid, pid)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
pictures := &Pictures{}
resp, err := s.client.Do(req, pictures)
if err != nil {
return nil, resp, err
}
return pictures, resp, err
}
// EditPictures edit specific pictures by ID.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/videos/%7Bvideo_id%7D/pictures/%7Bpicture_id%7D
func (s *VideosService) EditPictures(vid int, pid int, r *PicturesRequest) (*Pictures, *Response, error) {
u := fmt.Sprintf("videos/%d/pictures/%d", vid, pid)
req, err := s.client.NewRequest("PATCH", u, r)
if err != nil {
return nil, nil, err
}
pictures := &Pictures{}
resp, err := s.client.Do(req, pictures)
if err != nil {
return nil, resp, err
}
return pictures, resp, nil
}
// DeletePictures delete specific pictures by ID.
//
// Vimeo API docs: https://developer.vimeo.com/api/playground/videos/%7Bvideo_id%7D/comments/%7Bcomment_id%7D
func (s *VideosService) DeletePictures(vid int, pid int) (*Response, error) {
u := fmt.Sprintf("videos/%d/pictures/%d", vid, pid)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}