From 0c08cd07377ab2dff76913f144c233311de638c8 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Wed, 16 Nov 2022 23:45:48 +0100 Subject: Move ApiHelper and add comment for schema in muddle.moodle --- muddle/moodle.py | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/muddle/moodle.py b/muddle/moodle.py index 489f50a..870de8a 100644 --- a/muddle/moodle.py +++ b/muddle/moodle.py @@ -74,7 +74,28 @@ class MoodleInstance: yield Course._fromdict(c) +class ApiHelper: + def __init__(self, api): + self.api = api + + def get_userid(self): + req = self.api.core_webservice_get_site_info() + if req: + return req.json()["userid"] + else: + return None + + def get_file(self, url, local_path): + with requests.post(url, data={"token": self.api._token}, stream=True) as r: + r.raise_for_status() + with open(local_path, "wb") as f: + for chunk in r.iter_content(chunk_size=8192): + if chunk: + f.write(chunk) + + # A bare minimum impl of Moodle SCHEMA +# This is an experiment and not currently in use! # Beware that lots of parameters have been omitted class SchemaObj: @@ -158,23 +179,3 @@ class Folder(SchemaObj): @dataclasses.dataclass class ExternalLink(SchemaObj): pass - - -class ApiHelper: - def __init__(self, api): - self.api = api - - def get_userid(self): - req = self.api.core_webservice_get_site_info() - if req: - return req.json()["userid"] - else: - return None - - def get_file(self, url, local_path): - with requests.post(url, data={"token": self.api._token}, stream=True) as r: - r.raise_for_status() - with open(local_path, "wb") as f: - for chunk in r.iter_content(chunk_size=8192): - if chunk: - f.write(chunk) -- cgit v1.2.1