omk

1.0.0 • Public • Published

🚌 Oma matkakortti (OMK) API

Build Status

Unofficial oma matkakortti API for Node.js

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

Name Type Description
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

Name Type Description
id string the id of the card

Readme

Keywords

none

Package Sidebar

Install

npm i omk

Weekly Downloads

2

Version

1.0.0

License

MIT

Last publish

Collaborators

  • jolle