Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #19 from andaryjo/derhuerst-tweaks
Browse files Browse the repository at this point in the history
Incorporate changes from @derhuerst
  • Loading branch information
andaryjo authored May 1, 2021
2 parents 37c5d26 + 559c42d commit 007e2da
Show file tree
Hide file tree
Showing 20 changed files with 1,503 additions and 8,108 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# editorconfig.org
root = true

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[**.{ts, json}]
indent_style = spaces
indent_size = 4
23 changes: 23 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"env": {
"node": true
},
"plugins": [
"@typescript-eslint",
"jest"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:jest/recommended",
"prettier"
],
"rules": {
"@typescript-eslint/no-unused-vars": "off"
},
"ignorePatterns": [
"lib"
]
}
3 changes: 2 additions & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"printWidth": 200,
"tabWidth": 4,
"trailingComma": "all"
"trailingComma": "all",
"singleQuote": false
}
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This client aims to be an easy to use and lightweight implementation for the pub
Install the package:

```
```shell
npm install trias-client
```

Expand All @@ -39,6 +39,8 @@ var departuresResult = await client.getDepartures({
});
```

There's also an [example script](docs/example.ts) available that demonstrates how to use `trias-client`.

## What is TRIAS?

TRIAS stands for "**T**ravellor **R**ealtime **I**nformation and **A**dvisory **S**tandard", has been developed in scope of the research and standardisation project for public transport "IP-KOM-ÖV" and was then introduced in 2014 as a standardized specification by the VDV ([Verband Deutscher Verkehrsunternehmen](https://de.wikipedia.org/wiki/Verband_Deutscher_Verkehrsunternehmen)). TRIAS offers a wide-range list of functionalities, including station / location search, realtime departures, navigation, ticket price calculation, malfunction reportings, and so on. [Here](https://github.com/andaryjo/trias-client/blob/main/docs/PROVIDERS.md) is a list of all public transport providers that provide a TRIAS API.
Expand Down
2 changes: 2 additions & 0 deletions docs/PROVIDERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Coming soon™.
- :heavy_check_mark: Supports Location Information, Stop Events and Trips
- :heavy_check_mark: No contract required

They provide an open API for testing purposes. Use `https://api.opentransportdata.swiss/trias2020` as URL and `57c5dbbbf1fe4d000100001842c323fa9ff44fbba0b9b925f0c052d1` as `Authorization` header.

### [Verkehrsverbund Bremen & Niedersachsen](https://www.vbn.de/service/entwicklerinfos/)

- :heavy_check_mark: Supports Location Information, Stop Events and Trips
Expand Down
8 changes: 5 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Trias Client Documentation

This Node.js module is written using TypeScript and therefore comes with easy to use type specifications you can have a look at in the [`types`](https://github.com/andaryjo/trias-client/blob/main/src/types) directory.
This Node.js module is written using TypeScript and therefore comes with easy to use type specifications you can have a look at in the [`types`](../src/types) directory.

Every function requires defined [options](https://github.com/andaryjo/trias-client/blob/main/src/types/options.ts) and returns defined [results](https://github.com/andaryjo/trias-client/blob/main/src/types/results.ts), which then include [Friendly Public Transport Format](https://github.com/andaryjo/trias-client/blob/main/src/types/fptf.ts) elements. As of now, the FPTF does not fully support all TRIAS functionalities, so be aware that there are some [slight differences](https://github.com/andaryjo/trias-client/blob/main/src/types/fptf.ts).
Every function requires defined [options](../src/types/options.ts) and returns defined [results](../src/types/results.ts), which then include [Friendly Public Transport Format](../src/types/fptf.ts) elements. As of now, the FPTF does not fully support all TRIAS functionalities, so be aware that there are some [slight differences](../main/src/types/fptf.ts).

## trias.getClient(ClientOptions options)

Expand Down Expand Up @@ -44,6 +44,8 @@ This function returns a list of journeys for given origin and destination stops.
|---|---|---|---|---|---|
| origin | ID of the origin stop. | string | yes | none | `"de:08222:2417"` |
| destination | ID of the destination stop. | string | yes | none | `"de:08221:1146"` |
| via | IDs of the in between stops. | array | no | `[]` | `["de:08221:1146"]` |
| arrivalTime | Desired time of arrival as ISO 8601. Overrides departure time. | string | no | none | `"2021-03-24T21:14:00+01:00` |
| departureTime | Desired time of departure as ISO 8601. Only considered if arrival time is not set. | string | no | now | `"2021-03-24T23:08:00+01:00` |
| maxResults | Maximum amount of results. | number | no | `5` | `15` |
| maxResults | Maximum amount of results. | number | no | `5` | `15` |
| includeFares | Whether you want to retrieve fares. | boolean | no |`false` | `false` |
33 changes: 33 additions & 0 deletions docs/example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { inspect } from "util";
import { getClient } from "../lib";

const sbbProfile = {
// Test environment of SBB
// See here: https://opentransportdata.swiss/de/cookbook/abfahrts-ankunftsanzeiger/
url: "https://api.opentransportdata.swiss/trias2020",
requestorRef: "trias-client",
headers: {
authorization: "57c5dbbbf1fe4d000100001842c323fa9ff44fbba0b9b925f0c052d1",
}
};

const zürich = "8503000";
const luzern = "8505000";
const aarau = "8502113";

const client = getClient(sbbProfile);

// To Do: Add examples for station search and departures

async () => {
const journeys = await client.getJourneys({
origin: zürich,
destination: luzern,
via: [aarau],
departureTime: "2021-05-20T14:00+02:00",
maxResults: 2,
includeFares: true,
});

console.log(inspect(journeys, { depth: null, colors: true }));
};
Loading

0 comments on commit 007e2da

Please sign in to comment.