mirror of
				https://github.com/public-transport/db-vendo-client.git
				synced 2025-11-04 01:56:33 +02:00 
			
		
		
		
	query departures
This commit is contained in:
		
							parent
							
								
									eb98123e5b
								
							
						
					
					
						commit
						f86f908dcc
					
				
					 1 changed files with 34 additions and 2 deletions
				
			
		
							
								
								
									
										36
									
								
								index.js
									
										
									
									
									
								
							
							
						
						
									
										36
									
								
								index.js
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -9,8 +9,40 @@ const createClient = (profile) => {
 | 
			
		|||
		throw new Error('profile.timezone must be a string.')
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	const client = data => request(profile, data)
 | 
			
		||||
	return client
 | 
			
		||||
	const departures = (station, opt = {}) => {
 | 
			
		||||
		if ('string' !== typeof station) throw new Error('station must be a string.')
 | 
			
		||||
 | 
			
		||||
		opt = Object.assign({
 | 
			
		||||
			direction: null, // only show departures heading to this station
 | 
			
		||||
			duration:  10 // show departures for the next n minutes
 | 
			
		||||
		}, opt)
 | 
			
		||||
		opt.when = opt.when || new Date()
 | 
			
		||||
		const products = profile.formatProducts(opt.products || {})
 | 
			
		||||
 | 
			
		||||
		const dir = opt.direction ? profile.formatStation(opt.direction) : null
 | 
			
		||||
		return request(profile, {
 | 
			
		||||
			meth: 'StationBoard',
 | 
			
		||||
			req: {
 | 
			
		||||
	        	type: 'DEP',
 | 
			
		||||
				date: profile.formatDate(profile, opt.when),
 | 
			
		||||
				time: profile.formatTime(profile, opt.when),
 | 
			
		||||
				stbLoc: profile.formatStation(station),
 | 
			
		||||
				dirLoc: dir,
 | 
			
		||||
				jnyFltrL: [
 | 
			
		||||
					profile.formatProducts(opt.products) // todo
 | 
			
		||||
				],
 | 
			
		||||
				dur: opt.duration,
 | 
			
		||||
		        getPasslist: false
 | 
			
		||||
			}
 | 
			
		||||
		})
 | 
			
		||||
		.then((d) => {
 | 
			
		||||
			if (!Array.isArray(d.jnyL)) return [] // todo: throw err?
 | 
			
		||||
			const parse = profile.parseDeparture(profile, d.locations, d.lines, d.remarks)
 | 
			
		||||
			return d.jnyL.map(parse)
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return {departures}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
module.exports = createClient
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue