Skip to content

Commit 87570fe

Browse files
committed
chore: Rename snippet methods + remove improper comment
1 parent c309beb commit 87570fe

File tree

3 files changed

+51
-58
lines changed

3 files changed

+51
-58
lines changed

slides/api/Helpers.gs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
let filesToDelete = [];
1716

1817
/**
1918
* Helper functions.
@@ -31,7 +30,7 @@ Helpers.prototype.deleteFileOnCleanup = function(id) {
3130
};
3231

3332
Helpers.prototype.cleanup = function() {
34-
filesToDelete.forEach(Drive.Files.remove);
33+
this.filesToDelete.forEach(Drive.Files.remove);
3534
};
3635

3736
Helpers.prototype.createTestPresentation = function() {
@@ -131,4 +130,4 @@ Helpers.prototype.createTestSheetsChart = function(presentationId, pageId,
131130
requests: requests
132131
}, presentationId);
133132
return createSheetsChartResponse.replies[0].createSheetsChart.objectId;
134-
};
133+
};

slides/api/Snippets.gs

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,12 @@
1515
*/
1616
const title = 'my title';
1717

18-
/**
19-
* Snippet class for the Google Slides Advanced Service.
20-
*/
21-
function Snippets() {}
22-
2318
// [START slides_create_presentation]
2419
/**
2520
* Creates a presentation
2621
* @returns {*} the created presentation
2722
*/
28-
Snippets.prototype.createPresentation = function() {
23+
function createPresentation() {
2924
try {
3025
const presentation = Slides.Presentations.create({
3126
title: title
@@ -42,12 +37,11 @@ Snippets.prototype.createPresentation = function() {
4237

4338
// [START slides_copy_presentation]
4439
/**
45-
* create a presentation and copy it??? doesn't this need a presentation file as input????
46-
* doesn't make any sense!
40+
* create a presentation and copy it
41+
* @param {string} presentationId - ID of presentation to copy
4742
* @returns {*} the copy's presentation id
4843
*/
49-
Snippets.prototype.copyPresentation = function() {
50-
const presentationId = this.createPresentation().presentationId;
44+
function copyPresentation(presentationId) {
5145
const copyTitle = 'Copy Title';
5246

5347
let copyFile = {
@@ -74,7 +68,7 @@ Snippets.prototype.copyPresentation = function() {
7468
* @param {string} pageId
7569
* @returns {*}
7670
*/
77-
Snippets.prototype.createSlide = function(presentationId, pageId) {
71+
function createSlide(presentationId, pageId) {
7872
// See Presentation.insertSlide(...) to learn how to add a slide using SlidesApp.
7973
// http://developers.google.com/apps-script/reference/slides/presentation#appendslidelayout
8074
const requests = [{
@@ -111,41 +105,42 @@ Snippets.prototype.createSlide = function(presentationId, pageId) {
111105
* @param {string} pageId
112106
* @returns {*}
113107
*/
114-
Snippets.prototype.createTextboxWithText = function(presentationId, pageId) {
108+
function createTextboxWithText(presentationId, pageId) {
115109
const elementId = 'MyTextBox_01';
116110
const pt350 = {
117111
magnitude: 350,
118112
unit: 'PT'
119113
};
120-
const requests = [{
121-
createShape: {
122-
objectId: elementId,
123-
shapeType: 'TEXT_BOX',
124-
elementProperties: {
125-
pageObjectId: pageId,
126-
size: {
127-
height: pt350,
128-
width: pt350
129-
},
130-
transform: {
131-
scaleX: 1,
132-
scaleY: 1,
133-
translateX: 350,
134-
translateY: 100,
135-
unit: 'PT'
114+
const requests = [
115+
{
116+
createShape: {
117+
objectId: elementId,
118+
shapeType: 'TEXT_BOX',
119+
elementProperties: {
120+
pageObjectId: pageId,
121+
size: {
122+
height: pt350,
123+
width: pt350
124+
},
125+
transform: {
126+
scaleX: 1,
127+
scaleY: 1,
128+
translateX: 350,
129+
translateY: 100,
130+
unit: 'PT'
131+
}
136132
}
137133
}
138-
}
139-
},
140-
134+
},
141135
// Insert text into the box, using the supplied element ID.
142136
{
143137
insertText: {
144138
objectId: elementId,
145139
insertionIndex: 0,
146140
text: 'New Box Text Inserted!'
147141
}
148-
}];
142+
}
143+
];
149144

150145
// Execute the request.
151146
try {
@@ -170,7 +165,7 @@ Snippets.prototype.createTextboxWithText = function(presentationId, pageId) {
170165
* @param {string} pageId
171166
* @returns {*}
172167
*/
173-
Snippets.prototype.createImage = function(presentationId, pageId) {
168+
function createImage(presentationId, pageId) {
174169
let requests = [];
175170
const imageId = 'MyImage_01';
176171
const imageUrl = 'https://www.google.com/images/branding/googlelogo/2x/' +
@@ -224,7 +219,7 @@ Snippets.prototype.createImage = function(presentationId, pageId) {
224219
* @param {string} dataSpreadsheetId
225220
* @returns {*[]}
226221
*/
227-
Snippets.prototype.textMerging = function(templatePresentationId, dataSpreadsheetId) {
222+
function textMerging(templatePresentationId, dataSpreadsheetId) {
228223
let responses = [];
229224
const dataRangeNotation = 'Customers!A2:M6';
230225
try {
@@ -306,7 +301,7 @@ Snippets.prototype.textMerging = function(templatePresentationId, dataSpreadshee
306301
* @param {string} customerName
307302
* @returns {*}
308303
*/
309-
Snippets.prototype.imageMerging = function(templatePresentationId, imageUrl, customerName) {
304+
function imageMerging(templatePresentationId, imageUrl, customerName) {
310305
const logoUrl = imageUrl;
311306
const customerGraphicUrl = imageUrl;
312307

@@ -368,7 +363,7 @@ Snippets.prototype.imageMerging = function(templatePresentationId, imageUrl, cus
368363
* @param {string} replacementText
369364
* @returns {*}
370365
*/
371-
Snippets.prototype.simpleTextReplace = function(presentationId, shapeId, replacementText) {
366+
function simpleTextReplace(presentationId, shapeId, replacementText) {
372367
const requests = [{
373368
deleteText: {
374369
objectId: shapeId,
@@ -408,7 +403,7 @@ Snippets.prototype.simpleTextReplace = function(presentationId, shapeId, replace
408403
* @param {string} shapeId
409404
* @returns {*}
410405
*/
411-
Snippets.prototype.textStyleUpdate = function(presentationId, shapeId) {
406+
function textStyleUpdate(presentationId, shapeId) {
412407
const requests = [{
413408
updateTextStyle: {
414409
objectId: shapeId,
@@ -485,7 +480,7 @@ Snippets.prototype.textStyleUpdate = function(presentationId, shapeId) {
485480
/**
486481
* Add arrow-diamond-disc bullets to all text in the shape.
487482
*/
488-
Snippets.prototype.createBulletedText = function(presentationId, shapeId) {
483+
function createBulletedText(presentationId, shapeId) {
489484
const requests = [{
490485
createParagraphBullets: {
491486
objectId: shapeId,
@@ -522,7 +517,7 @@ Snippets.prototype.createBulletedText = function(presentationId, shapeId) {
522517
* @param {string} sheetChartId
523518
* @returns {*}
524519
*/
525-
Snippets.prototype.createSheetsChart = function(presentationId, pageId, shapeId, sheetChartId) {
520+
function createSheetsChart(presentationId, pageId, shapeId, sheetChartId) {
526521
const emu4M = {
527522
magnitude: 4000000,
528523
unit: 'EMU'
@@ -573,7 +568,7 @@ Snippets.prototype.createSheetsChart = function(presentationId, pageId, shapeId,
573568
* @param {string} presentationChartId
574569
* @returns {*}
575570
*/
576-
Snippets.prototype.refreshSheetsChart = function(presentationId, presentationChartId) {
571+
function refreshSheetsChart(presentationId, presentationChartId) {
577572
const requests = [{
578573
refreshSheetsChart: {
579574
objectId: presentationChartId

slides/api/Tests.gs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
let snippets = new Snippets();
17-
let helpers = new Helpers();
16+
const helpers = new Helpers();
1817

1918
// Constants
2019
const IMAGE_URL =
@@ -68,7 +67,7 @@ function RUN_ALL_TESTS() {
6867
*/
6968
function itShouldCreateAPresentation() {
7069
console.log('> itShouldCreateAPresentation');
71-
const presentation = snippets.createPresentation();
70+
const presentation = createPresentation();
7271
expectToExist(presentation.presentationId);
7372
helpers.deleteFileOnCleanup(presentation.presentationId);
7473
}
@@ -79,7 +78,7 @@ function itShouldCreateAPresentation() {
7978
function itShouldCopyAPresentation() {
8079
console.log('> itShouldCopyAPresentation');
8180
const presentationId = helpers.createTestPresentation();
82-
const copyId = snippets.copyPresentation(presentationId, 'My Duplicate, Presentation');
81+
const copyId = copyPresentation(presentationId, 'My Duplicate, Presentation');
8382
expectToExist(copyId);
8483
helpers.deleteFileOnCleanup(copyId);
8584
}
@@ -92,7 +91,7 @@ function itShouldCreateASlide() {
9291
const presentationId = helpers.createTestPresentation();
9392
helpers.addSlides(presentationId, 3, 'TITLE_AND_TWO_COLUMNS');
9493
const pageId = 'my_page_id';
95-
const response = snippets.createSlide(presentationId, pageId);
94+
const response = createSlide(presentationId, pageId);
9695
expectToExist(response.replies[0].createSlide.objectId);
9796
}
9897

@@ -104,7 +103,7 @@ function itShouldCreateATextboxWithText() {
104103
const presentationId = helpers.createTestPresentation();
105104
const ids = helpers.addSlides(presentationId, 3, 'TITLE_AND_TWO_COLUMNS');
106105
const pageId = ids[0];
107-
const response = snippets.createTextboxWithText(presentationId, pageId);
106+
const response = createTextboxWithText(presentationId, pageId);
108107
expectToEqual(2, response.replies.length);
109108
const boxId = response.replies[0].createShape.objectId;
110109
expectToExist(boxId);
@@ -118,7 +117,7 @@ function itShouldCreateAnImage() {
118117
const presentationId = helpers.createTestPresentation();
119118
const ids = helpers.addSlides(presentationId, 1, 'BLANK');
120119
const pageId = ids[0];
121-
const response = snippets.createImage(presentationId, pageId);
120+
const response = createImage(presentationId, pageId);
122121
expectToEqual(1, response.length);
123122
const imageId = response[0].createImage.objectId;
124123
expectToExist(imageId);
@@ -129,7 +128,7 @@ function itShouldCreateAnImage() {
129128
*/
130129
function itShouldMergeText() {
131130
console.log('> itShouldMergeText');
132-
let responses = snippets.textMerging(TEMPLATE_PRESENTATION_ID, DATA_SPREADSHEET_ID);
131+
let responses = textMerging(TEMPLATE_PRESENTATION_ID, DATA_SPREADSHEET_ID);
133132
expectToEqual(5, responses.length);
134133
responses.forEach(function(response) {
135134
let numReplacements = 0;
@@ -145,7 +144,7 @@ function itShouldMergeText() {
145144
*/
146145
function itShouldImageMerge() {
147146
console.log('> itShouldImageMerge');
148-
let response = snippets.imageMerging(TEMPLATE_PRESENTATION_ID, IMAGE_URL, CUSTOMER_NAME);
147+
let response = imageMerging(TEMPLATE_PRESENTATION_ID, IMAGE_URL, CUSTOMER_NAME);
149148
expectToEqual(2, response.replies.length);
150149
let numReplacements = 0;
151150
response.replies.forEach(function(reply) {
@@ -163,7 +162,7 @@ function itShouldSimpleTextReplace() {
163162
const pageIds = helpers.addSlides(presentationId, 1, 'BLANK');
164163
const pageId = pageIds[0];
165164
const boxId = helpers.createTestTextbox(presentationId, pageId);
166-
const response = snippets.simpleTextReplace(presentationId, boxId, 'MY NEW TEXT');
165+
const response = simpleTextReplace(presentationId, boxId, 'MY NEW TEXT');
167166
expectToEqual(2, response.replies.length);
168167
}
169168

@@ -176,7 +175,7 @@ function itShouldTextStyleUpdate() {
176175
const pageIds = helpers.addSlides(presentationId, 1, 'BLANK');
177176
const pageId = pageIds[0];
178177
const boxId = helpers.createTestTextbox(presentationId, pageId);
179-
const response = snippets.textStyleUpdate(presentationId, boxId);
178+
const response = textStyleUpdate(presentationId, boxId);
180179
expectToEqual(3, response.replies.length);
181180
}
182181

@@ -189,7 +188,7 @@ function itShouldCreateBulletedText() {
189188
const pageIds = helpers.addSlides(presentationId, 1, 'BLANK');
190189
const pageId = pageIds[0];
191190
const boxId = helpers.createTestTextbox(presentationId, pageId);
192-
const response = snippets.createBulletedText(presentationId, boxId);
191+
const response = createBulletedText(presentationId, boxId);
193192
expectToEqual(1, response.replies.length);
194193
}
195194

@@ -201,7 +200,7 @@ function itShouldCreateSheetsChart() {
201200
const presentationId = helpers.createTestPresentation();
202201
const pageIds = helpers.addSlides(presentationId, 1, 'BLANK');
203202
const pageId = pageIds[0];
204-
const response = snippets.createSheetsChart(presentationId, pageId, DATA_SPREADSHEET_ID, CHART_ID);
203+
const response = createSheetsChart(presentationId, pageId, DATA_SPREADSHEET_ID, CHART_ID);
205204
expectToEqual(1, response.replies.length);
206205
const chartId = response.replies[0].createSheetsChart.objectId;
207206
expectToExist(chartId);
@@ -217,6 +216,6 @@ function itShouldRefreshSheetsChart() {
217216
const pageId = pageIds[0];
218217
const sheetChartId = helpers.createTestSheetsChart(presentationId, pageId, DATA_SPREADSHEET_ID,
219218
CHART_ID);
220-
const response = snippets.refreshSheetsChart(presentationId, sheetChartId);
219+
const response = refreshSheetsChart(presentationId, sheetChartId);
221220
expectToEqual(1, response.replies.length);
222-
}
221+
}

0 commit comments

Comments
 (0)