0.1.0-beta.0 • Published 4 years ago

sakai-api v0.1.0-beta.0

Weekly downloads
2
License
MIT
Repository
-
Last release
4 years ago

Sakai API

Unofficial wrapper for the Sakai API

Installation

$ npm install sakai-api

Authenticate

Before you can take any actions you need to be authenticated.

const SakaiAPI = require("sakai-api").default;

(async () => {
    const API = new SakaiAPI();
    await API.login({ username: "xxx", password: "xxx" });
})();

Getting announcement for a site

const SakaiAPI = require("sakai-api").default;

(async () => {
    const API = new SakaiAPI();
    await API.login({ username: "xxx", password: "xxx" });

    const siteId = "xxx"; // <---- site id
    let announcement = await API.getSiteAnnouncement(siteId);
    console.log(announcement.data);
})();

Getting assignments for a site

const SakaiAPI = require("sakai-api").default;

(async () => {
    const API = new SakaiAPI();
    await API.login({ username: "xxx", password: "xxx" });

    const siteId = "xxx"; // <---- site id
    let assignment = await API.getSiteAssignment(siteId);
    console.log(assignment.data);
})();

Error handling

Any unsuccessful action will throw an error. If you want to mitigate that you need to catch it.

const SakaiAPI = require("sakai-api").default;

(async () => {
    const API = new SakaiAPI();
    try {
        await API.login({ username: "xxx", password: "xxx" });

        const siteId = "xxx"; // <---- site id
        let assignment = await API.getSiteAssignment(siteId);
        console.log(assignment.data);
    } catch (e) {
        console.log(e)
    }
})();

API

SakaiAPI.new(config)

Initialize new SakaiAPI.

ParamTypeDescription
config.baseUrlStringBaseurl - your institution's url

SakaiAPI.login(params) => null

Returns the extracted meaning from a sentence, based on the context.

ParamTypeDescription
params.usernameStringUsername
params.passwordStringPassword

SakaiAPI.getSiteAnnouncement(siteId) => Promise

Gets announcement for a specific site

ParamTypeDescription
siteIdStringSite ID

SakaiAPI.getUserAnnouncement() => Promise

Gets all announcement for current user


SakaiAPI.getSiteAssignment(siteId) => Promise

Gets assignments for a specific site

ParamTypeDescription
siteIdStringSite ID

SakaiAPI.getItemAssignment(assignmentId) => Promise

Gets an assignment

ParamTypeDescription
assignmentIdStringAssignment ID

SakaiAPI.getMyAssignment() => Promise

Gets all assignments for current user


SakaiAPI.getSiteCalendar(siteId) => Promise

Gets calendar for a specific site

ParamTypeDescription
siteIdStringSite ID

SakaiAPI.getMyCalendar() => Promise

Gets all calendars for current user


SakaiAPI.getEventCalendar(params) => Promise

Gets calendar event for a specific site

ParamTypeDescription
params.siteIdStringSite ID
params.eventIdStringEvent ID

SakaiAPI.getSite() => Promise

Gets sites for current user


SakaiAPI.getSiteContent(siteId)

Gets content for a specific site

ParamTypeDescription
siteIdStringSite ID

SakaiAPI.getMyContent()

Gets content for current user