1.0.0 • Published 7 years ago

omk v1.0.0

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

Oma matkakortti is a web service that allows HSL (Helsingin Seudun Liikenne) users to get information about their travel cards. This is an unofficial Node.js API for getting (and possibly setting in the future) information using the web service.

Please note that this library cannot (yet) add new cards, so you should that manually in the web portal.

Usage

A simple example:

const OMK = require('omk');

const omk = new OMK();

omk.login('test', 'test') // change these
.then(() => omk.getCards())
.then((cards) => {
    console.log(`Cards: ${cards.map(a => `${a.id} (${a.name})`).join(', ')}\n`);
    return cards;
})
.then((cards) => Promise.all(cards.map(card => omk.getCard(card.id))))
.then((cardInfos) => {
    cardInfos.forEach((card) => {
        console.log(`Card #${card.id}:`);
        console.log(`\tBalance: ${card.balance}`);
        console.log(`\tName: ${card.name}`);
        console.log(`\tSeason: ${card.rawSeason.replace(/\n|\r/g, ' ')}`);
        console.log(`\t\tParsed season: ${JSON.stringify(card.season)}`);
    });
})
.catch(console.error);

Methods

login(username, password) ⇒ Promise

Logs the user in with an username and a password. Resolves on successful login.

Parameters

NameTypeDescription
username string username of the user
password string password of the user

getCards() ⇒ Promise<Array<Object>>

Fetches all the cards of the user and caches them for next time.

Note: Even though the array has objects with lots of information, only id and name are accurate; others are bogus.

getCard(id) ⇒ Promise<Object>

gets information about a specific card

Parameters

NameTypeDescription
id string the id of the card