Find a file
2017-12-29 10:16:41 +01:00
docs docs, tests: rename journey.parts -> journey.legs 📝 2017-12-28 17:14:53 +01:00
format throw error if products filter is empty 2017-12-28 17:12:46 +01:00
lib rename journey.parts -> journey.legs 2017-12-28 17:13:02 +01:00
p fix typo 2017-12-29 10:16:41 +01:00
parse mark & filter stations that are passed without stopping, as they contain no arrival/departure time information which would violate the fptf spec 2017-12-29 09:00:18 +01:00
test add profile and tests for oebb 2017-12-29 10:01:19 +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
index.js rename journey.parts -> journey.legs 2017-12-28 17:13:02 +01:00
license.md pass line name, Gitter badge, 0.6.2 2017-02-27 16:51:19 +01:00
package.json add juliuste to contributors 2017-12-29 10:04:24 +01:00
readme.md add docs for oebb 2017-12-29 10:15:32 +01:00

hafas-client

A client for HAFAS public transport APIs. Sort of like public-transport-enabler, 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 Friendly Public Transport Format (FPTF) 1.0.1. Endpoint-specific customisations (called "profiles" here) increase the quality of the returned data.

Installing

npm install hafas-client

API

Usage

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

// create a client with Deutsche Bahn profile
const client = createClient(dbProfile)

// Berlin Jungfernheide to München Hbf
client.journeys('8011167', '8000261', {results: 1})
.then(console.log)
.catch(console.error)

The returned Promise will resolved with an array of one journey in the FPTF 1.0.1.

[ {
	legs: [ {
		id: '1|100067|48|81|17122017',
		origin: {
			type: 'station',
			id: '8089100',
			name: 'Berlin Jungfernheide (S)',
			location: {
				type: 'location',
				latitude: 52.530291,
				longitude: 13.299451
			},
			products: { /* … */ }
		},
		departure: '2017-12-17T17:05:00.000+01:00',
		departurePlatform: '5',
		destination: {
			type: 'station',
			id: '8089118',
			name: 'Berlin Beusselstraße',
			location: { /* … */ },
			products: { /* … */ }
		},
		arrival: '2017-12-17T17:08:00.000+01:00',
		arrivalPlatform: '1',
		line: {
			type: 'line',
			id: '41172',
			name: 'S 41',
			public: true,
			mode: 'train',
			product: 'suburban',
			class: 16,
			productCode: 4
		},
		direction: 'Ringbahn ->'
	}, /* … */ {
		origin: {
			type: 'station',
			id: '730749',
			name: 'Berlin Hauptbahnhof (S+U), Berlin',
			location: {
				type: 'location',
				latitude: 52.526461,
				longitude: 13.369378
			},
			products: { /* … */ }
		},
		departure: '2017-12-17T17:25:00.000+01:00',
		destination: {
			type: 'station',
			id: '8098160',
			name: 'Berlin Hbf (tief)',
			location: { /* … */ },
			products: { /* … */ }
		},
		arrival: '2017-12-17T17:33:00.000+01:00',
		mode: 'walking',
		public: true
	}, {
		id: '1|70906|0|81|17122017',
		origin: {
			type: 'station',
			id: '8098160',
			name: 'Berlin Hbf (tief)',
			location: { /* … */ },
			products: { /* … */ }
		},
		departure: '2017-12-17T17:37:00.000+01:00',
		departurePlatform: '1',
		destination: {
			type: 'station',
			id: '8000261',
			name: 'München Hbf',
			location: { /* … */ },
			products: { /* … */ }
		},
		arrival: '2017-12-17T22:45:00.000+01:00',
		arrivalPlatform: '13',
		line: { /* … */ },
		direction: 'München Hbf'
	} ],
	origin: {
		type: 'station',
		id: '8089100',
		name: 'Berlin Jungfernheide (S)',
		location: { /* … */ },
		products: { /* … */ }
	},
	departure: '2017-12-17T17:05:00.000+01:00',
	destination: {
		type: 'station',
		id: '8000261',
		name: 'München Hbf',
		location: { /* … */ },
		products: { /* … */ }
	},
	arrival: '2017-12-17T22:45:00.000+01:00',
	price: {
		amount: null,
		hint: 'No pricing information available.'
	}
} ]

Contributing

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