-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
60 lines (49 loc) · 1.16 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
'use strict'
var request = require('request-promise')
var parse = require('./parse')
var HafasClient = function (opts) {
if (!opts.baseUrl) throw new Error('HafasClient requires "baseUrl"')
this.baseUrl = opts.baseUrl
if (!opts.auth) throw new Error('HafasClient requires "auth"')
this.auth = opts.auth
if (!opts.name) throw new Error('HafasClient requires "name"')
this.clientName = opts.name
}
HafasClient.prototype.stationBoard = function (opts) {
var stationId = opts.station
var svcRequest = {
'meth': 'StationBoard',
'req': {
'getPasslist': false,
'stbLoc': {
'extId': stationId,
'type': 'S'
},
'maxJny': 20
}
}
return this.makeRequest({
svcReqL: [svcRequest]
})
.then(resp => parse.board(resp))
}
HafasClient.prototype.makeRequest = function (opts) {
var defaultBody = {
client: {
name: this.clientName || ''
},
auth: {
'aid': this.auth,
'type': 'AID'
},
lang: 'eng',
ver: '1.12'
}
var req = {
url: this.baseUrl,
body: Object.assign({}, defaultBody, opts),
json: true
}
return request(req)
}
module.exports = HafasClient