1.1.0 • Published 7 years ago

magister-tools v1.1.0

Weekly downloads
6
License
MIT
Repository
github
Last release
7 years ago

intro

The goal of this module is to make getting grades and other data from magister easier. Getting grades from Magister using Magister.js (v1) is a mess in my opinion. For my personal use I needed a way to get the average grades of students and this module does just that.

I am open to any suggestions.

Contents


Installation

Using npm:

Install the npm package

npm install magister-tools

Cloning github source code:

1: Clone the source code.

git clone https://github.com/skillzzjesse/magister-tools.git

2: install the dependencies.

npm install

3: Profit??

Example usage

var magister_tools = require('magister-tools');

magister_tools.magisterLogin({
   school: 'xxxx' || {url: 'xxxx'},
   username: 'xxxx',
   password: 'xxxx'
}, function (err, magisterlogin) {
   if (err) {
      // Handle error..
   }
   // This is the callback function.
   // What to do when logged in to Magister.

   // Get the current course for the logged in user.
   magister_tools.fetchCurrentCourse(magisterlogin, function (err, course) {
      if (err) {
         // Handle error..
      }   
      // What to do when we have the current course for the logged in user.


      magister_tools.fetchGrades(course, function (err, grades) {
         if (err) {
            // Handle error...
         }
         // What to do when we've got the grades for the current course of the logged in user.

         // Select the endgrades (avarage grades) from this list of grades.
         var endgrades = magister_tools.selectEndGrades(grades);

         /*=======================================================
           ******************************************************
               Now do whatever you want with these endgrades.
           ******************************************************
           =======================================================*/
      })
   })
}, function () {
   // What to do before logging in to Magister.
   // This is optional but can be useful, for example:
   // log something to the console indicating you're trying to login.
});

Or use the (new) shortcut function

var  magister_tools = require('magister-tools');

var login = {
  school: 'xxxx' || {url: 'xxxx'},
  username: 'xxxx',
  password: 'xxxx'
}

magister_tools.fetchEndGrades(login, function (err, endGrades) {
  if (err) {
    // Handle the error
  }

  /* Do something with the endGrades, for example log them */
  console.log(endGrades);

}, function () {
  // What to do before logging in to Magister.
  // This is optional but can be useful, for example:
  // log something to the console indicating you're trying to login.
})

Documentation

Contents

Shortcut functions


magisterLogin(settings, callback, doFirst)

This function logs into magister using MagisterJS.

ParamTypeDescription
settingsObjectAn object containing the data needed to login to magister.
callbackfunctionA callback function taking two parameters. -> err, magisterlogin
doFirstoptional functionA function the program needs to excecute before trying to login to Magister. For instance: logging something to the console indicating we're trying to log in. This is optional

fetchCurrentCourse(magisterlogin, callback)

This function fetches the current course for the logged in user.

ParamTypeDescription
magisterlogin?magisterlogin. (pass in magisterlogin from the callback of the magisterLogin method)
callbackfunctionA callback function taking two parameters. -> err, currentcourse

fetchGrades(course, callback)

This function fetches the grades for the course of the logged in user.

ParamTypeDescription
courseArraycourse: A Course (like: 4 VWO E/M 14-15) (You can get the courses from MagisterJS)
callbackfunctionA callback function taking two parameters. -> err, grades

selectEndGrades(grades, settings)

This function selects the endgrades from a list of grades. ⇒ Object
Returns: Object - endgrades An object structured like this:

{ class: endGrade }
// For example (with default settings)
{EN: 7.9, WB: 6.5}  
ParamTypeDescription
gradesArrayA list of all the grades (generated by MagisterJS)
settingsObject(OPTIONAL) Settings determining the functions behavior and output.
settings.fullClassNameBooleanIf the function should use the full class name or the class abbreviation. (DEAFAULT: false)
settings.gradeToNumberBooleanIf the function should convert the grade to a JS number or leave it a string. (DEAFAULT: true)

Shortcut functions

The Goal of this module is to write less and do more! The normal way you would use this module will result in quite a lot of code still. See the example.
Shortcut functions allow you to write even less code and still get the desired results.


fetchEndGrades(settings, callback, doFirst)

This function fetches the endgrades from magister for a specified user.

Note that this is a shortcut function designed to make using this module just a little easier.
However, it has less customizability since the function will use default settings in the selectEndGrades function.
Also tracking where an error occurred while getting the data from Magister isn't possible.

Returns: Object - endgrades An object structured like this: (Note that it will return via the callback)

{ class: endGrade }
// For example (with default settings)
{EN: 7.9, WB: 6.5}  
ParamTypeDescription
settingsObjectAn object containing the data needed to login to magister.
callbackfunctionA callback function taking two parameters -> err, endgrades.
doFirstfunction(OPTIONAL) A function the program needs to execute before trying to login to Magister. For instance: logging something to the console indicating we're trying to log in.

Suggestions

This module is in a very early state and does not have a lot of functionality yet. Any suggested features are more than welcome. If you have an awesome feature in mind please open an issue.

License & Disclaimer

This module is open-sourced under the MIT Licence (see LICENSE for the full license). So within some limits, you can do with the code whatever you want.

The software is provided as is. It might work as expected - or not. Just don't blame me.

1.1.0

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

8 years ago

1.0.0

8 years ago