@malereg/aowatch-client

1.3.3 • Public • Published

@malereg/aowatch-client

Abgeordnetenwatch TypeScript/JavaScript API client for Browser, Node and Typescript

npm version GitHub stars

Features:

Installation

npm install @malereg/aowatch-client --save

All api methods available

fetch one item

import { politicianList, politician } from '@malereg/aowatch-client/src/entities/entity.politician';
politician(100).then(console.log)

fetch a list

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)

Filtering

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)

Extends the original API

get all data of a specific type

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)   

get website links of politicians

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)

Javascript/Node

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)

Browser Package

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.3.3
    0
    • latest

Version History

Package Sidebar

Install

npm i @malereg/aowatch-client

Weekly Downloads

1

Version

1.3.3

License

MIT

Unpacked Size

2.03 MB

Total Files

91

Last publish

Collaborators

  • maschlesreg