-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathservice.js
52 lines (44 loc) · 1.34 KB
/
service.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
var merge = require('extend');
var Emitter = require('extended-emitter');
var request = require('request');
//RIP xboxapi.duncanmackenzie.net, xboxleaders.com
// http://gamercard.xbox.com/en-US/<gamertag>.card
function XBoxLiveService(options){
(new Emitter()).onto(this);
}
XBoxLiveService.prototype.parseResponse = function(response, body, callback){
setTimeout(function(){
callback(JSON.parse(body));
}, 1);
}
XBoxLiveService.prototype.normalizeFieldNames = function(data){
return data;
}
XBoxLiveService.prototype.fetch = function(options, callback){
var unifiedOptions = merge(this.options, options);
var ob = this;
// todo: normalizeFieldNames
request({
method: options.method || 'GET',
uri: ob.transformURL(this.url, options)
}, function (error, response, body) {
try{
var result = ob.parseResponse(response, body, function(err, res){
callback(err, res);
});
}catch(err){
callback(err);
}
});
}
//make all options available to the url
XBoxLiveService.prototype.transformURL = function(url, opts){
var options = this.options || opts;
Object.keys(options).forEach(function(optionName){
if(url.indexOf('{'+optionName+'}' != -1)){
url = url.replace('{'+optionName+'}', options[optionName]);
}
});
return url;
}
module.exports = XBoxLiveService;