|
| 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