-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient.go
86 lines (74 loc) · 2.66 KB
/
client.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
package slidesutil
import (
"context"
"fmt"
"net/http"
"github.com/grokify/mogo/errors/errorsutil"
"google.golang.org/api/option"
slides "google.golang.org/api/slides/v1"
)
type GoogleSlidesService struct {
httpClient *http.Client
SlidesService *slides.Service
PresentationsService *slides.PresentationsService
}
func NewGoogleSlidesService(httpClient *http.Client) (*GoogleSlidesService, error) {
gsc := GoogleSlidesService{}
err := gsc.SetHTTPClient(httpClient)
return &gsc, err
}
func (gsc *GoogleSlidesService) SetHTTPClient(httpClient *http.Client) error {
if httpClient == nil {
return fmt.Errorf("httpClient parameter canot be nil")
}
gsc.httpClient = httpClient
service, err := slides.NewService(context.Background(), option.WithHTTPClient(httpClient))
if err != nil {
return errorsutil.Wrap(err, "unable to create slides.Service")
}
gsc.SlidesService = service
gsc.PresentationsService = slides.NewPresentationsService(service)
return nil
}
type SlidesClient struct {
GoogleSlidesService *GoogleSlidesService
}
func NewSlidesClient(googHTTPClient *http.Client) (*SlidesClient, error) {
sc := &SlidesClient{}
gss, err := NewGoogleSlidesService(googHTTPClient)
if err != nil {
return nil, err
}
sc.GoogleSlidesService = gss
return sc, nil
}
func (sc *SlidesClient) CreatePresentation(
filename, titleText, subtitleText string) (string, error) {
return CreatePresentation(
sc.GoogleSlidesService.SlidesService,
sc.GoogleSlidesService.PresentationsService,
filename, titleText, subtitleText)
}
func (sc *SlidesClient) CreateEmptyPresentation(name string) (string, error) {
return CreateEmptyPresentation(
sc.GoogleSlidesService.PresentationsService, name)
}
// BatchUpdate is a convenience function to make calling `BatchUpdate`
// less verbose.
func (sc *SlidesClient) BatchUpdate(presentationID string, batchupdatepresentationrequest *slides.BatchUpdatePresentationRequest) *slides.PresentationsBatchUpdateCall {
return sc.GoogleSlidesService.PresentationsService.BatchUpdate(
presentationID, batchupdatepresentationrequest)
}
// CreateSlideTitleAndBody is a convenience function.
func (sc *SlidesClient) CreateSlideTitleAndBody(presentationID string, filename string) (string, error) {
return CreateSlideTitleAndBody(
sc.GoogleSlidesService.SlidesService,
sc.GoogleSlidesService.PresentationsService,
presentationID, filename)
}
func (sc *SlidesClient) CreateSlideMarkdown(presentationID, titleText, bodyMarkdown string, underlineLinks bool) error {
return CreateSlideMarkdown(
sc.GoogleSlidesService.SlidesService,
sc.GoogleSlidesService.PresentationsService,
presentationID, titleText, bodyMarkdown, underlineLinks)
}