Abgeordnetenwatch TypeScript/JavaScript API client for Browser, Node and Typescript
Features:
npm install @malereg/aowatch-client --save
import { politicianList, politician } from '@malereg/aowatch-client/src/entities/entity.politician';
politician(100).then(console.log)
import { politicianList, politician } from '@malereg/aowatch-client/src/entities/entity.politician';
politician().then(console.log)
Paging
import { politicianList } from '@malereg/aowatch-client/src/entities/entity.politician';
politicianList({
page: 0,
pager_limit: 10
}).then(console.log)
Sorting
import { politicianList } from '@malereg/aowatch-client/src/entities/entity.politician';
politicianList(null, {
sort_by: 'id',
sort_direction: 'asc'
}).then(console.log)
Simple equal filters on a property.
All female politicians
import { politicianList } from '@malereg/aowatch-client/src/entities/entity.politician';
politicianList(null, null, {
sex: "f"
}).then(console.log)
More complex filters can be set up as well with comparators.
import { politicianList } from '@malereg/aowatch-client/src/entities/entity.politician';
politicianList(null, null, [{
field: 'year_of_birth',
operator: 'gt',
value: 1983
}
]).then(console.log)
If you need all the data of one specific endpoint, you can simply use currying to do so using the listAll method. It will make sure all data is loaded and the metadata is properly updated.
import { listAll } from '@malereg/aowatch-client/src/list-all'
import { partyList, url } from '@malereg/aowatch-client//src/entities/entity.party';
// get all parties
const res = await listAll(partyList);
There is a Event emitter argument that allows to react to parts of the fetchAll process
const politicianList = require('@malereg/aowatch-client/entities/entity.politician').politicianList;
const partyList = require('@malereg/aowatch-client/entities/entity.party').partyList;
const listAll = require('@malereg/aowatch-client/list-all').listAll;
const getEmitter = require('@malereg/aowatch-client/list-all').getEmitter;
const politicianEmitter = getEmitter();
politicianEmitter.on('count', (count)=>{
console.log(`fetching ${count} pages`);
});
politicianEmitter.on('page', (meta)=>{
console.log(`Fetching politician page ${meta.result.page} of ${Math.ceil(meta.result.total/meta.result.count)}`);
});
const res = listAll(politicianList, politicianEmitter);
res.then(console.log)
import { extractLinks } from '@malereg/aowatch-client/src/extract-links'
import { politician } from '@malereg/aowatch-client//src/entities/entity.politician';
// load the politician
const politician = await politician(100).data;
const links = extractLinks(politician.abgeordnetenwatch_url)
In Node and browser builds, you should use the generic API object. It comes with the positive sideeffect of providing events.
const client = require('@malereg/aowatch-client').AowatchCLient;
const c = new client();
c.politician.item(100).then(console.log)
Generated using TypeDoc