forked from bendl/node-xbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXbox.js
55 lines (44 loc) · 1.08 KB
/
Xbox.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
'use strict';
Xbox.DEFAULT_HOST = "xboxapi.com";
Xbox.DEFAULT_BASE_PATH = "/v2/";
var resources = {
Account: require('./resources/account'),
Game: require('./resources/game'),
Profile: require('./resources/profile')
};
/*
account:
/accountXuid
/messages
profile:
/{xuid}/profile
*/
Xbox.XboxResource = require('./XboxResource');
function Xbox(key, options) {
if (key == undefined)
throw new Error("xbox-node API key missing. E.g. require('xbox-node')('myApiKey')")
if (!(this instanceof Xbox)) {
return new Xbox(key, options);
}
this._api = {
auth: null,
host: Xbox.DEFAULT_HOST,
basePath: Xbox.DEFAULT_BASE_PATH,
key: key
};
this._prepResources();
};
Xbox.prototype = {
_prepResources: function(){
for(var name in resources){
this[name[0].toLowerCase() + name.substr(1)] = new resources[name](this);
}
},
_setApiField: function(key, value){
this._api[key] = value;
},
_getApiField: function(key){
return this._api[key];
}
};
module.exports = Xbox;