Skip to content

Commit f41be36

Browse files
google-labs-jules[bot]jpoehneltvinay-google
authored
chore: Code Cleanup (#564)
* fix: force https * feat: Replace Logger.log with console.log and var with let/const Replaced all instances of `Logger.log` with `console.log` and `var` with either `let` or `const` across the entire codebase. This change modernizes the code and improves its readability and maintainability. It also ensures that all variables are properly scoped, which can help to prevent bugs. --------- Co-authored-by: Justin Poehnelt <jpoehnelt@google.com> Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: Vinay Vyas <69166360+vinay-google@users.noreply.github.com>
1 parent 34d0e2d commit f41be36

File tree

11 files changed

+203
-203
lines changed

11 files changed

+203
-203
lines changed

advanced/driveActivity.gs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@
1919
* unique users that performed the activity.
2020
*/
2121
function getUsersActivity() {
22-
var fileId = 'YOUR_FILE_ID_HERE';
22+
const fileId = 'YOUR_FILE_ID_HERE';
2323

24-
var pageToken;
25-
var users = {};
24+
let pageToken;
25+
const users = {};
2626
do {
27-
var result = AppsActivity.Activities.list({
27+
let result = AppsActivity.Activities.list({
2828
'drive.fileId': fileId,
2929
'source': 'drive.google.com',
3030
'pageToken': pageToken
3131
});
32-
var activities = result.activities;
33-
for (var i = 0; i < activities.length; i++) {
34-
var events = activities[i].singleEvents;
35-
for (var j = 0; j < events.length; j++) {
36-
var event = events[j];
32+
const activities = result.activities;
33+
for (let i = 0; i < activities.length; i++) {
34+
const events = activities[i].singleEvents;
35+
for (let j = 0; j < events.length; j++) {
36+
const event = events[j];
3737
users[event.user.name] = true;
3838
}
3939
}

advanced/iot.gs

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
* Lists the registries for the configured project and region.
1919
*/
2020
function listRegistries() {
21-
console.log(response);
22-
var projectId = 'your-project-id';
23-
var cloudRegion = 'us-central1';
24-
var parent = 'projects/' + projectId + '/locations/' + cloudRegion;
21+
const projectId = 'your-project-id';
22+
const cloudRegion = 'us-central1';
23+
const parent = 'projects/' + projectId + '/locations/' + cloudRegion;
2524

26-
var response = CloudIoT.Projects.Locations.Registries.list(parent);
25+
const response = CloudIoT.Projects.Locations.Registries.list(parent);
26+
console.log(response);
2727
if (response.deviceRegistries) {
2828
response.deviceRegistries.forEach(
2929
function(registry) {
@@ -38,23 +38,23 @@ function listRegistries() {
3838
* Creates a registry.
3939
*/
4040
function createRegistry() {
41-
var cloudRegion = 'us-central1';
42-
var name = 'your-registry-name';
43-
var projectId = 'your-project-id';
44-
var topic = 'your-pubsub-topic';
41+
const cloudRegion = 'us-central1';
42+
const name = 'your-registry-name';
43+
const projectId = 'your-project-id';
44+
const topic = 'your-pubsub-topic';
4545

46-
var pubsubTopic = 'projects/' + projectId + '/topics/' + topic;
46+
const pubsubTopic = 'projects/' + projectId + '/topics/' + topic;
4747

48-
var registry = {
48+
const registry = {
4949
'eventNotificationConfigs': [{
5050
// From - https://console.cloud.google.com/cloudpubsub
5151
pubsubTopicName: pubsubTopic
5252
}],
5353
'id': name
5454
};
55-
var parent = 'projects/' + projectId + '/locations/' + cloudRegion;
55+
const parent = 'projects/' + projectId + '/locations/' + cloudRegion;
5656

57-
var response = CloudIoT.Projects.Locations.Registries.create(registry, parent);
57+
const response = CloudIoT.Projects.Locations.Registries.create(registry, parent);
5858
console.log('Created registry: ' + response.id);
5959
}
6060
// [END apps_script_iot_create_registry]
@@ -64,14 +64,14 @@ function createRegistry() {
6464
* Describes a registry.
6565
*/
6666
function getRegistry() {
67-
var cloudRegion = 'us-central1';
68-
var name = 'your-registry-name';
69-
var projectId = 'your-project-id';
67+
const cloudRegion = 'us-central1';
68+
const name = 'your-registry-name';
69+
const projectId = 'your-project-id';
7070

71-
var parent = 'projects/' + projectId + '/locations/' + cloudRegion;
72-
var registryName = parent + '/registries/' + name;
71+
const parent = 'projects/' + projectId + '/locations/' + cloudRegion;
72+
const registryName = parent + '/registries/' + name;
7373

74-
var response = CloudIoT.Projects.Locations.Registries.get(registryName);
74+
const response = CloudIoT.Projects.Locations.Registries.get(registryName);
7575
console.log('Retrieved registry: ' + response.id);
7676
}
7777
// [END apps_script_iot_get_registry]
@@ -81,14 +81,14 @@ function getRegistry() {
8181
* Deletes a registry.
8282
*/
8383
function deleteRegistry() {
84-
var cloudRegion = 'us-central1';
85-
var name = 'your-registry-name';
86-
var projectId = 'your-project-id';
84+
const cloudRegion = 'us-central1';
85+
const name = 'your-registry-name';
86+
const projectId = 'your-project-id';
8787

88-
var parent = 'projects/' + projectId + '/locations/' + cloudRegion;
89-
var registryName = parent + '/registries/' + name;
88+
const parent = 'projects/' + projectId + '/locations/' + cloudRegion;
89+
const registryName = parent + '/registries/' + name;
9090

91-
var response = CloudIoT.Projects.Locations.Registries.remove(registryName);
91+
const response = CloudIoT.Projects.Locations.Registries.remove(registryName);
9292
// Successfully removed registry if exception was not thrown.
9393
console.log('Deleted registry: ' + name);
9494
}
@@ -99,14 +99,14 @@ function deleteRegistry() {
9999
* Lists the devices in the given registry.
100100
*/
101101
function listDevicesForRegistry() {
102-
var cloudRegion = 'us-central1';
103-
var name = 'your-registry-name';
104-
var projectId = 'your-project-id';
102+
const cloudRegion = 'us-central1';
103+
const name = 'your-registry-name';
104+
const projectId = 'your-project-id';
105105

106-
var parent = 'projects/' + projectId + '/locations/' + cloudRegion;
107-
var registryName = parent + '/registries/' + name;
106+
const parent = 'projects/' + projectId + '/locations/' + cloudRegion;
107+
const registryName = parent + '/registries/' + name;
108108

109-
var response = CloudIoT.Projects.Locations.Registries.Devices.list(registryName);
109+
const response = CloudIoT.Projects.Locations.Registries.Devices.list(registryName);
110110

111111
console.log('Registry contains the following devices: ');
112112
if (response.devices) {
@@ -123,23 +123,23 @@ function listDevicesForRegistry() {
123123
* Creates a device without credentials.
124124
*/
125125
function createDevice() {
126-
var cloudRegion = 'us-central1';
127-
var name = 'your-device-name';
128-
var projectId = 'your-project-id';
129-
var registry = 'your-registry-name';
126+
const cloudRegion = 'us-central1';
127+
const name = 'your-device-name';
128+
const projectId = 'your-project-id';
129+
const registry = 'your-registry-name';
130130

131131
console.log('Creating device: ' + name + ' in Registry: ' + registry);
132-
var parent = 'projects/' + projectId + '/locations/' + cloudRegion + '/registries/' + registry;
132+
const parent = 'projects/' + projectId + '/locations/' + cloudRegion + '/registries/' + registry;
133133

134-
var device = {
134+
const device = {
135135
id: name,
136136
gatewayConfig: {
137137
gatewayType: 'NON_GATEWAY',
138138
gatewayAuthMethod: 'ASSOCIATION_ONLY'
139139
}
140140
};
141141

142-
var response = CloudIoT.Projects.Locations.Registries.Devices.create(device, parent);
142+
const response = CloudIoT.Projects.Locations.Registries.Devices.create(device, parent);
143143
console.log('Created device:' + response.name);
144144
}
145145
// [END apps_script_iot_create_unauth_device]
@@ -153,21 +153,21 @@ function createRsaDevice() {
153153
// openssl req -x509 -newkey rsa:2048 -days 3650 -keyout rsa_private.pem \
154154
// -nodes -out rsa_cert.pem -subj "/CN=unused"
155155
//
156-
// **NOTE** Be sure to insert the newline charaters in the string varant.
157-
var cert =
156+
// **NOTE** Be sure to insert the newline charaters in the string constant.
157+
const cert =
158158
'-----BEGIN CERTIFICATE-----\n' +
159159
'your-PUBLIC-certificate-b64-bytes\n' +
160160
'...\n' +
161161
'more-PUBLIC-certificate-b64-bytes==\n' +
162162
'-----END CERTIFICATE-----\n';
163163

164-
var cloudRegion = 'us-central1';
165-
var name = 'your-device-name';
166-
var projectId = 'your-project-id';
167-
var registry = 'your-registry-name';
164+
const cloudRegion = 'us-central1';
165+
const name = 'your-device-name';
166+
const projectId = 'your-project-id';
167+
const registry = 'your-registry-name';
168168

169-
var parent = 'projects/' + projectId + '/locations/' + cloudRegion + '/registries/' + registry;
170-
var device = {
169+
const parent = 'projects/' + projectId + '/locations/' + cloudRegion + '/registries/' + registry;
170+
const device = {
171171
id: name,
172172
gatewayConfig: {
173173
gatewayType: 'NON_GATEWAY',
@@ -181,7 +181,7 @@ function createRsaDevice() {
181181
}]
182182
};
183183

184-
var response = CloudIoT.Projects.Locations.Registries.Devices.create(device, parent);
184+
const response = CloudIoT.Projects.Locations.Registries.Devices.create(device, parent);
185185
console.log('Created device:' + response.name);
186186
}
187187
// [END apps_script_iot_create_rsa_device]
@@ -191,15 +191,15 @@ function createRsaDevice() {
191191
* Deletes a device from the given registry.
192192
*/
193193
function deleteDevice() {
194-
var cloudRegion = 'us-central1';
195-
var name = 'your-device-name';
196-
var projectId = 'your-project-id';
197-
var registry = 'your-registry-name';
194+
const cloudRegion = 'us-central1';
195+
const name = 'your-device-name';
196+
const projectId = 'your-project-id';
197+
const registry = 'your-registry-name';
198198

199-
var parent = 'projects/' + projectId + '/locations/' + cloudRegion + '/registries/' + registry;
200-
var deviceName = parent + '/devices/' + name;
199+
const parent = 'projects/' + projectId + '/locations/' + cloudRegion + '/registries/' + registry;
200+
const deviceName = parent + '/devices/' + name;
201201

202-
var response = CloudIoT.Projects.Locations.Registries.Devices.remove(deviceName);
202+
const response = CloudIoT.Projects.Locations.Registries.Devices.remove(deviceName);
203203
// If no exception thrown, device was successfully removed
204204
console.log('Successfully deleted device: ' + deviceName);
205205
}

0 commit comments

Comments
 (0)