An open API service indexing awesome lists of open source software.

https://github.com/james-firth/kanka-js

A Javascript wrapper for the Kanka.io API.
https://github.com/james-firth/kanka-js

api-wrapper async-await javascript js kanka

Last synced: 3 days ago
JSON representation

A Javascript wrapper for the Kanka.io API.

Awesome Lists containing this project

README

        

# Kanka JS

:warning: **OUT OF DATE/DEPRECATION WARNING:** I haven't had a chance to work with this for a long time now and there have been _many_ changes. Considering using this as inspiration for your own library instead of using it directly!

---

A wrapper for the Kanka API written in javascript.

This wrapper works with both async/await and Promises.

```js
const kanka = require('kanka');

// First set your API token.
// Alternatively export the environmental variable KANKA_TOKEN="myToken"
const token = 'myAPIToken';
kanka.setToken(token);

// Grab an individual campaign, or list all of them.
// NOTE: If you have a lot of campaigns (over 45) this version not work for you as I haven't implemented pagination.

async function runExample(){
console.log("Start");
try {
let campaignList = await kanka.listCampaigns();
// Some types come back as Pages. For those types look at the data key
let campaignNames = campaignList.data.map(x => `"${x.name}"`);
console.log(`Campaign Names: ${campaignNames}\n`);

let camp = await kanka.getCampaign(campaignList.data[0].id);
console.log(`Looking at Campaign: "${camp.name}"\n`);

let characters = await camp.characters.get();
console.log(`Characters: ${characters.map(x => ' '+x.name)}\n`);

let person = await camp.characters.get(characters[0].id);
let attributes = await person.attributes.get();
console.log(`Attributes for ${person.name}: ${attributes.map(x => x.name+': '+x.value+'\n')}\n`);

let relations = await person.relations.get();
console.log(`Relations for ${person.name}: ${relations}\n`);

let notes = await person.notes.get();
console.log(`Notes for ${person.name}: ${notes}\n`);

let calendar = await camp.calendars.get();
console.log(`Calendars: ${calendar.map(x => ' '+x.name)}\n`);

let events = await camp.events.get();
console.log(`Events: ${events.map(x => ' '+x.name)}\n`);

} catch(e) {
throw e;
}
}

runExample();
```