|
1 | | -from __future__ import print_function |
2 | | -from googleapiclient.discovery import build |
3 | | -from httplib2 import Http |
4 | | -from oauth2client import file, client, tools |
| 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. |
5 | 14 |
|
6 | | -# If modifying these scopes, delete the file token.json. |
7 | | -SCOPES = 'https://www.googleapis.com/auth/classroom.courses' |
| 15 | +from __future__ import print_function |
8 | 16 |
|
9 | | -def main(): |
10 | | - """Shows basic usage of the Classroom API. |
11 | | - Prints the names of the first 10 courses the user has access to. |
12 | | - """ |
13 | | - # The file token.json stores the user's access and refresh tokens, and is |
14 | | - # created automatically when the authorization flow completes for the first |
15 | | - # time. |
16 | | - store = file.Storage('token.json') |
17 | | - print(store) |
18 | | - creds = None |
19 | | - if not creds or creds.invalid: |
20 | | - flow = client.flow_from_clientsecrets('credentials.json', SCOPES) |
21 | | - creds = tools.run_flow(flow, store) |
22 | | - # [START classroom_quickstart] |
23 | | - service = build('classroom', 'v1', http=creds.authorize(Http())) |
| 17 | +class ClassroomSnippets(object): |
| 18 | + def __init__(self, service): |
| 19 | + self.service = service |
24 | 20 |
|
25 | | - alias = 'd:school_math_101' |
26 | | - course = { |
27 | | - 'id': alias, |
28 | | - 'name': 'Math 101', |
29 | | - 'section': 'Period 2', |
30 | | - 'description': 'Course Description', |
31 | | - 'room': '301', |
32 | | - 'ownerId': 'teacherId' |
33 | | - } |
34 | | - try: |
35 | | - course = service.courses().create( |
36 | | - body=course).execute() |
37 | | - except: |
38 | | - print('Course Creation Failed') |
39 | | - # Handle error |
40 | | - # [END classroom_quickstart |
| 21 | + def add_alias_existing(self): |
| 22 | + """Shows basic usage of the Classroom API. |
| 23 | + Creates a course with alias specification. |
| 24 | + """ |
| 25 | + service = self.service |
| 26 | + # [START classroom_quickstart] |
| 27 | + alias = 'd:school_math_101' |
| 28 | + course = { |
| 29 | + 'id': alias, |
| 30 | + 'name': 'Math 101', |
| 31 | + 'section': 'Period 2', |
| 32 | + 'description': 'Course Description', |
| 33 | + 'room': '301', |
| 34 | + 'ownerId': 'teacherId' |
| 35 | + } |
| 36 | + try: |
| 37 | + course = service.courses().create( |
| 38 | + body=course).execute() |
| 39 | + except: |
| 40 | + print('Course Creation Failed') |
| 41 | + # [END classroom_quickstart] |
41 | 42 |
|
42 | | -if __name__ == '__main__': |
43 | | - main() |
| 43 | + def add_alias_new(self): |
| 44 | + # [START classroom_quickstart] |
| 45 | + service = self.service |
| 46 | + classroomCourseId = '123456' |
| 47 | + alias = 'd:school_math_101' |
| 48 | + courseAlias = { |
| 49 | + 'alias': alias |
| 50 | + } |
| 51 | + courseAlias = service.courses().aliases().create( |
| 52 | + courseId=classroomCourseId, |
| 53 | + body=courseAlias).execute() |
| 54 | + # [END classroom_quickstart |
0 commit comments