1.0.4 • Published 3 years ago

akora-moodle v1.0.4

Weekly downloads
206
License
MIT
Repository
github
Last release
3 years ago

NPM Version NPM Downloads NPM License Github Size

AKORA Moodle Client

This is a simple Client for moodle, that is inspired by the moodle-client by mudrd8mz, it has built in typings and typings for many endpoints of the Moodle API(which are documented here), the typings will be extended in the future till hopefully one day al endpoints are built in this package.

The Documentation is also available on GitBook

Why should i use this package?

If you ever read the documentation of the Moodle API, then you know that there are hundrets of methods and if you dont have the right documentation the docs can be hard to read and understand, you still need the documentation to use this package but it provides you most methods with built in types so that you know what you get back and what you need to supply to the request.

Getting started

Installation

npm install akora-moodle

Creating an instance

To create an instance of the Client, you use the static init method of the Client with an object which contains all needed options to initialize the client. The method will return a Promise wich returns a instance of the Client class.

const { Client } = require('akora-moodle');

Client.init({
    wwwroot: 'https://moodle.your-school.de/',
    username: 'Bob',
    password: 'SuPeRsecRet'
})
Client.init({
    wwwroot: 'https://moodle.your-school.de/',
    token: 'yourtokengoesbrrrrrr'
})


Built-in Methods

At the moment all implemented methods can be found in the client.core property, your IDE will tell you what methods are already implemented and usable, as well as your IDE will tell you what arguments you need to provide and what the response looks like.

const { Client } = require('akora-moodle');

Client.init({
    wwwroot: 'https://moodle.your-school.de/',
    token: 'yourtokengoesbrrrrrr'
}).then(async (client) => {
    var info = await client.core.getInfo();

    console.log('You are Logged in as %s %s', info.firstname, info.lastname)
}).catch((err) => {
    console.log('Something went wrong ._.', err);
});
const { Client } = require('akora-moodle');

client.init({
    wwwroot: 'https://moodle.your-school.de/',
    token: 'yourtokengoesbrrrrrr'
}).then(async (client) => {
    var contents = await client.core.course.getContents({
        courseid: 3272
    });

    console.log('There are %s Sections in this Course', contents.length)
}).catch((err) => {
    console.log('Something went wrong ._.', err);
});

Custom API Calls

At the moment not even nearly all methods are implemented, so you might often want to use the client.call method to make a custom API Requests.

const { Client } = require('akora-moodle');

Client.init({
    wwwroot: 'https://moodle.your-school.de/',
    token: 'yourtokengoesbrrrrrr',
}).then(async (client) => {
    var response = await client.call({
        wsfunction: 'core_not_implemented_yet',
        method: 'POST',
        args: {
            someid: 123
        }
        //You can also provide settings > for advanced usage
    })
}).catch((err) => {
    console.log('Something went wrong ._.', err);
});

Advanced Client settings

const { Client } = require('akora-moodle');

Client.init({
    wwwroot: 'https://moodle.your-school.de/',
    token: 'yourtokengoesbrrrrrr',
    // The web service to use, default is moodle_mobile_app
    service: 'moodle_mobile_app',
    // If set to false, SSL certificates do not need to be valid.
    strictSSL: true,
    // Will enable the built-in Logger
    logger: true
})