-
Notifications
You must be signed in to change notification settings - Fork 2
/
slide_create.go
66 lines (54 loc) · 1.91 KB
/
slide_create.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
package slidesutil
import (
slides "google.golang.org/api/slides/v1"
)
// CreateSlideTitleOnly creates a slide using Markdown
// given a PresentationID and title.
func CreateSlideTitleOnly(srv *slides.Service, psv *slides.PresentationsService, presentationID, titleText string) (string, error) {
reqs1 := []*slides.Request{CreateSlideRequestLayout(LayoutTitleOnly)}
resp1, err := psv.BatchUpdate(
presentationID,
&slides.BatchUpdatePresentationRequest{Requests: reqs1}).Do()
if err != nil {
return "", err
}
slideID := resp1.Replies[0].CreateSlide.ObjectId
presentation, err := srv.Presentations.Get(presentationID).Do()
if err != nil {
return slideID, err
}
newSlide := presentation.Slides[len(presentation.Slides)-1]
newSlideTitleID := newSlide.PageElements[0].ObjectId
_, err = psv.BatchUpdate(
presentationID,
&slides.BatchUpdatePresentationRequest{
Requests: []*slides.Request{InsertTextRequest(
newSlideTitleID, titleText)},
}).Do()
return slideID, err
}
// CreateSlideTitleAndBody creates a slide using Markdown
// given a PresentationID, title, and markdown body.
func CreateSlideTitleAndBody(srv *slides.Service, psv *slides.PresentationsService, presentationID, titleText string) (string, error) {
reqs1 := []*slides.Request{CreateSlideRequestLayout(LayoutTitleAndBody)}
resp1, err := psv.BatchUpdate(
presentationID,
&slides.BatchUpdatePresentationRequest{Requests: reqs1}).Do()
if err != nil {
return "", err
}
slideID := resp1.Replies[0].CreateSlide.ObjectId
presentation, err := srv.Presentations.Get(presentationID).Do()
if err != nil {
return slideID, err
}
newSlide := presentation.Slides[len(presentation.Slides)-1]
newSlideTitleID := newSlide.PageElements[0].ObjectId
_, err = psv.BatchUpdate(
presentationID,
&slides.BatchUpdatePresentationRequest{
Requests: []*slides.Request{InsertTextRequest(
newSlideTitleID, titleText)},
}).Do()
return slideID, err
}