NUS IVLE API JavaScript SDK

Make things as simple as possible, but not simpler.

Overview

This is the documentation for NUS IVLE APIs JavaScript SDK, Version 0.0.0.

It is derivied from my Firefox Add-on NUS IVLE Helper, developed for my UNFINISHED IVLE client-side website.

Demos in following Sections

Please remember to put your IVLE API key (get it at IVLE page) in the top right input box, and get your user token using your NUS account first.

Important For all results, if the result is Array, only the first item will be displayed in Run. You can use Run in Console to access the complete result.

NOTE If you Run in Console, you can always access the last data outputted in Console using $$.

Download

Found a issue, or any feedbacks, please file an issue here.

License

Copyright (c) 2012 Wang Zhuochun
Licensed under the MIT license.

ivle

Login

ivle.login(key, redirectUrl); // return the login url

Get Token

ivle.getToken([url]); // return the token if it is found in location.href/url

User

Initial User

var user = ivle.User(key, token); // return a User instance

// you must init user, it will validate the user and query his/her profile
user.init().done(function() {
    // start doing things
    // e.g. get user's profile
    user.profile();
    // e.g. or get a profile item
    user.profile("Faculty"); // "Multi Disciplinary Programme"
})

Validate User

user.validate(function(result) {
    // result = true/false
});

Get User Profile

All information

var profile = user.profile();

Matric Number

var id = user.profile("UserID");

Email Address

var email = user.profile("Email");

All modules taken

user.modulesTaken(function(mods) {
    // mods = [...]
});

Unread Announcements

user.unreadAnnouncements(function(anns) {
    // anns = [...]
});

Search

var params = {ModuleCode: "ACC1002"};
user.search("Modules", params, function(result) {
    // result = [...]
});

Allowed Query Params:

// must have at least one query param in search
q = {
    ModuleCode: "ACC1002" // String
  , ModuleTitle: "Financial" // String
  , LecturerName: "XXX" // String
  , Department: "Arts" // String
  , Semester: "1" // String
  , AcadYear: "2012/2013" // String
  , ModNameExact: false // Boolean
  , LecNameExact: false // Boolean
};

Modules

Getting the Modules

var modules = [];
user.modules(function(mods) {
    modules = mods; // mods = Module[...]
});

Getting Data

var modId = modules[0].get("CourseName"); // course name of the 1st module in list

Update Module

modules[0].update(); // update the data of the 1st module

Announcements

// prefer this one 
anns = modules[0].announcements();
// or fetch from server
modules[0].announcementsAsync(function(anns) {
    // anns = [...]
});

Workbins

bins = modules[0].workbins();
// or fetch from server
modules[0].workbinsAsync(function(bins) {
    // bins = [...]
});

Forums

forums = modules[0].forums();
// or fetch from server
modules[0].forumsAsync(function(forums) {
    // forums = [...]
});

Webcasts

webcasts = modules[0].webcasts();
// or fetch from server
modules[0].webcastsAsync(function(webcasts) {
    // webcasts = [...]
});

Gradebook

grades = modules[0].gradebooks();
// or fetch from server
modules[0].gradebooksAsync(function(grades) {
    // grades = [...]
});

Additions

Async functions

Instead of passing in callbacks into functions, all functions return a $.Deferred object that you can also call with done, success, error. So you can more controls.

However, the result will be raw data. You can filter the data using ivle.filterResult.

// instead of passing in a callback
modules[0].gradebooksAsync(function(grades) {
    // grades = [...]
});

// you can also do this
modules[0].gradebooksAync().success(function(data) {
    var grades = ivle.filterResult(data); // grades = [...]
});

Extend APIs

For APIs not provided, you can always call user.get(api, params). If params are not required for a API, you need to pass in an empty object {}.

// for example, get all unread announcements
user.get("Announcements_Unread", {TitleOnly: false})
    .success(function(data) {
        var anns = ivle.filterResult(data); // anns = [...]
    });