Skip to content
/ omk Public

🚌 Oma matkakortti API for Node.js (unofficial)

License

Notifications You must be signed in to change notification settings

jolle/omk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🚌 Oma matkakortti (OMK) API

Build Status
NPM

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.

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

About

🚌 Oma matkakortti API for Node.js (unofficial)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published