Find a file
2017-11-29 02:27:04 +01:00
format pull out bitmask parsing from profiles 2017-11-27 20:30:53 +01:00
lib expose only supported methods, fix test helpers 🐛 2017-11-27 20:33:34 +01:00
p expose only supported methods, fix test helpers 🐛 2017-11-27 20:33:34 +01:00
parse pull out bitmask parsing from profiles 2017-11-27 20:30:53 +01:00
test fix build 💚 2017-11-29 02:27:04 +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 readme, example 📝 2017-11-13 00:38:09 +01:00
index.js expose only supported methods, fix test helpers 🐛 2017-11-27 20:33:34 +01:00
license.md pass line name, Gitter badge, 0.6.2 2017-02-27 16:51:19 +01:00
package.json fix build 💚 2017-11-29 02:27:04 +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.