Find a file
2017-12-16 02:28:09 +01:00
format more fixes for 3811b45 🐛 2017-12-12 23:40:12 +01:00
lib deal with some todos, add more 2017-12-12 04:04:41 +01:00
p comply with FPTF 1.0.1, using validate-fptf 2017-12-16 01:56:59 +01:00
parse update validate-fptf 🐛, expose movement trip, add more todos 2017-12-16 02:28:09 +01:00
test comply with FPTF 1.0.1, using validate-fptf 2017-12-16 01:56:59 +01:00
.editorconfig Node 6+, cleanup 2016-12-14 00:22:02 +01:00
.gitignore init 2016-06-22 02:11:13 +02:00
.travis.yml prepare for larger changes 2017-11-11 21:24:30 +01:00
example.js VBB: parse tickets, change client ID 2017-12-11 15:42:35 +01:00
index.js deal with some todos, add more 2017-12-12 04:04:41 +01:00
license.md pass line name, Gitter badge, 0.6.2 2017-02-27 16:51:19 +01:00
package.json update validate-fptf 🐛, expose movement trip, add more todos 2017-12-16 02:28:09 +01:00
readme.md VBB profile 2017-11-18 17:53:12 +01:00

hafas-client

A client for HAFAS public transport APIs. Sort of like public-transport-enable, but with a smaller scope. It also contains customisations for the following transport networks:

npm version build status ISC-licensed chat on gitter

Background

There's a company called HaCon that sells a public transport management system called HAFAS. It is used by companies all over Europe to serve routing and departure information for apps. All those endpoints are similar, with the same terms and API routes, but have slightly different options, filters and enable features.

hafas-client contains all logic for communicating with these, as well as serialising from and parsing to FPTF. Endpoint-specific customisations increase the quality of the returned data.

Installing

npm install hafas-client

Usage

const createClient = require('hafas-client')
const dbProfile = require('hafas-client/p/db')

const client = createClient(dbProfile)

// Berlin Jungfernheide to München Hbf
client.journeys('8011167', '8000261', {results: 1})
.then(console.log)
.catch(console.error)
[ {
	origin: {
		type: 'station',
		id: '8089100',
		name: 'Berlin Jungfernheide (S)',
		coordinates: {
			latitude: 52.530291,
			longitude: 13.299451
		},
		products: { /* … */ }
	},
	departure: '2017-11-13T01:00:00Z',

	destination: {
		type: 'station',
		id: '8000261',
		name: 'München Hbf',
		coordinates: {
			latitude: 48.140364,
			longitude: 11.558735
		},
		products: { /* … */ }
	},
	arrival: '2017-11-13T09:39:00Z',

	parts: [ {
		id: '1|1436339|0|80|12112017',

		origin: {
			type: 'station',
			id: '8089100',
			name: 'Berlin Jungfernheide (S)',
			coordinates: {
				latitude: 52.530291,
				longitude: 13.299451
			},
			products: {
				nationalExp: false,
				national: false,
				regionalExp: false,
				regional: true,
				suburban: true,
				bus: true,
				ferry: false,
				subway: true,
				tram: false,
				taxi: false
			}
		},
		departure: '2017-11-13T00:50:00Z',
		departurePlatform: '6',

		destination: {
			type: 'station',
			id: '8089047',
			name: 'Berlin Westkreuz',
			coordinates: {
				latitude: 52.500752,
				longitude: 13.283854
			},
			products: {
				nationalExp: false,
				national: false,
				regionalExp: false,
				regional: true,
				suburban: true,
				bus: true,
				ferry: false,
				subway: false,
				tram: false,
				taxi: false
			}
		},
		arrival: '2017-11-13T00:57:00Z',
		delay: 0,

		line: {
			type: 'line',
			name: 'S 42',
			mode: 'train',
			product: 'suburban',
			class: 16,
			productCode: 4,
			productName: 's'
		},
		direction: 'Ringbahn <-',
		arrivalPlatform: '12'
	}, {
		id: '1|332491|0|80|12112017',

		origin: { /* … */ },
		departure: '2017-11-13T01:05:00Z',
		departurePlatform: '3',

		destination: { /* … */ },
		arrival: '2017-11-13T01:18:00Z',
		delay: 0,

		line: { /* … */ },
		direction: 'Berlin Ostbahnhof'
	}, {
		origin: { /* … */ },
		departure: '2017-11-13T01:18:00Z',
		destination: { /* … */ },
		arrival: '2017-11-13T01:26:00Z',
		mode: 'walking'
	}, {
		 /* … */
	} ]
} ]

Contributing

If you have a question, found a bug or want to propose a feature, have a look at the issues page.