@pipedream/google_slides 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2020 Pipedream, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,45 @@
1
+ import app from "../../google_slides.app.mjs";
2
+
3
+ export default {
4
+ key: "google_slides-create-presentation",
5
+ name: "Create Presentation",
6
+ description: "Create a blank presentation or duplicate an existing presentation. [See the docs here](https://developers.google.com/slides/api/guides/presentations#copy_an_existing_presentation)",
7
+ version: "0.0.1",
8
+ type: "action",
9
+ props: {
10
+ app,
11
+ title: {
12
+ type: "string",
13
+ label: "Title",
14
+ description: "The title of the new presentation.",
15
+ },
16
+ drive: {
17
+ propDefinition: [
18
+ app,
19
+ "watchedDrive",
20
+ ],
21
+ description: "The drive to select a presentation from. If you are connected with any [Google Shared Drives](https://support.google.com/a/users/answer/9310351), you can select it here.",
22
+ },
23
+ presentationId: {
24
+ propDefinition: [
25
+ app,
26
+ "presentationId",
27
+ (c) => ({
28
+ driveId: app.methods.getDriveId(c.drive),
29
+ }),
30
+ ],
31
+ description: "Select the presentation that you want to copy from.",
32
+ optional: true,
33
+ },
34
+ },
35
+ async run({ $ }) {
36
+ if (this.presentationId) {
37
+ const presentation = await this.app.copyPresentation(this.presentationId, this.title);
38
+ $.export("$summary", `Successfully copied presentation with ID: ${this.presentationId} to ${presentation.id}`);
39
+ return presentation;
40
+ }
41
+ const presentation = await this.app.createPresentation(this.title);
42
+ $.export("$summary", `Successfully created presentation with ID: ${presentation.presentationId}`);
43
+ return presentation;
44
+ },
45
+ };
@@ -0,0 +1,34 @@
1
+ import app from "../../google_slides.app.mjs";
2
+
3
+ export default {
4
+ key: "google_slides-find-presentation",
5
+ name: "Find a Presentation",
6
+ description: "Find a presentation on Google Drive. [See the docs here](https://developers.google.com/slides/api/samples/presentation#list_existing_presentation_files)",
7
+ version: "0.0.1",
8
+ type: "action",
9
+ props: {
10
+ app,
11
+ drive: {
12
+ propDefinition: [
13
+ app,
14
+ "watchedDrive",
15
+ ],
16
+ description: "The drive to select a presentation from. If you are connected with any [Google Shared Drives](https://support.google.com/a/users/answer/9310351), you can select it here.",
17
+ },
18
+ presentationId: {
19
+ propDefinition: [
20
+ app,
21
+ "presentationId",
22
+ (c) => ({
23
+ driveId: app.methods.getDriveId(c.drive),
24
+ }),
25
+ ],
26
+ description: "List of presentations in the specified drive",
27
+ },
28
+ },
29
+ async run({ $ }) {
30
+ const presentation = await this.app.getPresentation(this.presentationId);
31
+ $.export("$summary", `Successfully found presentation with ID: ${presentation.presentationId}`);
32
+ return presentation;
33
+ },
34
+ };
@@ -0,0 +1,42 @@
1
+ import app from "../../google_slides.app.mjs";
2
+
3
+ export default {
4
+ key: "google_slides-refresh-chart",
5
+ name: "Refresh a chart",
6
+ description: "Refresh a chart from Sheets. [See the docs here](https://developers.google.com/slides/api/samples/elements#refresh_a_chart_from_sheets)",
7
+ version: "0.0.1",
8
+ type: "action",
9
+ props: {
10
+ app,
11
+ drive: {
12
+ propDefinition: [
13
+ app,
14
+ "watchedDrive",
15
+ ],
16
+ description: "The drive to select a presentation from. If you are connected with any [Google Shared Drives](https://support.google.com/a/users/answer/9310351), you can select it here.",
17
+ },
18
+ presentationId: {
19
+ propDefinition: [
20
+ app,
21
+ "presentationId",
22
+ (c) => ({
23
+ driveId: app.methods.getDriveId(c.drive),
24
+ }),
25
+ ],
26
+ description: "List of presentations in the specified drive",
27
+ },
28
+ },
29
+ async run({ $ }) {
30
+ const presentation = await this.app.getPresentation(this.presentationId);
31
+ const elements = presentation.slides.map((slide) => slide.pageElements).flat();
32
+ const chartIds = elements.filter((element) => {
33
+ return element.sheetsChart && element.sheetsChart.spreadsheetId;
34
+ }).map((element) => element.objectId);
35
+ const promises = [];
36
+ for (let chartId of chartIds) {
37
+ promises.push(this.app.refreshChart(this.presentationId, chartId));
38
+ }
39
+ await Promise.all(promises);
40
+ $.export("$summary", `Successfully refreshed ${chartIds.length} charts`);
41
+ },
42
+ };
@@ -0,0 +1,97 @@
1
+ import slides from "@googleapis/slides";
2
+ import googleDrive from "../google_drive/google_drive.app.mjs";
3
+
4
+ export default {
5
+ ...googleDrive,
6
+ type: "app",
7
+ app: "google_slides",
8
+ propDefinitions: {
9
+ ...googleDrive.propDefinitions,
10
+ presentationId: {
11
+ type: "string",
12
+ label: "Presentation",
13
+ description: "The Presentation ID",
14
+ options({
15
+ prevContext,
16
+ driveId,
17
+ }) {
18
+ const { nextPageToken } = prevContext;
19
+ return this.listPresentationsOptions(driveId, nextPageToken);
20
+ },
21
+ },
22
+ },
23
+ methods: {
24
+ ...googleDrive.methods,
25
+ slides() {
26
+ const auth = new slides.auth.OAuth2();
27
+ auth.setCredentials({
28
+ access_token: this.$auth.oauth_access_token,
29
+ });
30
+ return slides.slides({
31
+ version: "v1",
32
+ auth,
33
+ });
34
+ },
35
+ refreshChart(presentationId, chartId) {
36
+ const slides = this.slides();
37
+ const requests = [
38
+ {
39
+ refreshSheetsChart: {
40
+ objectId: chartId,
41
+ },
42
+ },
43
+ ];
44
+ return slides.presentations.batchUpdate({
45
+ presentationId,
46
+ requestBody: {
47
+ requests,
48
+ },
49
+ });
50
+ },
51
+ async createPresentation(title) {
52
+ const slides = this.slides();
53
+ const presentation = await slides.presentations.create({
54
+ title,
55
+ });
56
+ return presentation.data;
57
+ },
58
+ async listPresentationsOptions(driveId, pageToken = null) {
59
+ const q = "mimeType='application/vnd.google-apps.presentation'";
60
+ let request = {
61
+ q,
62
+ };
63
+ if (driveId) {
64
+ request = {
65
+ ...request,
66
+ corpora: "drive",
67
+ driveId,
68
+ pageToken,
69
+ includeItemsFromAllDrives: true,
70
+ supportsAllDrives: true,
71
+ };
72
+ }
73
+ return this.listFilesOptions(pageToken, request);
74
+ },
75
+ async getPresentation(presentationId) {
76
+ const slides = this.slides();
77
+ const request = {
78
+ presentationId,
79
+ };
80
+ return (await slides.presentations.get(request)).data;
81
+ },
82
+ async copyPresentation(fileId, name) {
83
+ const drive = this.drive();
84
+ const resource = {
85
+ name,
86
+ };
87
+ return (
88
+ await drive.files.copy({
89
+ fileId,
90
+ fields: "*",
91
+ supportsAllDrives: true,
92
+ resource,
93
+ })
94
+ ).data;
95
+ },
96
+ },
97
+ };
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@pipedream/google_slides",
3
+ "version": "0.0.1",
4
+ "description": "Pipedream Google Slides Components",
5
+ "main": "google_slides.app.mjs",
6
+ "keywords": [
7
+ "pipedream",
8
+ "google_slides"
9
+ ],
10
+ "homepage": "https://pipedream.com/apps/google_slides",
11
+ "author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
12
+ "license": "MIT",
13
+ "dependencies": {
14
+ "@googleapis/slides": "^0.7.1",
15
+ "@googleapis/drive": "^2.3.0",
16
+ "@pipedream/platform": "^0.9.0",
17
+ "axios": "^0.21.1",
18
+ "mime-db": "^1.51.0",
19
+ "uuid": "^8.3.2"
20
+ },
21
+ "gitHead": "e12480b94cc03bed4808ebc6b13e7fdb3a1ba535",
22
+ "publishConfig": {
23
+ "access": "public"
24
+ }
25
+ }
@@ -0,0 +1,64 @@
1
+ import newFilesInstant from "../../../google_drive/sources/new-files-instant/new-files-instant.mjs";
2
+
3
+ export default {
4
+ ...newFilesInstant,
5
+ key: "google_slides-new-presentation",
6
+ type: "source",
7
+ name: "New Presentation (Instant)",
8
+ description: "Emit new event each time a new presentation is created in a drive.",
9
+ version: "0.0.1",
10
+ hooks: {
11
+ ...newFilesInstant.hooks,
12
+ async deploy() {
13
+ // Emit sample records on the first run
14
+ const slides = await this.getPresentations(10);
15
+ for (const fileInfo of slides) {
16
+ const createdTime = Date.parse(fileInfo.createdTime);
17
+ this.$emit(fileInfo, {
18
+ summary: `New File: ${fileInfo.name}`,
19
+ id: fileInfo.id,
20
+ ts: createdTime,
21
+ });
22
+ }
23
+ },
24
+ },
25
+ methods: {
26
+ ...newFilesInstant.methods,
27
+ shouldProcess(file) {
28
+ return (
29
+ file.mimeType.includes("presentation") &&
30
+ newFilesInstant.methods.shouldProcess.bind(this)(file)
31
+ );
32
+ },
33
+ getPresentationsFromFolderOpts(folderId) {
34
+ const mimeQuery = "mimeType = 'application/vnd.google-apps.presentation'";
35
+ let opts = {
36
+ q: `${mimeQuery} and parents in '${folderId}' and trashed = false`,
37
+ };
38
+ if (!this.isMyDrive()) {
39
+ opts = {
40
+ corpora: "drive",
41
+ driveId: this.getDriveId(),
42
+ includeItemsFromAllDrives: true,
43
+ supportsAllDrives: true,
44
+ ...opts,
45
+ };
46
+ }
47
+ return opts;
48
+ },
49
+ async getPresentations(limit) {
50
+ const slides = [];
51
+ const foldersIds = this.folders;
52
+ for (const folderId of foldersIds) {
53
+ const opts = this.getPresentationsFromFolderOpts(folderId);
54
+ const filesWrapper = await this.googleDrive.listFilesInPage(null, opts);
55
+ for (const file of filesWrapper.files) {
56
+ const fileInfo = await this.googleDrive.getFile(file.id);
57
+ slides.push(fileInfo);
58
+ if (slides.length >= limit) { return slides; }
59
+ }
60
+ }
61
+ return slides;
62
+ },
63
+ },
64
+ };