-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommonAPI.js
104 lines (101 loc) · 4.1 KB
/
commonAPI.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
const ak = require('../config/appkey').common;
const request = require('request');
const convert = require('xml2js')
const urlencode = require('urlencode');
module.exports = {
getBusArriveTime : (stId, busRouteId, ord) => { //버스 실시간 도착정보
return new Promise((resolve, reject)=> {
const options = {
'uri' : `http://ws.bus.go.kr/api/rest/arrive/getArrInfoByRoute?ServiceKey=${ak}&stId=${stId}&busRouteId=${busRouteId}&ord=${ord}`
}
request(options, (err, result)=>{
if(err) reject(err)
else {
convert.parseString(result.body, (err, result)=>{
//console.log(result.ServiceResult.msgBody[0].itemList)
resolve(result.ServiceResult.msgBody[0].itemList);
})
}
})
})
},
getBusRouteList : (busNo) => { //버스 번호로 찾기
return new Promise((resolve, reject)=>{
const options = {
"uri" : `http://ws.bus.go.kr/api/rest/busRouteInfo/getBusRouteList?ServiceKey=${ak}&strSrch=${busNo}`
}
request(options, (err, result)=>{
if(err) reject(err)
else {
convert.parseString(result.body, (err, result)=>{
//console.log(result.ServiceResult.msgBody[0].itemList);
resolve(result.ServiceResult.msgBody[0].itemList);
})
}
})
})
},
getBusRouteInfo : (busRouteId) => { //버스 경로 ID로 정보 조회
return new Promise((resolve, reject)=>{
const options = {
"uri" : `http://ws.bus.go.kr/api/rest/busRouteInfo/getRouteInfo?ServiceKey=${ak}&busRouteId=${busRouteId}`
}
request(options, (err, result)=>{
if(err) reject(err)
else {
convert.parseString(result.body, (err, result)=>{
//console.log(result.ServiceResult.msgBody[0].itemList);
resolve(result.ServiceResult.msgBody[0].itemList);
})
}
})
})
},
getStationByRoute : (busRouteId) => { // 경로 ID 로 노선 경로 목록 조회
return new Promise((resolve,reject)=>{
const options = {
"uri" : `http://ws.bus.go.kr/api/rest/busRouteInfo/getStaionByRoute?ServiceKey=${ak}&busRouteId=${busRouteId}`
}
request(options, (err, result)=>{
if(err) reject(err)
else {
convert.parseString(result.body, (err, result)=>{
resolve(result.ServiceResult.msgBody[0].itemList);
})
}
})
})
},
getStationByName : (stSrch) => {
return new Promise((resolve,reject)=>{
let stationName = urlencode(stSrch);
const options = {
"uri" : `http://ws.bus.go.kr/api/rest/stationinfo/getStationByName?ServiceKey=${ak}&stSrch=${stationName}`
}
request(options, (err, result)=>{
if(err) reject(err)
else {
//console.log(result.body);
convert.parseString(result.body, (err, result)=>{
resolve(result.ServiceResult.msgBody[0].itemList);
})
}
})
})
},
getBusTimeByStation : (arsId, busRouteId) => {
return new Promise((resolve,reject)=>{
const options = {
"uri" : `http://ws.bus.go.kr/api/rest/stationinfo/getBustimeByStation?ServiceKey=${ak}&arsId=${arsId}&busRouteId=${busRouteId}`
}
request(options, (err, result)=>{
if(err) reject(err)
else {
convert.parseString(result.body, (err, result)=>{
resolve(result.ServiceResult.msgBody[0].itemList);
})
}
})
})
}
}