-
-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathlist.go
More file actions
67 lines (57 loc) · 1.64 KB
/
list.go
File metadata and controls
67 lines (57 loc) · 1.64 KB
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
package deck
import (
"context"
"fmt"
"github.com/k1LoW/errors"
)
// List Google Slides presentations.
func List(ctx context.Context, opts ...Option) (_ []*Presentation, err error) {
defer func() {
err = errors.WithStack(err)
}()
d, err := newDeck(ctx, opts...)
if err != nil {
return nil, err
}
return d.List()
}
// List Google Slides presentations.
func (d *Deck) List() (_ []*Presentation, err error) {
defer func() {
err = errors.WithStack(err)
}()
var presentations []*Presentation
r, err := d.driveSrv.Files.List().SupportsAllDrives(true).IncludeItemsFromAllDrives(true).
Q("mimeType='application/vnd.google-apps.presentation' and trashed=false").Fields("files(id, name)").Do()
if err != nil {
return nil, err
}
for _, f := range r.Files {
presentations = append(presentations, &Presentation{
ID: f.Id,
Title: f.Name,
})
}
return presentations, nil
}
// ListLayouts lists layouts of the presentation.
func (d *Deck) ListLayouts() []string {
var layouts []string
for _, l := range d.presentation.Layouts {
layouts = append(layouts, l.LayoutProperties.DisplayName)
}
return layouts
}
// ListSlideURLs lists URLs of the slides in the Google Slides presentation.
func (d *Deck) ListSlideURLs() []string {
var slideURLs []string
baseURL := PresentationIDtoURL(d.id)
for _, s := range d.presentation.Slides {
slideURLs = append(slideURLs, baseURL+"present?slide=id."+s.ObjectId)
}
return slideURLs
}
// PresentationIDtoURL converts a presentation ID to a Google Slides URL.
func PresentationIDtoURL(presentationID string) string {
return fmt.Sprintf("https://docs.google.com/presentation/d/%s/", presentationID)
}