forked from simplesurance/bunny-go
/
videolibrary_list.go
56 lines (47 loc) · 1.85 KB
/
videolibrary_list.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
package bunny
import "context"
// VideoLibraries represents the response of the List Video Library API endpoint.
//
// Bunny.net API docs: https://docs.bunny.net/reference/videolibrarypublic_index
type VideoLibraries PaginationReply[VideoLibrary]
// VideoLibraryListOpts represents both PaginationOptions and the other optional
// query parameters of the List endpoint.
type VideoLibraryListOpts struct {
VideoLibraryGetOpts
PaginationOptions
}
// List retrieves the Video Libraries.
// If opts is nil, DefaultPaginationPerPage and DefaultPaginationPage will be used.
// if opts.Page or opts.PerPage is < 1, the related DefaultPagination values are used.
//
// Bunny.net API docs: https://docs.bunny.net/reference/videolibrarypublic_index
func (s *VideoLibraryService) List(ctx context.Context, opts *VideoLibraryListOpts) (*VideoLibraries, error) {
const path = "/videolibrary"
var res VideoLibraries
// NOTE: The resourceList function is not used for the purpose of
// providing the extra query param options in VideoLibraryGetOpts. In the future
// hopefully it can be removed for a better solution. See the following discussion:
// https://github.com/simplesurance/bunny-go/pull/27#discussion_r1021270152
// Ensure that opts.Page is >=1, if it isn't bunny.net will send a
// different response JSON object, that contains only a single Object,
// without items and paginations fields. Enforcing opts.page =>1 ensures
// that we always unmarshall into the same struct.
if opts == nil {
opts = &VideoLibraryListOpts{
PaginationOptions: PaginationOptions{
Page: DefaultPaginationPage,
PerPage: DefaultPaginationPerPage,
},
}
} else {
opts.ensureConstraints()
}
req, err := s.client.newGetRequest(path, opts)
if err != nil {
return nil, err
}
if err := s.client.sendRequest(ctx, req, &res); err != nil {
return nil, err
}
return &res, nil
}