def get_role(self, account_id, role_id): """ Get information about a single role, for the passed Canvas account ID. https://canvas.instructure.com/doc/api/roles.html#method.role_overrides.show """ url = ACCOUNTS_API.format(account_id) + "/roles/{}".format(role_id) return CanvasRole(data=self._get_resource(url))
def get_grading_standard_for_account(self, account_id, grading_standard_id): """ Get a single grading standard in account context. https://canvas.instructure.com/doc/api/grading_standards.html#method.grading_standards_api.context_show """ url = ACCOUNTS_API.format(account_id) + "/grading_standards/{}".format( grading_standard_id) return GradingStandard(data=self._get_resource(url))
def create_course(self, account_id, course_name): """ Create a canvas course with the given subaccount id and course name. https://canvas.instructure.com/doc/api/courses.html#method.courses.create """ url = ACCOUNTS_API.format(account_id) + "/courses" body = {"course": {"name": course_name}} return CanvasCourse(data=self._post_resource(url, body))
def delete_report(self, report): """ Deletes a generated report instance. https://canvas.instructure.com/doc/api/account_reports.html#method.account_reports.destroy """ url = ACCOUNTS_API.format(report.account_id) + "/reports/{}/{}".format( report.type, report.report_id) response = self._delete_resource(url) return True
def get_available_reports(self, account_id): """ Returns the list of reports for the canvas account id. https://canvas.instructure.com/doc/api/account_reports.html#method.account_reports.available_reports """ url = ACCOUNTS_API.format(account_id) + "/reports" report_types = [] for datum in self._get_resource(url): report_types.append(ReportType(data=datum, account_id=account_id)) return report_types
def get_external_tools_in_account(self, account_id, params={}): """ Return external tools for the passed canvas account id. https://canvas.instructure.com/doc/api/external_tools.html#method.external_tools.index """ url = ACCOUNTS_API.format(account_id) + "/external_tools" external_tools = [] for data in self._get_paged_resource(url, params=params): external_tools.append(data) return external_tools
def get_roles_in_account(self, account_id, params={}): """ List the roles for an account, for the passed Canvas account ID. https://canvas.instructure.com/doc/api/roles.html#method.role_overrides.api_index """ url = ACCOUNTS_API.format(account_id) + "/roles" roles = [] for datum in self._get_paged_resource(url, params=params): roles.append(CanvasRole(data=datum)) return roles
def update_term_overrides(self, sis_term_id, overrides={}): """ Update an existing enrollment term for the passed SIS ID. https://canvas.instructure.com/doc/api/enrollment_terms.html#method.terms.update """ if not self._canvas_account_id: raise MissingAccountID() url = ACCOUNTS_API.format( self._canvas_account_id) + "/terms/{}".format( self._sis_id(sis_term_id, sis_field='term')) body = {'enrollment_term': {'overrides': overrides}} return CanvasTerm(data=self._put_resource(url, body))
def create_user(self, user, account_id=None): """ Create and return a new user and pseudonym for an account. https://canvas.instructure.com/doc/api/users.html#method.users.create """ if account_id is None: account_id = self._canvas_account_id if account_id is None: raise MissingAccountID() url = ACCOUNTS_API.format(account_id) + "/users" data = self._post_resource(url, user.post_data()) return CanvasUser(data=data)
def get_courses_in_account(self, account_id, params={}): """ Returns a list of courses for the passed account ID. https://canvas.instructure.com/doc/api/accounts.html#method.accounts.courses_api """ if "published" in params: params["published"] = "true" if params["published"] else "" url = ACCOUNTS_API.format(account_id) + "/courses" courses = [] for data in self._get_paged_resource(url, params=params): courses.append(CanvasCourse(data=data)) return courses
def update_user_login(self, login, account_id=None): """ Update an existing login for a user in the given account. https://canvas.instructure.com/doc/api/logins.html#method.pseudonyms.update """ if account_id is None: account_id = self._canvas_account_id if account_id is None: raise MissingAccountID login_id = login.login_id url = ACCOUNTS_API.format(account_id) + "/logins/{}".format(login_id) data = self._put_resource(url, login.put_data()) return Login(data=data)
def create_report(self, report_type, account_id, term_id=None, params={}): """ Generates a report instance for the canvas account id. https://canvas.instructure.com/doc/api/account_reports.html#method.account_reports.create """ if term_id is not None: params["enrollment_term_id"] = term_id url = ACCOUNTS_API.format(account_id) + "/reports/{}".format( report_type) body = {"parameters": params} data = self._post_resource(url, body) data["account_id"] = account_id return Report(data=data)
def get_reports_by_type(self, account_id, report_type): """ Shows all reports of the passed report_type that have been run for the canvas account id. https://canvas.instructure.com/doc/api/account_reports.html#method.account_reports.index """ url = ACCOUNTS_API.format(account_id) + "/reports/{}".format( report_type) reports = [] for datum in self._get_resource(url): datum["account_id"] = account_id reports.append(Report(data=datum)) return reports
def get_report_status(self, report): """ Returns the status of a report. https://canvas.instructure.com/doc/api/account_reports.html#method.account_reports.show """ if (report.account_id is None or report.type is None or report.report_id is None): raise ReportFailureException(report) url = ACCOUNTS_API.format(report.account_id) + "/reports/{}/{}".format( report.type, report.report_id) data = self._get_resource(url) data["account_id"] = report.account_id return Report(data=data)
def get_all_terms(self): """ Return all of the terms in the account. https://canvas.instructure.com/doc/api/enrollment_terms.html#method.terms_api.index """ if not self._canvas_account_id: raise MissingAccountID() params = {"workflow_state": 'all', 'per_page': 500} url = ACCOUNTS_API.format(self._canvas_account_id) + "/terms" data_key = 'enrollment_terms' terms = [] response = self._get_paged_resource(url, params, data_key) for data in response[data_key]: terms.append(CanvasTerm(data=data)) return terms