diff --git a/advanced/driveActivity.gs b/advanced/driveActivity.gs index 3d5f8bd0f..b139dfe72 100644 --- a/advanced/driveActivity.gs +++ b/advanced/driveActivity.gs @@ -19,21 +19,21 @@ * unique users that performed the activity. */ function getUsersActivity() { - var fileId = 'YOUR_FILE_ID_HERE'; + const fileId = 'YOUR_FILE_ID_HERE'; - var pageToken; - var users = {}; + let pageToken; + const users = {}; do { - var result = AppsActivity.Activities.list({ + let result = AppsActivity.Activities.list({ 'drive.fileId': fileId, 'source': 'drive.google.com', 'pageToken': pageToken }); - var activities = result.activities; - for (var i = 0; i < activities.length; i++) { - var events = activities[i].singleEvents; - for (var j = 0; j < events.length; j++) { - var event = events[j]; + const activities = result.activities; + for (let i = 0; i < activities.length; i++) { + const events = activities[i].singleEvents; + for (let j = 0; j < events.length; j++) { + const event = events[j]; users[event.user.name] = true; } } diff --git a/advanced/iot.gs b/advanced/iot.gs index 8087fd023..4f9739183 100644 --- a/advanced/iot.gs +++ b/advanced/iot.gs @@ -18,12 +18,12 @@ * Lists the registries for the configured project and region. */ function listRegistries() { - console.log(response); - var projectId = 'your-project-id'; - var cloudRegion = 'us-central1'; - var parent = 'projects/' + projectId + '/locations/' + cloudRegion; + const projectId = 'your-project-id'; + const cloudRegion = 'us-central1'; + const parent = 'projects/' + projectId + '/locations/' + cloudRegion; - var response = CloudIoT.Projects.Locations.Registries.list(parent); + const response = CloudIoT.Projects.Locations.Registries.list(parent); + console.log(response); if (response.deviceRegistries) { response.deviceRegistries.forEach( function(registry) { @@ -38,23 +38,23 @@ function listRegistries() { * Creates a registry. */ function createRegistry() { - var cloudRegion = 'us-central1'; - var name = 'your-registry-name'; - var projectId = 'your-project-id'; - var topic = 'your-pubsub-topic'; + const cloudRegion = 'us-central1'; + const name = 'your-registry-name'; + const projectId = 'your-project-id'; + const topic = 'your-pubsub-topic'; - var pubsubTopic = 'projects/' + projectId + '/topics/' + topic; + const pubsubTopic = 'projects/' + projectId + '/topics/' + topic; - var registry = { + const registry = { 'eventNotificationConfigs': [{ // From - https://console.cloud.google.com/cloudpubsub pubsubTopicName: pubsubTopic }], 'id': name }; - var parent = 'projects/' + projectId + '/locations/' + cloudRegion; + const parent = 'projects/' + projectId + '/locations/' + cloudRegion; - var response = CloudIoT.Projects.Locations.Registries.create(registry, parent); + const response = CloudIoT.Projects.Locations.Registries.create(registry, parent); console.log('Created registry: ' + response.id); } // [END apps_script_iot_create_registry] @@ -64,14 +64,14 @@ function createRegistry() { * Describes a registry. */ function getRegistry() { - var cloudRegion = 'us-central1'; - var name = 'your-registry-name'; - var projectId = 'your-project-id'; + const cloudRegion = 'us-central1'; + const name = 'your-registry-name'; + const projectId = 'your-project-id'; - var parent = 'projects/' + projectId + '/locations/' + cloudRegion; - var registryName = parent + '/registries/' + name; + const parent = 'projects/' + projectId + '/locations/' + cloudRegion; + const registryName = parent + '/registries/' + name; - var response = CloudIoT.Projects.Locations.Registries.get(registryName); + const response = CloudIoT.Projects.Locations.Registries.get(registryName); console.log('Retrieved registry: ' + response.id); } // [END apps_script_iot_get_registry] @@ -81,14 +81,14 @@ function getRegistry() { * Deletes a registry. */ function deleteRegistry() { - var cloudRegion = 'us-central1'; - var name = 'your-registry-name'; - var projectId = 'your-project-id'; + const cloudRegion = 'us-central1'; + const name = 'your-registry-name'; + const projectId = 'your-project-id'; - var parent = 'projects/' + projectId + '/locations/' + cloudRegion; - var registryName = parent + '/registries/' + name; + const parent = 'projects/' + projectId + '/locations/' + cloudRegion; + const registryName = parent + '/registries/' + name; - var response = CloudIoT.Projects.Locations.Registries.remove(registryName); + const response = CloudIoT.Projects.Locations.Registries.remove(registryName); // Successfully removed registry if exception was not thrown. console.log('Deleted registry: ' + name); } @@ -99,14 +99,14 @@ function deleteRegistry() { * Lists the devices in the given registry. */ function listDevicesForRegistry() { - var cloudRegion = 'us-central1'; - var name = 'your-registry-name'; - var projectId = 'your-project-id'; + const cloudRegion = 'us-central1'; + const name = 'your-registry-name'; + const projectId = 'your-project-id'; - var parent = 'projects/' + projectId + '/locations/' + cloudRegion; - var registryName = parent + '/registries/' + name; + const parent = 'projects/' + projectId + '/locations/' + cloudRegion; + const registryName = parent + '/registries/' + name; - var response = CloudIoT.Projects.Locations.Registries.Devices.list(registryName); + const response = CloudIoT.Projects.Locations.Registries.Devices.list(registryName); console.log('Registry contains the following devices: '); if (response.devices) { @@ -123,15 +123,15 @@ function listDevicesForRegistry() { * Creates a device without credentials. */ function createDevice() { - var cloudRegion = 'us-central1'; - var name = 'your-device-name'; - var projectId = 'your-project-id'; - var registry = 'your-registry-name'; + const cloudRegion = 'us-central1'; + const name = 'your-device-name'; + const projectId = 'your-project-id'; + const registry = 'your-registry-name'; console.log('Creating device: ' + name + ' in Registry: ' + registry); - var parent = 'projects/' + projectId + '/locations/' + cloudRegion + '/registries/' + registry; + const parent = 'projects/' + projectId + '/locations/' + cloudRegion + '/registries/' + registry; - var device = { + const device = { id: name, gatewayConfig: { gatewayType: 'NON_GATEWAY', @@ -139,7 +139,7 @@ function createDevice() { } }; - var response = CloudIoT.Projects.Locations.Registries.Devices.create(device, parent); + const response = CloudIoT.Projects.Locations.Registries.Devices.create(device, parent); console.log('Created device:' + response.name); } // [END apps_script_iot_create_unauth_device] @@ -153,21 +153,21 @@ function createRsaDevice() { // openssl req -x509 -newkey rsa:2048 -days 3650 -keyout rsa_private.pem \ // -nodes -out rsa_cert.pem -subj "/CN=unused" // - // **NOTE** Be sure to insert the newline charaters in the string varant. - var cert = + // **NOTE** Be sure to insert the newline charaters in the string constant. + const cert = '-----BEGIN CERTIFICATE-----\n' + 'your-PUBLIC-certificate-b64-bytes\n' + '...\n' + 'more-PUBLIC-certificate-b64-bytes==\n' + '-----END CERTIFICATE-----\n'; - var cloudRegion = 'us-central1'; - var name = 'your-device-name'; - var projectId = 'your-project-id'; - var registry = 'your-registry-name'; + const cloudRegion = 'us-central1'; + const name = 'your-device-name'; + const projectId = 'your-project-id'; + const registry = 'your-registry-name'; - var parent = 'projects/' + projectId + '/locations/' + cloudRegion + '/registries/' + registry; - var device = { + const parent = 'projects/' + projectId + '/locations/' + cloudRegion + '/registries/' + registry; + const device = { id: name, gatewayConfig: { gatewayType: 'NON_GATEWAY', @@ -181,7 +181,7 @@ function createRsaDevice() { }] }; - var response = CloudIoT.Projects.Locations.Registries.Devices.create(device, parent); + const response = CloudIoT.Projects.Locations.Registries.Devices.create(device, parent); console.log('Created device:' + response.name); } // [END apps_script_iot_create_rsa_device] @@ -191,15 +191,15 @@ function createRsaDevice() { * Deletes a device from the given registry. */ function deleteDevice() { - var cloudRegion = 'us-central1'; - var name = 'your-device-name'; - var projectId = 'your-project-id'; - var registry = 'your-registry-name'; + const cloudRegion = 'us-central1'; + const name = 'your-device-name'; + const projectId = 'your-project-id'; + const registry = 'your-registry-name'; - var parent = 'projects/' + projectId + '/locations/' + cloudRegion + '/registries/' + registry; - var deviceName = parent + '/devices/' + name; + const parent = 'projects/' + projectId + '/locations/' + cloudRegion + '/registries/' + registry; + const deviceName = parent + '/devices/' + name; - var response = CloudIoT.Projects.Locations.Registries.Devices.remove(deviceName); + const response = CloudIoT.Projects.Locations.Registries.Devices.remove(deviceName); // If no exception thrown, device was successfully removed console.log('Successfully deleted device: ' + deviceName); } diff --git a/data-studio/auth.gs b/data-studio/auth.gs index 5035107ee..c595c188a 100644 --- a/data-studio/auth.gs +++ b/data-studio/auth.gs @@ -20,7 +20,7 @@ * @return {object} The Auth type. */ function getAuthType() { - var cc = DataStudioApp.createCommunityConnector(); + const cc = DataStudioApp.createCommunityConnector(); return cc.newAuthTypeResponse() .setAuthType(cc.AuthType.OAUTH2) .build(); @@ -33,7 +33,7 @@ function getAuthType() { * @return {object} The Auth type. */ function getAuthType() { - var cc = DataStudioApp.createCommunityConnector(); + const cc = DataStudioApp.createCommunityConnector(); return cc.newAuthTypeResponse() .setAuthType(cc.AuthType.PATH_USER_PASS) .setHelpUrl('https://www.example.org/connector-auth-help') @@ -47,7 +47,7 @@ function getAuthType() { * @return {object} The Auth type. */ function getAuthType() { - var cc = DataStudioApp.createCommunityConnector(); + const cc = DataStudioApp.createCommunityConnector(); return cc.newAuthTypeResponse() .setAuthType(cc.AuthType.USER_PASS) .setHelpUrl('https://www.example.org/connector-auth-help') @@ -61,7 +61,7 @@ function getAuthType() { * @return {object} The Auth type. */ function getAuthType() { - var cc = DataStudioApp.createCommunityConnector(); + const cc = DataStudioApp.createCommunityConnector(); return cc.newAuthTypeResponse() .setAuthType(cc.AuthType.USER_TOKEN) .setHelpUrl('https://www.example.org/connector-auth-help') @@ -75,7 +75,7 @@ function getAuthType() { * @return {object} The Auth type. */ function getAuthType() { - var cc = DataStudioApp.createCommunityConnector(); + const cc = DataStudioApp.createCommunityConnector(); return cc.newAuthTypeResponse() .setAuthType(cc.AuthType.KEY) .setHelpUrl('https://www.example.org/connector-auth-help') @@ -89,7 +89,7 @@ function getAuthType() { * @return {object} The Auth type. */ function getAuthType() { - var cc = DataStudioApp.createCommunityConnector(); + const cc = DataStudioApp.createCommunityConnector(); return cc.newAuthTypeResponse() .setAuthType(cc.AuthType.NONE) .build(); @@ -110,7 +110,7 @@ function resetAuth() { * Resets the auth service. */ function resetAuth() { - var userProperties = PropertiesService.getUserProperties(); + const userProperties = PropertiesService.getUserProperties(); userProperties.deleteProperty('dscc.path'); userProperties.deleteProperty('dscc.username'); userProperties.deleteProperty('dscc.password'); @@ -122,7 +122,7 @@ function resetAuth() { * Resets the auth service. */ function resetAuth() { - var userProperties = PropertiesService.getUserProperties(); + const userProperties = PropertiesService.getUserProperties(); userProperties.deleteProperty('dscc.username'); userProperties.deleteProperty('dscc.password'); } @@ -133,7 +133,7 @@ function resetAuth() { * Resets the auth service. */ function resetAuth() { - var userTokenProperties = PropertiesService.getUserProperties(); + const userTokenProperties = PropertiesService.getUserProperties(); userTokenProperties.deleteProperty('dscc.username'); userTokenProperties.deleteProperty('dscc.password'); } @@ -144,7 +144,7 @@ function resetAuth() { * Resets the auth service. */ function resetAuth() { - var userProperties = PropertiesService.getUserProperties(); + const userProperties = PropertiesService.getUserProperties(); userProperties.deleteProperty('dscc.key'); } // [END apps_script_data_studio_auth_reset_key] @@ -165,10 +165,10 @@ function isAuthValid() { * @return {boolean} True if the auth service has access. */ function isAuthValid() { - var userProperties = PropertiesService.getUserProperties(); - var path = userProperties.getProperty('dscc.path'); - var userName = userProperties.getProperty('dscc.username'); - var password = userProperties.getProperty('dscc.password'); + const userProperties = PropertiesService.getUserProperties(); + const path = userProperties.getProperty('dscc.path'); + const userName = userProperties.getProperty('dscc.username'); + const password = userProperties.getProperty('dscc.password'); // This assumes you have a validateCredentials function that // can validate if the userName and password are correct. return validateCredentials(path, userName, password); @@ -181,9 +181,9 @@ function isAuthValid() { * @return {boolean} True if the auth service has access. */ function isAuthValid() { - var userProperties = PropertiesService.getUserProperties(); - var userName = userProperties.getProperty('dscc.username'); - var password = userProperties.getProperty('dscc.password'); + const userProperties = PropertiesService.getUserProperties(); + const userName = userProperties.getProperty('dscc.username'); + const password = userProperties.getProperty('dscc.password'); // This assumes you have a validateCredentials function that // can validate if the userName and password are correct. return validateCredentials(userName, password); @@ -196,9 +196,9 @@ function isAuthValid() { * @return {boolean} True if the auth service has access. */ function isAuthValid() { - var userProperties = PropertiesService.getUserProperties(); - var userName = userProperties.getProperty('dscc.username'); - var token = userProperties.getProperty('dscc.token'); + const userProperties = PropertiesService.getUserProperties(); + const userName = userProperties.getProperty('dscc.username'); + const token = userProperties.getProperty('dscc.token'); // This assumes you have a validateCredentials function that // can validate if the userName and token are correct. return validateCredentials(userName, token); @@ -211,8 +211,8 @@ function isAuthValid() { * @return {boolean} True if the auth service has access. */ function isAuthValid() { - var userProperties = PropertiesService.getUserProperties(); - var key = userProperties.getProperty('dscc.key'); + const userProperties = PropertiesService.getUserProperties(); + const key = userProperties.getProperty('dscc.key'); // This assumes you have a validateKey function that can validate // if the key is valid. return validateKey(key); @@ -243,7 +243,7 @@ function getOAuthService() { * @return {HtmlOutput} The HTML output to show to the user. */ function authCallback(request) { - var authorized = getOAuthService().handleCallback(request); + const authorized = getOAuthService().handleCallback(request); if (authorized) { return HtmlService.createHtmlOutput('Success! You can close this tab.'); } else { @@ -270,22 +270,22 @@ function get3PAuthorizationUrls() { * @return {object} An object with an errorCode. */ function setCredentials(request) { - var creds = request.userPass; - var path = creds.path; - var username = creds.username; - var password = creds.password; + const creds = request.userPass; + const path = creds.path; + const username = creds.username; + const password = creds.password; // Optional // Check if the provided path, username and password are valid through // a call to your service. You would have to have a `checkForValidCreds` // function defined for this to work. - var validCreds = checkForValidCreds(path, username, password); + const validCreds = checkForValidCreds(path, username, password); if (!validCreds) { return { errorCode: 'INVALID_CREDENTIALS' }; } - var userProperties = PropertiesService.getUserProperties(); + const userProperties = PropertiesService.getUserProperties(); userProperties.setProperty('dscc.path', path); userProperties.setProperty('dscc.username', username); userProperties.setProperty('dscc.password', password); @@ -302,21 +302,21 @@ function setCredentials(request) { * @return {object} An object with an errorCode. */ function setCredentials(request) { - var creds = request.userPass; - var username = creds.username; - var password = creds.password; + const creds = request.userPass; + const username = creds.username; + const password = creds.password; // Optional // Check if the provided username and password are valid through a // call to your service. You would have to have a `checkForValidCreds` // function defined for this to work. - var validCreds = checkForValidCreds(username, password); + const validCreds = checkForValidCreds(username, password); if (!validCreds) { return { errorCode: 'INVALID_CREDENTIALS' }; } - var userProperties = PropertiesService.getUserProperties(); + const userProperties = PropertiesService.getUserProperties(); userProperties.setProperty('dscc.username', username); userProperties.setProperty('dscc.password', password); return { @@ -332,21 +332,21 @@ function setCredentials(request) { * @return {object} An object with an errorCode. */ function setCredentials(request) { - var creds = request.userToken; - var username = creds.username; - var token = creds.token; + const creds = request.userToken; + const username = creds.username; + const token = creds.token; // Optional // Check if the provided username and token are valid through a // call to your service. You would have to have a `checkForValidCreds` // function defined for this to work. - var validCreds = checkForValidCreds(username, token); + const validCreds = checkForValidCreds(username, token); if (!validCreds) { return { errorCode: 'INVALID_CREDENTIALS' }; } - var userProperties = PropertiesService.getUserProperties(); + const userProperties = PropertiesService.getUserProperties(); userProperties.setProperty('dscc.username', username); userProperties.setProperty('dscc.token', token); return { @@ -362,19 +362,19 @@ function setCredentials(request) { * @return {object} An object with an errorCode. */ function setCredentials(request) { - var key = request.key; + const key = request.key; // Optional // Check if the provided key is valid through a call to your service. // You would have to have a `checkForValidKey` function defined for // this to work. - var validKey = checkForValidKey(key); + const validKey = checkForValidKey(key); if (!validKey) { return { errorCode: 'INVALID_CREDENTIALS' }; } - var userProperties = PropertiesService.getUserProperties(); + const userProperties = PropertiesService.getUserProperties(); userProperties.setProperty('dscc.key', key); return { errorCode: 'NONE' diff --git a/data-studio/build.gs b/data-studio/build.gs index ec845dba6..82a6d1299 100644 --- a/data-studio/build.gs +++ b/data-studio/build.gs @@ -21,8 +21,8 @@ * @see https://developers.google.com/apps-script/reference/data-studio/config */ function getConfig() { - var cc = DataStudioApp.createCommunityConnector(); - var config = cc.getConfig(); + const cc = DataStudioApp.createCommunityConnector(); + const config = cc.getConfig(); config.newInfo() .setId('instructions') @@ -48,10 +48,10 @@ function getConfig() { * @see https://developers.google.com/apps-script/reference/data-studio/fields */ function getFields() { - var cc = DataStudioApp.createCommunityConnector(); - var fields = cc.getFields(); - var types = cc.FieldType; - var aggregations = cc.AggregationType; + const cc = DataStudioApp.createCommunityConnector(); + const fields = cc.getFields(); + const types = cc.FieldType; + const aggregations = cc.AggregationType; fields.newDimension() .setId('packageName') @@ -78,7 +78,7 @@ function getFields() { * @return {object} The schema. */ function getSchema(request) { - var fields = getFields().build(); + const fields = getFields().build(); return {'schema': fields}; } // [END apps_script_data_studio_build_get_fields] @@ -94,7 +94,7 @@ function getSchema(request) { function responseToRows(requestedFields, response, packageName) { // Transform parsed data and filter for requested fields return response.map(function(dailyDownload) { - var row = []; + let row = []; requestedFields.asArray().forEach(function(field) { switch (field.getId()) { case 'day': @@ -117,13 +117,13 @@ function responseToRows(requestedFields, response, packageName) { * @return {object} The data. */ function getData(request) { - var requestedFieldIds = request.fields.map(function(field) { + const requestedFieldIds = request.fields.map(function(field) { return field.name; }); - var requestedFields = getFields().forIds(requestedFieldIds); + const requestedFields = getFields().forIds(requestedFieldIds); // Fetch and parse data from API - var url = [ + const url = [ 'https://api.npmjs.org/downloads/range/', request.dateRange.startDate, ':', @@ -131,9 +131,9 @@ function getData(request) { '/', request.configParams.package ]; - var response = UrlFetchApp.fetch(url.join('')); - var parsedResponse = JSON.parse(response).downloads; - var rows = responseToRows(requestedFields, parsedResponse, request.configParams.package); + const response = UrlFetchApp.fetch(url.join('')); + const parsedResponse = JSON.parse(response).downloads; + const rows = responseToRows(requestedFields, parsedResponse, request.configParams.package); return { schema: requestedFields.build(), @@ -148,7 +148,7 @@ function getData(request) { * @return {object} The auth type. */ function getAuthType() { - var cc = DataStudioApp.createCommunityConnector(); + const cc = DataStudioApp.createCommunityConnector(); return cc.newAuthTypeResponse() .setAuthType(cc.AuthType.NONE) .build(); diff --git a/data-studio/errors.gs b/data-studio/errors.gs index e6cdc1719..f48fd1a7c 100644 --- a/data-studio/errors.gs +++ b/data-studio/errors.gs @@ -57,7 +57,7 @@ function throwConnectorError(message, userSafe) { * the log entry. */ function logConnectorError(originalError, message) { - var logEntry = [ + const logEntry = [ 'Original error (Message): ', originalError, '(', message, ')' diff --git a/data-studio/semantics.gs b/data-studio/semantics.gs index 426eb47e1..8b6af6837 100644 --- a/data-studio/semantics.gs +++ b/data-studio/semantics.gs @@ -15,7 +15,7 @@ */ // [START apps_script_data_studio_manual] -var schema = [ +const schema = [ { 'name': 'Income', 'label': 'Income (in USD)', diff --git a/forms-api/demos/AppsScriptFormsAPIWebApp/FormsAPI.gs b/forms-api/demos/AppsScriptFormsAPIWebApp/FormsAPI.gs index 5be743b4e..6e36d003c 100644 --- a/forms-api/demos/AppsScriptFormsAPIWebApp/FormsAPI.gs +++ b/forms-api/demos/AppsScriptFormsAPIWebApp/FormsAPI.gs @@ -42,7 +42,7 @@ function create(title) { }; console.log('Forms API POST options was: ' + JSON.stringify(options)); - let response = UrlFetchApp.fetch(formsAPIUrl, options); + const response = UrlFetchApp.fetch(formsAPIUrl, options); console.log('Response from Forms API was: ' + JSON.stringify(response)); return ('' + response); @@ -64,7 +64,7 @@ function get(formId) { }; try { - let response = UrlFetchApp.fetch(formsAPIUrl + formId, options); + const response = UrlFetchApp.fetch(formsAPIUrl + formId, options); console.log('Response from Forms API was: ' + response); return ('' + response); } catch (e) { @@ -103,7 +103,7 @@ function batchUpdate(formId) { 'muteHttpExceptions': true, }; - let response = UrlFetchApp.fetch(formsAPIUrl + formId + ':batchUpdate', + const response = UrlFetchApp.fetch(formsAPIUrl + formId + ':batchUpdate', options); console.log('Response code from API: ' + response.getResponseCode()); return (response.getResponseCode()); @@ -116,7 +116,7 @@ function batchUpdate(formId) { function responsesGet(formId, responseId) { const accessToken = ScriptApp.getOAuthToken(); - var options = { + const options = { 'headers': { Authorization: 'Bearer ' + accessToken, Accept: 'application/json' @@ -125,7 +125,7 @@ function responsesGet(formId, responseId) { }; try { - var response = UrlFetchApp.fetch(formsAPIUrl + formId + '/' + 'responses/' + + const response = UrlFetchApp.fetch(formsAPIUrl + formId + '/' + 'responses/' + responseId, options); console.log('Response from Forms.responses.get was: ' + response); return ('' + response); @@ -142,7 +142,7 @@ function responsesGet(formId, responseId) { function responsesList(formId) { const accessToken = ScriptApp.getOAuthToken(); - var options = { + const options = { 'headers': { Authorization: 'Bearer ' + accessToken, Accept: 'application/json' @@ -151,7 +151,7 @@ function responsesList(formId) { }; try { - var response = UrlFetchApp.fetch(formsAPIUrl + formId + '/' + 'responses', + const response = UrlFetchApp.fetch(formsAPIUrl + formId + '/' + 'responses', options); console.log('Response from Forms.responses was: ' + response); return ('' + response); @@ -166,9 +166,9 @@ function responsesList(formId) { * POST https://forms.googleapis.com/v1/forms/{formId}/watches */ function createWatch(formId) { - let accessToken = ScriptApp.getOAuthToken(); + const accessToken = ScriptApp.getOAuthToken(); - var myWatch = { + const myWatch = { 'watch': { 'target': { 'topic': { @@ -180,7 +180,7 @@ function createWatch(formId) { }; console.log('myWatch is: ' + JSON.stringify(myWatch)); - var options = { + const options = { 'headers': { Authorization: 'Bearer ' + accessToken }, @@ -192,7 +192,7 @@ function createWatch(formId) { console.log('options are: ' + JSON.stringify(options)); console.log('formsAPIURL was: ' + formsAPIUrl); - var response = UrlFetchApp.fetch(formsAPIUrl + formId + '/' + 'watches', + const response = UrlFetchApp.fetch(formsAPIUrl + formId + '/' + 'watches', options); console.log(response); return ('' + response); @@ -203,11 +203,11 @@ function createWatch(formId) { * DELETE https://forms.googleapis.com/v1/forms/{formId}/watches/{watchId} */ function deleteWatch(formId, watchId) { - let accessToken = ScriptApp.getOAuthToken(); + const accessToken = ScriptApp.getOAuthToken(); console.log('formsAPIUrl is: ' + formsAPIUrl); - var options = { + const options = { 'headers': { Authorization: 'Bearer ' + accessToken, Accept: 'application/json' @@ -217,7 +217,7 @@ function deleteWatch(formId, watchId) { }; try { - var response = UrlFetchApp.fetch(formsAPIUrl + formId + '/' + 'watches/' + + const response = UrlFetchApp.fetch(formsAPIUrl + formId + '/' + 'watches/' + watchId, options); console.log(response); return ('' + response); @@ -234,8 +234,8 @@ function deleteWatch(formId, watchId) { */ function watchesList(formId) { console.log('formId is: ' + formId); - let accessToken = ScriptApp.getOAuthToken(); - var options = { + const accessToken = ScriptApp.getOAuthToken(); + const options = { 'headers': { Authorization: 'Bearer ' + accessToken, Accept: 'application/json' @@ -243,7 +243,7 @@ function watchesList(formId) { 'method': 'get' }; try { - var response = UrlFetchApp.fetch(formsAPIUrl + formId + '/' + 'watches', + const response = UrlFetchApp.fetch(formsAPIUrl + formId + '/' + 'watches', options); console.log(response); return ('' + response); @@ -258,9 +258,9 @@ function watchesList(formId) { * POST https://forms.googleapis.com/v1/forms/{formId}/watches/{watchId}:renew */ function renewWatch(formId, watchId) { - let accessToken = ScriptApp.getOAuthToken(); + const accessToken = ScriptApp.getOAuthToken(); - var options = { + const options = { 'headers': { Authorization: 'Bearer ' + accessToken, Accept: 'application/json' @@ -269,7 +269,7 @@ function renewWatch(formId, watchId) { }; try { - var response = UrlFetchApp.fetch(formsAPIUrl + formId + '/' + 'watches/' + + const response = UrlFetchApp.fetch(formsAPIUrl + formId + '/' + 'watches/' + watchId + ':renew', options); console.log(response); return ('' + response); diff --git a/forms-api/demos/AppsScriptFormsAPIWebApp/Main.html b/forms-api/demos/AppsScriptFormsAPIWebApp/Main.html index 8612e1b37..b14d484bb 100644 --- a/forms-api/demos/AppsScriptFormsAPIWebApp/Main.html +++ b/forms-api/demos/AppsScriptFormsAPIWebApp/Main.html @@ -97,9 +97,9 @@ } function create() { - var status = document.getElementById('status'); + const status = document.getElementById('status'); status.innerHTML = "Creating new form..."; - var newFormTitle = document.getElementById('newFormTitle'); + const newFormTitle = document.getElementById('newFormTitle'); google.script.run .withFailureHandler(function(error) { @@ -119,9 +119,9 @@ } function get() { - var status = document.getElementById('status'); + const status = document.getElementById('status'); status.innerHTML = "Get form by id..."; - var formId = document.getElementById('globalFormId'); + const formId = document.getElementById('globalFormId'); google.script.run .withFailureHandler(function(error) { @@ -135,9 +135,9 @@ } function batchUpdate() { - var status = document.getElementById('status'); + const status = document.getElementById('status'); status.innerHTML = "Batch update..."; - var formId = document.getElementById('globalFormId'); + const formId = document.getElementById('globalFormId'); google.script.run .withFailureHandler(function(error) { @@ -153,9 +153,9 @@ function responsesList() { - var status = document.getElementById('status'); + const status = document.getElementById('status'); status.innerHTML = "Get form by id..."; - var formId = document.getElementById('globalFormId'); + const formId = document.getElementById('globalFormId'); google.script.run .withFailureHandler(function(error) { @@ -169,10 +169,10 @@ } function responsesGet() { - var status = document.getElementById('status'); + const status = document.getElementById('status'); status.innerHTML = "Get response by id..."; - var formId = document.getElementById('globalFormId'); - var respId = document.getElementById('responseId'); + const formId = document.getElementById('globalFormId'); + const respId = document.getElementById('responseId'); google.script.run .withFailureHandler(function(error) { @@ -186,9 +186,9 @@ } function watchesList() { - var status = document.getElementById('status'); + const status = document.getElementById('status'); status.innerHTML = "Get watches ..."; - var formId = document.getElementById('globalFormId'); + const formId = document.getElementById('globalFormId'); google.script.run .withFailureHandler(function(error) { @@ -202,9 +202,9 @@ } function createWatch() { - var status = document.getElementById('status'); + const status = document.getElementById('status'); status.innerHTML = "Create watch ..."; - var formId = document.getElementById('globalFormId'); + const formId = document.getElementById('globalFormId'); google.script.run .withFailureHandler(function(error) { @@ -218,10 +218,10 @@ } function deleteWatch() { - var status = document.getElementById('status'); + const status = document.getElementById('status'); status.innerHTML = "Delete watch ..."; - var formId = document.getElementById('globalFormId'); - var watchId = document.getElementById('watchId'); + const formId = document.getElementById('globalFormId'); + const watchId = document.getElementById('watchId'); google.script.run .withFailureHandler(function(error) { @@ -235,10 +235,10 @@ } function renewWatch() { - var status = document.getElementById('status'); + const status = document.getElementById('status'); status.innerHTML = "Renew watch ..."; - var formId = document.getElementById('globalFormId'); - var watchId = document.getElementById('renewWatchId'); + const formId = document.getElementById('globalFormId'); + const watchId = document.getElementById('renewWatchId'); google.script.run .withFailureHandler(function(error) { diff --git a/forms-api/snippets/retrieve_all_responses.gs b/forms-api/snippets/retrieve_all_responses.gs index 78a55ceeb..c7d865e6d 100644 --- a/forms-api/snippets/retrieve_all_responses.gs +++ b/forms-api/snippets/retrieve_all_responses.gs @@ -15,21 +15,21 @@ # [START forms_retrieve_all_responses] function callFormsAPI() { console.log('Calling the Forms API!'); - var formId = ''; + const formId = ''; // Get OAuth Token - var OAuthToken = ScriptApp.getOAuthToken(); + const OAuthToken = ScriptApp.getOAuthToken(); console.log('OAuth token is: ' + OAuthToken); - var formsAPIUrl = 'https://forms.googleapis.com/v1/forms/' + formId + '/' + 'responses'; + const formsAPIUrl = 'https://forms.googleapis.com/v1/forms/' + formId + '/' + 'responses'; console.log('formsAPIUrl is: ' + formsAPIUrl); - var options = { + const options = { 'headers': { Authorization: 'Bearer ' + OAuthToken, Accept: 'application/json' }, 'method': 'get' }; -var response = UrlFetchApp.fetch(formsAPIUrl, options); +const response = UrlFetchApp.fetch(formsAPIUrl, options); console.log('Response from forms.responses was: ' + response); } # [END forms_retrieve_all_responses] diff --git a/slides/SpeakerNotesScript/scriptGen.gs b/slides/SpeakerNotesScript/scriptGen.gs index 7e4841d57..d89938f84 100644 --- a/slides/SpeakerNotesScript/scriptGen.gs +++ b/slides/SpeakerNotesScript/scriptGen.gs @@ -42,25 +42,25 @@ function onOpen(e) { * with the speaker notes for each slide. */ function generateSlidesScript() { - var presentation = SlidesApp.getActivePresentation(); - var docTitle = presentation.getName() + ' Script'; - var slides = presentation.getSlides(); + const presentation = SlidesApp.getActivePresentation(); + const docTitle = presentation.getName() + ' Script'; + const slides = presentation.getSlides(); // Creates a document in the user's home Drive directory. - var speakerNotesDoc = DocumentApp.create(docTitle); + const speakerNotesDoc = DocumentApp.create(docTitle); console.log('Created document with id %s', speakerNotesDoc.getId()); - var docBody = speakerNotesDoc.getBody(); - var header = docBody.appendParagraph(docTitle); + const docBody = speakerNotesDoc.getBody(); + const header = docBody.appendParagraph(docTitle); header.setHeading(DocumentApp.ParagraphHeading.HEADING1); // Iterate through each slide and extract the speaker notes // into the document body. - for (var i = 0; i < slides.length; i++) { - var section = docBody.appendParagraph('Slide ' + (i + 1)) + for (let i = 0; i < slides.length; i++) { + const section = docBody.appendParagraph('Slide ' + (i + 1)) .setHeading(DocumentApp.ParagraphHeading.HEADING2); - var notes = slides[i].getNotesPage().getSpeakerNotesShape().getText().asString(); + const notes = slides[i].getNotesPage().getSpeakerNotesShape().getText().asString(); docBody.appendParagraph(notes) .appendHorizontalRule(); } diff --git a/slides/imageSlides/imageSlides.gs b/slides/imageSlides/imageSlides.gs index 32dbd1b18..3214fa630 100644 --- a/slides/imageSlides/imageSlides.gs +++ b/slides/imageSlides/imageSlides.gs @@ -15,8 +15,8 @@ */ // [START apps_script_slides_image_create] -var NAME = 'My favorite images'; -var deck = SlidesApp.create(NAME); +const NAME = 'My favorite images'; +const deck = SlidesApp.create(NAME); // [END apps_script_slides_image_create] // [START apps_script_slides_image_add_image] @@ -26,8 +26,8 @@ var deck = SlidesApp.create(NAME); * @param {number} index The slide index to add the image to */ function addImageSlide(imageUrl, index) { - var slide = deck.appendSlide(SlidesApp.PredefinedLayout.BLANK); - var image = slide.insertImage(imageUrl); + const slide = deck.appendSlide(SlidesApp.PredefinedLayout.BLANK); + const image = slide.insertImage(imageUrl); } // [END apps_script_slides_image_add_image] @@ -36,14 +36,14 @@ var deck = SlidesApp.create(NAME); * Adds images to a slides presentation. */ function main() { - var images = [ + const images = [ 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', 'http://www.google.com/services/images/phone-animation-results_2x.png', 'http://www.google.com/services/images/section-work-card-img_2x.jpg', 'http://gsuite.google.com/img/icons/product-lockup.png', 'http://gsuite.google.com/img/home-hero_2x.jpg' ]; - var [title, subtitle] = deck.getSlides()[0].getPageElements(); + const [title, subtitle] = deck.getSlides()[0].getPageElements(); title.asShape().getText().setText(NAME); subtitle.asShape().getText().setText('Google Apps Script\nSlides Service demo'); images.forEach(addImageSlide); @@ -58,22 +58,22 @@ function main() { * @param {number} index The index into the array; unused (req'd by forEach) */ function addImageSlide(imageUrl, index) { - var slide = deck.appendSlide(SlidesApp.PredefinedLayout.BLANK); - var image = slide.insertImage(imageUrl); - var imgWidth = image.getWidth(); - var imgHeight = image.getHeight(); - var pageWidth = deck.getPageWidth(); - var pageHeight = deck.getPageHeight(); - var newX = pageWidth/2. - imgWidth/2.; - var newY = pageHeight/2. - imgHeight/2.; + const slide = deck.appendSlide(SlidesApp.PredefinedLayout.BLANK); + const image = slide.insertImage(imageUrl); + const imgWidth = image.getWidth(); + const imgHeight = image.getHeight(); + const pageWidth = deck.getPageWidth(); + const pageHeight = deck.getPageHeight(); + const newX = pageWidth/2. - imgWidth/2.; + const newY = pageHeight/2. - imgHeight/2.; image.setLeft(newX).setTop(newY); } // [END apps_script_slides_image_add_image_slide] // [START apps_script_slides_image_full_script] -var NAME = 'My favorite images'; -var presentation = SlidesApp.create(NAME); +const NAME = 'My favorite images'; +const presentation = SlidesApp.create(NAME); /** * Creates a single slide using the image from the given link; @@ -82,14 +82,14 @@ var presentation = SlidesApp.create(NAME); * @param {number} index The index into the array; unused (req'd by forEach) */ function addImageSlide(imageUrl, index) { - var slide = presentation.appendSlide(SlidesApp.PredefinedLayout.BLANK); - var image = slide.insertImage(imageUrl); - var imgWidth = image.getWidth(); - var imgHeight = image.getHeight(); - var pageWidth = presentation.getPageWidth(); - var pageHeight = presentation.getPageHeight(); - var newX = pageWidth/2. - imgWidth/2.; - var newY = pageHeight/2. - imgHeight/2.; + const slide = presentation.appendSlide(SlidesApp.PredefinedLayout.BLANK); + const image = slide.insertImage(imageUrl); + const imgWidth = image.getWidth(); + const imgHeight = image.getHeight(); + const pageWidth = presentation.getPageWidth(); + const pageHeight = presentation.getPageHeight(); + const newX = pageWidth/2. - imgWidth/2.; + const newY = pageHeight/2. - imgHeight/2.; image.setLeft(newX).setTop(newY); } @@ -98,14 +98,14 @@ function addImageSlide(imageUrl, index) { * main title & subtitle, and creation of individual slides for each image. */ function main() { - var images = [ + const images = [ 'http://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', 'http://www.google.com/services/images/phone-animation-results_2x.png', 'http://www.google.com/services/images/section-work-card-img_2x.jpg', 'http://gsuite.google.com/img/icons/product-lockup.png', 'http://gsuite.google.com/img/home-hero_2x.jpg' ]; - var [title, subtitle] = presentation.getSlides()[0].getPageElements(); + const [title, subtitle] = presentation.getSlides()[0].getPageElements(); title.asShape().getText().setText(NAME); subtitle.asShape().getText().setText('Google Apps Script\nSlides Service demo'); images.forEach(addImageSlide);