-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoodle.js
51 lines (43 loc) · 1.38 KB
/
moodle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
var moodle = require('moodle-client');
var config = require('./config.json');
var fs = require('fs');
moodle.init({
wwwroot: config.moodle.url,
// username: config.moodle.username,
// password: config.moodle.password,
token: config.moodle.tokens[0].token,
service: "moodleee-discord-bot",
moodlewsrestformat: 'json',
moodlewssettinglang: 'en',
}).then(function(client) {
//console.log(client.token);
return do_something(client);
}).catch(function(err) {
console.log("Unable to initialize the client: " + err);
});
var api_call = "mod_assign_get_assignments"
function do_something(client) {
// return client.get_courses().then(function(courses) {
// }
return client.call({
wsfunction: api_call,
moodlewsrestformat: json,
//wsfunction: "core_course_get_contents",
// args: {
// users: {
// "lang": "en",
// }
// }
}).then(function(value) {
// courses = value.courses;
// courses.forEach(course => {
// return client.call({})
// });
fs.writeFileSync(`./api-calls/${api_call}.json`, JSON.stringify(value, null, 2));
// value.events.forEach(event => {
// console.log(`${event.name} (${event.timesort})`);
// });
//console.log(value.courses[0].assignments);
return;
});
}