Skip to content

Commit 0ba02b5

Browse files
author
Eric Koleda
authored
Merge pull request googleworkspace#55 from lesley2958/master
added classroom snippets for managing new and existing aliases
2 parents 6e92563 + a609b2a commit 0ba02b5

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

classroom/snippets/snippets.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from __future__ import print_function
16+
from googleapiclient import errors
17+
18+
19+
class ClassroomSnippets(object):
20+
def __init__(self, service):
21+
self.service = service
22+
23+
def add_alias_new(self):
24+
"""
25+
Creates a course with alias specification.
26+
"""
27+
service = self.service
28+
# [START classroom_new_alias]
29+
alias = 'd:school_math_101'
30+
course = {
31+
'id': alias,
32+
'name': 'Math 101',
33+
'section': 'Period 2',
34+
'description': 'Course Description',
35+
'room': '301',
36+
'ownerId': 'me'
37+
}
38+
try:
39+
course = service.courses().create(
40+
body=course).execute()
41+
except errors.HttpError:
42+
print('Course Creation Failed')
43+
# [END classroom_new_alias]
44+
45+
def add_alias_existing(self):
46+
"""
47+
Adds alias to existing course.
48+
"""
49+
service = self.service
50+
# [START classroom_existing_alias]
51+
courseId = '123456'
52+
alias = 'd:school_math_101'
53+
courseAlias = {
54+
'alias': alias
55+
}
56+
try:
57+
courseAlias = service.courses().aliases().create(
58+
courseId=courseId,
59+
body=courseAlias).execute()
60+
except errors.HttpError:
61+
print('Alias Creation Failed')
62+
# [END classroom_existing_alias]

0 commit comments

Comments
 (0)