Skip to content

Commit 49c917f

Browse files
authored
Merge pull request googleworkspace#165 from lesley2958/master
Adds two snippets: 1. patch a course 2. add an alias to an existing course.
2 parents e87fd64 + cb67fe1 commit 49c917f

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

classroom/snippets/addAlias.gs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Copyright Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
// [START classroom_add_alias]
17+
/**
18+
* Updates the section and room of Google Classroom.
19+
*/
20+
function addAlias(course_id) {
21+
var alias = {
22+
'alias': 'p:bio_101'
23+
}
24+
try {
25+
var course_alias = Classroom.Courses.Aliases.create(resource=alias, courseId=course_id);
26+
Logger.log('%s successfully added as an alias!', course_alias.alias)
27+
} catch (err) {
28+
Logger.log("Request to add alias %s failed.", alias.alias)
29+
}
30+
}
31+
// [END classroom_add_alias]

classroom/snippets/patchCourse.gs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Copyright Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
// [START classroom_patch_course]
17+
/**
18+
* Updates the section and room of Google Classroom.
19+
*/
20+
function coursePatch(course_id) {
21+
var course = {
22+
'section': 'Period 3',
23+
'room': '302'
24+
};
25+
var mask = {
26+
updateMask: 'section,room'
27+
};
28+
var course = Classroom.Courses.patch(body=course, id=course_id, updateMask=mask);
29+
Logger.log('Course "%s" updated.', course.name);
30+
}
31+
// [END classroom_patch_course]

0 commit comments

Comments
 (0)