-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
126 lines (100 loc) · 3.21 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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
(function (module) {
/******************************
* Constant definitions.
******************************/
/**
* Default user agent for HTTP requests.
*/
const DEFAULT_UA = 'easy.GO Client Android v1.2.1 (Mozilla/5.0 (Linux; Android 4.4.4; Nexus 4 Build/KTU84Q) ' +
'AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/33.0.0.0 Mobile Safari/537.36)';
/**
* Default API endpoint.
*/
const API_URL = 'http://rnv.the-agent-factory.de:8080/easygo2/rest/regions/rnv/modules/';
/**
* Default client config.
*/
const DEFAULT_CONFIG = {
userAgent: "default"
};
"use strict";
/******************************
* Module imports.
******************************/
var request = require('request');
var querystring = require('querystring');
/******************************
* API client.
******************************/
var rnv = function (opts) {
if (!opts) {
opts = DEFAULT_CONFIG;
}
var proxy = opts.proxy;
var userAgent = opts.userAgent;
if ("default" == userAgent) {
userAgent = DEFAULT_UA;
}
this.stations = function (callback) {
var data = {};
data.path = 'stations/packages/1';
getResult(data, callback);
}
this.stationMonitor = function (query, callback) {
var data = {};
data.query = query;
data.path = "stationmonitor/element";
getResult(data, callback);
}
// For compatiblity reasons.
this.stationmonitor = this.stationMonitor;
this.lines = function (query, callback) {
var data = {};
data.query = query;
data.path = "lines";
getResult(data, callback);
}
this.ticker = function (callback) {
var data = {};
data.path = 'ticker/'
getResult(data, callback);
}
this.tickerCount = function (callback) {
var data = {};
data.path = 'ticker/numberOfNewEntries/0'
getResult(data, callback);
}
this.news = function (callback) {
var data = {};
data.path = 'news/'
getResult(data, callback);
}
this.newsCount = function (callback) {
var data = {};
data.path = 'news/numberOfNewEntries/0'
getResult(data, callback);
}
function getResult(data, callback) {
var query = "";
if (data.query)
query = "?" + querystring.stringify(data.query);
var url = API_URL + data.path + query;
request.get({url: url, json: true, proxy: proxy}, function (err, res, body) {
callback(body);
//callback(err, body);
});
}
}
/******************************
* Module exports.
******************************/
/**
* Factory method for API client.
*/
function createClient (opts) {
var client = new rnv(opts);
return client;
}
module.exports = rnv;
module.exports.createClient = createClient;
})(module);