Skip to content

Commit

Permalink
chore: Rename snippet methods + remove improper comment
Browse files Browse the repository at this point in the history
  • Loading branch information
sqrrrl committed Oct 19, 2022
1 parent c309beb commit 87570fe
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 58 deletions.
5 changes: 2 additions & 3 deletions slides/api/Helpers.gs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
let filesToDelete = [];

/**
* Helper functions.
Expand All @@ -31,7 +30,7 @@ Helpers.prototype.deleteFileOnCleanup = function(id) {
};

Helpers.prototype.cleanup = function() {
filesToDelete.forEach(Drive.Files.remove);
this.filesToDelete.forEach(Drive.Files.remove);
};

Helpers.prototype.createTestPresentation = function() {
Expand Down Expand Up @@ -131,4 +130,4 @@ Helpers.prototype.createTestSheetsChart = function(presentationId, pageId,
requests: requests
}, presentationId);
return createSheetsChartResponse.replies[0].createSheetsChart.objectId;
};
};
75 changes: 35 additions & 40 deletions slides/api/Snippets.gs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,12 @@
*/
const title = 'my title';

/**
* Snippet class for the Google Slides Advanced Service.
*/
function Snippets() {}

// [START slides_create_presentation]
/**
* Creates a presentation
* @returns {*} the created presentation
*/
Snippets.prototype.createPresentation = function() {
function createPresentation() {
try {
const presentation = Slides.Presentations.create({
title: title
Expand All @@ -42,12 +37,11 @@ Snippets.prototype.createPresentation = function() {

// [START slides_copy_presentation]
/**
* create a presentation and copy it??? doesn't this need a presentation file as input????
* doesn't make any sense!
* create a presentation and copy it
* @param {string} presentationId - ID of presentation to copy
* @returns {*} the copy's presentation id
*/
Snippets.prototype.copyPresentation = function() {
const presentationId = this.createPresentation().presentationId;
function copyPresentation(presentationId) {
const copyTitle = 'Copy Title';

let copyFile = {
Expand All @@ -74,7 +68,7 @@ Snippets.prototype.copyPresentation = function() {
* @param {string} pageId
* @returns {*}
*/
Snippets.prototype.createSlide = function(presentationId, pageId) {
function createSlide(presentationId, pageId) {
// See Presentation.insertSlide(...) to learn how to add a slide using SlidesApp.
// http://developers.google.com/apps-script/reference/slides/presentation#appendslidelayout
const requests = [{
Expand Down Expand Up @@ -111,41 +105,42 @@ Snippets.prototype.createSlide = function(presentationId, pageId) {
* @param {string} pageId
* @returns {*}
*/
Snippets.prototype.createTextboxWithText = function(presentationId, pageId) {
function createTextboxWithText(presentationId, pageId) {
const elementId = 'MyTextBox_01';
const pt350 = {
magnitude: 350,
unit: 'PT'
};
const requests = [{
createShape: {
objectId: elementId,
shapeType: 'TEXT_BOX',
elementProperties: {
pageObjectId: pageId,
size: {
height: pt350,
width: pt350
},
transform: {
scaleX: 1,
scaleY: 1,
translateX: 350,
translateY: 100,
unit: 'PT'
const requests = [
{
createShape: {
objectId: elementId,
shapeType: 'TEXT_BOX',
elementProperties: {
pageObjectId: pageId,
size: {
height: pt350,
width: pt350
},
transform: {
scaleX: 1,
scaleY: 1,
translateX: 350,
translateY: 100,
unit: 'PT'
}
}
}
}
},

},
// Insert text into the box, using the supplied element ID.
{
insertText: {
objectId: elementId,
insertionIndex: 0,
text: 'New Box Text Inserted!'
}
}];
}
];

// Execute the request.
try {
Expand All @@ -170,7 +165,7 @@ Snippets.prototype.createTextboxWithText = function(presentationId, pageId) {
* @param {string} pageId
* @returns {*}
*/
Snippets.prototype.createImage = function(presentationId, pageId) {
function createImage(presentationId, pageId) {
let requests = [];
const imageId = 'MyImage_01';
const imageUrl = 'https://www.google.com/images/branding/googlelogo/2x/' +
Expand Down Expand Up @@ -224,7 +219,7 @@ Snippets.prototype.createImage = function(presentationId, pageId) {
* @param {string} dataSpreadsheetId
* @returns {*[]}
*/
Snippets.prototype.textMerging = function(templatePresentationId, dataSpreadsheetId) {
function textMerging(templatePresentationId, dataSpreadsheetId) {
let responses = [];
const dataRangeNotation = 'Customers!A2:M6';
try {
Expand Down Expand Up @@ -306,7 +301,7 @@ Snippets.prototype.textMerging = function(templatePresentationId, dataSpreadshee
* @param {string} customerName
* @returns {*}
*/
Snippets.prototype.imageMerging = function(templatePresentationId, imageUrl, customerName) {
function imageMerging(templatePresentationId, imageUrl, customerName) {
const logoUrl = imageUrl;
const customerGraphicUrl = imageUrl;

Expand Down Expand Up @@ -368,7 +363,7 @@ Snippets.prototype.imageMerging = function(templatePresentationId, imageUrl, cus
* @param {string} replacementText
* @returns {*}
*/
Snippets.prototype.simpleTextReplace = function(presentationId, shapeId, replacementText) {
function simpleTextReplace(presentationId, shapeId, replacementText) {
const requests = [{
deleteText: {
objectId: shapeId,
Expand Down Expand Up @@ -408,7 +403,7 @@ Snippets.prototype.simpleTextReplace = function(presentationId, shapeId, replace
* @param {string} shapeId
* @returns {*}
*/
Snippets.prototype.textStyleUpdate = function(presentationId, shapeId) {
function textStyleUpdate(presentationId, shapeId) {
const requests = [{
updateTextStyle: {
objectId: shapeId,
Expand Down Expand Up @@ -485,7 +480,7 @@ Snippets.prototype.textStyleUpdate = function(presentationId, shapeId) {
/**
* Add arrow-diamond-disc bullets to all text in the shape.
*/
Snippets.prototype.createBulletedText = function(presentationId, shapeId) {
function createBulletedText(presentationId, shapeId) {
const requests = [{
createParagraphBullets: {
objectId: shapeId,
Expand Down Expand Up @@ -522,7 +517,7 @@ Snippets.prototype.createBulletedText = function(presentationId, shapeId) {
* @param {string} sheetChartId
* @returns {*}
*/
Snippets.prototype.createSheetsChart = function(presentationId, pageId, shapeId, sheetChartId) {
function createSheetsChart(presentationId, pageId, shapeId, sheetChartId) {
const emu4M = {
magnitude: 4000000,
unit: 'EMU'
Expand Down Expand Up @@ -573,7 +568,7 @@ Snippets.prototype.createSheetsChart = function(presentationId, pageId, shapeId,
* @param {string} presentationChartId
* @returns {*}
*/
Snippets.prototype.refreshSheetsChart = function(presentationId, presentationChartId) {
function refreshSheetsChart(presentationId, presentationChartId) {
const requests = [{
refreshSheetsChart: {
objectId: presentationChartId
Expand Down
29 changes: 14 additions & 15 deletions slides/api/Tests.gs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
let snippets = new Snippets();
let helpers = new Helpers();
const helpers = new Helpers();

// Constants
const IMAGE_URL =
Expand Down Expand Up @@ -68,7 +67,7 @@ function RUN_ALL_TESTS() {
*/
function itShouldCreateAPresentation() {
console.log('> itShouldCreateAPresentation');
const presentation = snippets.createPresentation();
const presentation = createPresentation();
expectToExist(presentation.presentationId);
helpers.deleteFileOnCleanup(presentation.presentationId);
}
Expand All @@ -79,7 +78,7 @@ function itShouldCreateAPresentation() {
function itShouldCopyAPresentation() {
console.log('> itShouldCopyAPresentation');
const presentationId = helpers.createTestPresentation();
const copyId = snippets.copyPresentation(presentationId, 'My Duplicate, Presentation');
const copyId = copyPresentation(presentationId, 'My Duplicate, Presentation');
expectToExist(copyId);
helpers.deleteFileOnCleanup(copyId);
}
Expand All @@ -92,7 +91,7 @@ function itShouldCreateASlide() {
const presentationId = helpers.createTestPresentation();
helpers.addSlides(presentationId, 3, 'TITLE_AND_TWO_COLUMNS');
const pageId = 'my_page_id';
const response = snippets.createSlide(presentationId, pageId);
const response = createSlide(presentationId, pageId);
expectToExist(response.replies[0].createSlide.objectId);
}

Expand All @@ -104,7 +103,7 @@ function itShouldCreateATextboxWithText() {
const presentationId = helpers.createTestPresentation();
const ids = helpers.addSlides(presentationId, 3, 'TITLE_AND_TWO_COLUMNS');
const pageId = ids[0];
const response = snippets.createTextboxWithText(presentationId, pageId);
const response = createTextboxWithText(presentationId, pageId);
expectToEqual(2, response.replies.length);
const boxId = response.replies[0].createShape.objectId;
expectToExist(boxId);
Expand All @@ -118,7 +117,7 @@ function itShouldCreateAnImage() {
const presentationId = helpers.createTestPresentation();
const ids = helpers.addSlides(presentationId, 1, 'BLANK');
const pageId = ids[0];
const response = snippets.createImage(presentationId, pageId);
const response = createImage(presentationId, pageId);
expectToEqual(1, response.length);
const imageId = response[0].createImage.objectId;
expectToExist(imageId);
Expand All @@ -129,7 +128,7 @@ function itShouldCreateAnImage() {
*/
function itShouldMergeText() {
console.log('> itShouldMergeText');
let responses = snippets.textMerging(TEMPLATE_PRESENTATION_ID, DATA_SPREADSHEET_ID);
let responses = textMerging(TEMPLATE_PRESENTATION_ID, DATA_SPREADSHEET_ID);
expectToEqual(5, responses.length);
responses.forEach(function(response) {
let numReplacements = 0;
Expand All @@ -145,7 +144,7 @@ function itShouldMergeText() {
*/
function itShouldImageMerge() {
console.log('> itShouldImageMerge');
let response = snippets.imageMerging(TEMPLATE_PRESENTATION_ID, IMAGE_URL, CUSTOMER_NAME);
let response = imageMerging(TEMPLATE_PRESENTATION_ID, IMAGE_URL, CUSTOMER_NAME);
expectToEqual(2, response.replies.length);
let numReplacements = 0;
response.replies.forEach(function(reply) {
Expand All @@ -163,7 +162,7 @@ function itShouldSimpleTextReplace() {
const pageIds = helpers.addSlides(presentationId, 1, 'BLANK');
const pageId = pageIds[0];
const boxId = helpers.createTestTextbox(presentationId, pageId);
const response = snippets.simpleTextReplace(presentationId, boxId, 'MY NEW TEXT');
const response = simpleTextReplace(presentationId, boxId, 'MY NEW TEXT');
expectToEqual(2, response.replies.length);
}

Expand All @@ -176,7 +175,7 @@ function itShouldTextStyleUpdate() {
const pageIds = helpers.addSlides(presentationId, 1, 'BLANK');
const pageId = pageIds[0];
const boxId = helpers.createTestTextbox(presentationId, pageId);
const response = snippets.textStyleUpdate(presentationId, boxId);
const response = textStyleUpdate(presentationId, boxId);
expectToEqual(3, response.replies.length);
}

Expand All @@ -189,7 +188,7 @@ function itShouldCreateBulletedText() {
const pageIds = helpers.addSlides(presentationId, 1, 'BLANK');
const pageId = pageIds[0];
const boxId = helpers.createTestTextbox(presentationId, pageId);
const response = snippets.createBulletedText(presentationId, boxId);
const response = createBulletedText(presentationId, boxId);
expectToEqual(1, response.replies.length);
}

Expand All @@ -201,7 +200,7 @@ function itShouldCreateSheetsChart() {
const presentationId = helpers.createTestPresentation();
const pageIds = helpers.addSlides(presentationId, 1, 'BLANK');
const pageId = pageIds[0];
const response = snippets.createSheetsChart(presentationId, pageId, DATA_SPREADSHEET_ID, CHART_ID);
const response = createSheetsChart(presentationId, pageId, DATA_SPREADSHEET_ID, CHART_ID);
expectToEqual(1, response.replies.length);
const chartId = response.replies[0].createSheetsChart.objectId;
expectToExist(chartId);
Expand All @@ -217,6 +216,6 @@ function itShouldRefreshSheetsChart() {
const pageId = pageIds[0];
const sheetChartId = helpers.createTestSheetsChart(presentationId, pageId, DATA_SPREADSHEET_ID,
CHART_ID);
const response = snippets.refreshSheetsChart(presentationId, sheetChartId);
const response = refreshSheetsChart(presentationId, sheetChartId);
expectToEqual(1, response.replies.length);
}
}

0 comments on commit 87570fe

Please sign in to comment.