1.3.3 • Published 4 years ago

@malereg/aowatch-client v1.3.3

Weekly downloads
33
License
MIT
Repository
github
Last release
4 years ago

@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

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.16

4 years ago

1.2.12

4 years ago

1.2.13

4 years ago

1.2.14

4 years ago

1.2.15

4 years ago

1.2.11

4 years ago

1.2.10

4 years ago

1.2.8

4 years ago

1.2.9

4 years ago

1.2.7

4 years ago

1.2.6

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.3

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.1.2

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago