diff --git a/index.js b/index.js index 616e6a0c..a02fa68e 100644 --- a/index.js +++ b/index.js @@ -12,7 +12,9 @@ const createClient = (profile) => { validateProfile(profile) const departures = (station, opt = {}) => { - if ('string' !== typeof station) throw new Error('station must be a string.') + if ('object' === typeof station) station = profile.formatStation(station.id) + else if ('string' === typeof station) station = profile.formatStation(station) + else throw new Error('station must be an object or a string.') opt = Object.assign({ direction: null, // only show departures heading to this station @@ -28,7 +30,7 @@ const createClient = (profile) => { type: 'DEP', date: profile.formatDate(profile, opt.when), time: profile.formatTime(profile, opt.when), - stbLoc: profile.formatStation(station), + stbLoc: station, dirLoc: dir, jnyFltrL: [products], dur: opt.duration, diff --git a/test/db.js b/test/db.js index 317b3c65..735a9c0f 100644 --- a/test/db.js +++ b/test/db.js @@ -226,6 +226,22 @@ test('departures at Berlin Jungfernheide', co.wrap(function* (t) { t.end() })) +test('departures with station object', co.wrap(function* (t) { + yield client.departures({ + type: 'station', + id: '8011167', + name: 'Berlin Jungfernheide', + location: { + type: 'location', + latitude: 1.23, + longitude: 2.34 + } + }, {when}) + + t.ok('did not fail') + t.end() +})) + test('nearby Berlin Jungfernheide', co.wrap(function* (t) { const nearby = yield client.nearby(52.530273, 13.299433, { results: 2, distance: 400 diff --git a/test/vbb.js b/test/vbb.js index cc9eec9d..156a7580 100644 --- a/test/vbb.js +++ b/test/vbb.js @@ -260,6 +260,22 @@ test('departures', co.wrap(function* (t) { t.end() })) +test('departures with station object', co.wrap(function* (t) { + yield client.departures({ + type: 'station', + id: spichernstr, + name: 'U Spichernstr', + location: { + type: 'location', + latitude: 1.23, + longitude: 2.34 + } + }, {when}) + + t.ok('did not fail') + t.end() +})) + test('departures at 7-digit station', co.wrap(function* (t) { const eisenach = '8010097' // see derhuerst/vbb-hafas#22 yield client.departures(eisenach, {when})