1.1.3 • Published 2 years ago

@nowarries/gegevensmagazijn.ts v1.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Gegevensmagazijn.ts

https://www.npmjs.com/package/@nowarries/gegevensmagazijn.ts

npm NPM

A simple typescript/javascript wrapper for the Dutch : House of Representatives OData API

Table of Contents

Installation

To get started with the api in your project. First install the package by writing

pnpm install @nowarries/gegevensmagazijn.ts

in your project location

Usage

Setup

Now the project is installed in your project we can import the project:

import { gegevensmagazijn } from "@nowarries/gegevensmagazijn.ts"

from gegevensmagazijn all functionalities will be made available

Method 1

(Default / Recommended) method of extracting data

The project exists of 2 main functions

  • selectAll
  • select

selectAll(request, settings?)

selectAll as you might've guessed will get all information relevant to the given Query.

A request might look like this

gegevensmagazijn.selectAll('Stemming')
  .then((data) => console.log(data))
  .catch((err) => console.error(err));

But can also optionaly contain a set of settings to pass

gegevensmagazijn.selectAll('Stemming', {
  top : 1,
  select: ['ActorNaam']
})
  .then((data) => console.log(data))
  .catch((err) => console.error(err));

More on these options below

select(request, identifer, settings?)

select will get all information relevant to the given Entity and its identifier.

A request might look like this

gegevensmagazijn.select('Stemming', "076034d0-52b2-409a-a841-001bfc4bcb39")
  .then((data) => console.log(data))
  .catch((err) => console.error(err));

But can also optionaly just like selectAll contain a set of settings

gegevensmagazijn.select('Stemming', "e0fe1dc7-c9c3-4b74-9625-00004cff6854", {
  select: ['ActorNaam']
})
  .then((data) => console.log(data))
  .catch((err) => console.error(err));

It is for non-bulk requests also possible to pass settings. But more limited.

More on these options below

Options

For a better understanding of how these options work we higly recommend reading the official API documentation first

https://opendata.tweedekamer.nl/documentatie/odata-api

Top

OptionDescriptionType
topdefines the amount of items to shownumber(1..250)

Single use : No

Example:

{
  top : 43
}

Skip

OptionDescriptionType
skipDefines the amount of items to skipnumber(0..n)

Single use : No

Example:

{
  skip : 43
}

Count

OptionDescriptionType
countTotal of found items for this query (ignores skip & $top)boolean

Single use : No

Example:

{
  count : false
}

Order

OptionDescriptionType
orderGiven an attribute sort the data ascending or descending[string, 'asc'/'desc']

Single use : No

Example:

{
  order: ["Afkorting", "asc"]
}

Expand

OptionDescriptionType
expandGiven a relevant association and optionally inner filter extract associated dataArray<Array<string>>

Single use : Yes

Example:

{
  expand: [
    ["Fractie"],
    ["Besluit", "$filter=(Verwijderd eq false)"]
  ]
}

Select

OptionDescriptionType
selectOnly return selected attributes as dataArray<string>

Single use : Yes

Example:

{
  select: ["ActorNaam"]
}
{
  select: ["ActorNaam", "FractieGrootte"]
}

Filter

OptionDescriptionType
filterGiven one or more filters return relevant resultsArray<Array<string>>

Single use : No

Example:

{
  filter: [
    ["Soort eq 'voor'"],
    ["and"],
    ["FractieGrootte le 34"],
    ["and"],
    ["year(GewijzigdOp) gt 2020"]
  ]
}

Format

OptionDescriptionType
formatsets the amount of metadata to displaynone/minimal/full

Single use : Yes

Example:

{
  format: 'full'
}

Custom

OptionDescriptionType
customCustom operationany

Single use : Yes

This will overwrite any other option you might've opted in for

Example:

{
  custom : "$filter=Verwijderd eq false and (Functie eq 'Eerste Kamerlid' or Functie eq 'Tweede Kamerlid')"
}

Advanced examples

gegevensmagazijn.selectAll('Fractie', {
    top: 5, // Only show  5 results
    skip: 5, // Skip the first 5 entries
    filter: [
        ["Afkorting ne null"] // Afkorting not equals null (is defined)
    ],
    order: ["Afkorting", "asc"] // Sort by attribute afkorting ascending
})

URL that is generated for you

https://gegevensmagazijn.tweedekamer.nl/OData/v4/2.0/Fractie?$top=5&$skip=5&$orderby=Afkorting asc&$filter=( Afkorting ne null )


gegevensmagazijn.selectAll('Besluit', {
  top: 1, // Only show top 1 result
  select: ["BesluitSoort"], // only display besluitsoort for Besluit
  expand: [
    ["Zaak", "$select=Onderwerp"] // get Associate Zaak and select Onderwerp
  ],
  filter: [
    ["BesluitSoort eq 'Ingediend'"] // where BesluitSoort equals ingediend
  ],
  order: ["Status", "asc"] // Sort by attribute status ascending
})

URL that is generated for you :

https://gegevensmagazijn.tweedekamer.nl/OData/v4/2.0/Besluit?$top=1&$orderby=Status asc&$filter=( BesluitSoort eq 'Ingediend' )&$select=BesluitSoort&$expand=Zaak($select=Onderwerp)

Method 2

Experimental method of extracting data

Method 2 is strongly discouraged for people who are using javascript (not-typescript)

You can now limitedly experiment with using a deserialized version of the api

  1. Start by importing the Classes you wish to access
import { Fractie } from "@nowarries/gegevensmagazijn.ts"
  1. Request a data by id
Fractie.get('e133cd98-1b5c-47e0-ac4d-031f34199767')
  .then((data: Fractie) => {
    console.log(data.ActiviteitActor.Functie);
    for (let stem in data.Stemming) {
      console.log(data.Stemming[stem].Soort);
    }
  })
  .catch((err) => console.error(err));
FractieZetel.get('0f772b49-fe42-46c7-b2b9-00e7bea09ee7')
  .then((data: FractieZetel) => {
    console.log(data.Gewicht);
  });
  1. All data should be made available including associations

Supported

Class
Fractie
FractieZetel
Stemming
Verslag
Vergadering

Dependency

This project is dependent on:

Dutch : House of Representatives OData API | https://opendata.tweedekamer.nl

cross-fetch | https://github.com/lquixada/cross-fetch

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.7.5

2 years ago