npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

kamar-js

v0.3.3

Published

A simple, promised based wrapper for working with the Kamar API

Downloads

20

Readme

:mortar_board: Kamar.js

NPM npm GitHub repo size GitHub commit activity GitHub last commit code style: prettier

Kamar JS is a flexible promise based api wrapper for the popular school management suite KAMAR

This is a passion project of a High School Student, so updates and bug fixes may not be the fastest however I will try my hardest to provide a powerful library for working with KAMAR

:man_factory_worker: Installation

You can start using Kamar JS by installing it from npm using

npm i kamar-js

:woman_technologist: Getting Started

You can create a new Kamar object by using

const Kamar = require('kamar-js'),
  kamar = new Kamar({portal: 'demo.school.kiwi'});

This object has many options, here is a list of what it will accept

| Parameter | Description | Default | Required | | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------- | ------------------------------------------------------------------------- | | Portal | The url of your school's kamar website this is often something like kamar.schoolname.nz or portal.schoolname.nz/kamar There's no need to include https:// and /api/api.php as these are added automatically when Kamar is defined | | Yes | | Year | The year to use when returning time based Objects like the student's calender | Date().getFullYear() | No. Will use current year if not provided | | User Agent | The user agent sent with the request headers | 'Kamar-JS v????' | No. Although it is recommended to have your application's name on this | | Timezone | The timezone to use when converting timetable times between locations | Pacific/Auckland | No. Helpful for dealing with schools based in Fiji, The Cook Islands, etc | | Calender | This is only to be used if you don't want to use kamar.getCalender() or already have one ready. Use at your own risk as your file must be formatted correctly | | No. In most cases kamar.getCalender() works | | Timeout | The timeout for HTTPS requests in ms. before they are abandoned | 10000 | No |

Examples

Here are some example and breakdowns explaining how to use kamar js

Getting a Students Timetable

Example

const Kamar = require('kamar-js'),
  kamar = new Kamar({portal: 'demo.school.kiwi'});

// Authenticates the student using the portal set above
kamar.logon('web.student', 'student').then(credentials => {
  kamar
    .getCalendar(credentials)
    .then(calender => kamar.getTimetable(credentials, calender))
    .then(timetable => {
      console.log(timetable);
      // Anything you want to do with the timetable.
    });
});

Breakdown of the Code

Creating a Kamar object
const Kamar = require('kamar-js'),
  kamar = new Kamar({portal: 'demo.school.kiwi'});

This is where we construct the new Kamar object, the only required parameter is portal

Logging in
kamar.logon("web.student", "student").then(credentials => {
A example of the credentials object
{
  username: 'web.student',
  studentID: 17046,
  key: 'bocpq9iXOjr9DDOOBOto9DVcppOtY9B6',
  accessLevel: 0
}

From that Kamar object we start to authenticate a Student using their portal username and password. This will return a credentials object which looks like this

Getting the calender
kamar.getCalendar(credentials);
A example of the calender day object
{
  Date: '2021-06-14',
  Status: '',
  DayTT: 1,
  Term: 2,
  TermA: 2,
  Week: 7,
  WeekA: 7,
  WeekYear: 18,
  TermYear: 7
}

After the authentication is ready we call kamar.getCalender(), this is the first and only time that we will need to call this as when it is called it is assigned globally to the Kamar object. But for simplicity only DayTT, Date and Week are passed to the Timetable

Getting the Student's Timetable for this week
.then(calender => kamar.getTimetable(credentials, calender))
.then(timetable => {
    console.log(timetable)
    // Anything you want to do with the timetable.
})
A example of the Timetable object
[
  {Class: 'L2DIT', Room: 'B13', Teacher: 'SCH', Time: '08:45'},
  {Class: 'L2BUS', Room: 'R1', Teacher: 'MOC', Time: '09:50'},
  {
    Class: undefined,
    Room: undefined,
    Teacher: undefined,
    Time: '10:50',
  },
  {Class: 'L2DVC', Room: 'T2', Teacher: 'STE', Time: '11:15'},
  {Class: 'L2MA1', Room: 'B1', Teacher: 'NEV', Time: '12:15'},
  {
    Class: undefined,
    Room: undefined,
    Teacher: undefined,
    Time: '13:15',
  },
  {Class: 'Whanau', Room: 'B8', Teacher: 'SEA/JEN', Time: '14:00'},
  {Class: 'L2EN1', Room: 'E5', Teacher: 'CHI', Time: '14:20'},
];

Finally we call kamar.GetTimetable() This takes the calender and credentials objects from before and turns them into a array of Periods with Class, Room, Teacher and Time. If undefined this is because of unmarked events, assemblies or lunch breaks.