-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsimple-authenticated-service.js
More file actions
57 lines (50 loc) · 1.62 KB
/
simple-authenticated-service.js
File metadata and controls
57 lines (50 loc) · 1.62 KB
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
var XBoxService = require('../service');
var clone = require('extend');
var requiresAuth = ['user', 'friends', 'acheivements', 'games'];
var disabled = {};
var disabledProxy = function(){
throw new Error('API Not yet authenticated!');
}
function MyAuthenticatedService(options){
XBoxService.apply(this, arguments);
var ob = this;
requiresAuth.forEach(function(memberName){
disabled[memberName] = ob[memberName];
ob[memberName] = disabledProxy;
});
this.url = 'http://my-service.domain/{action}/{gamertag}'
this.finishAuthentication = function(){
requiresAuth.forEach(function(memberName){
ob[memberName] = disabled[memberName];
delete disabled[memberName];
});
delete ob.finishAuthentication;
};
}
MyAuthenticatedService.prototype = clone(XBoxService.prototype);
MyAuthenticatedService.prototype.constructor = MyAuthenticatedService;
MyAuthenticatedService.prototype.user = function(options, callback){
this.fetch({
action : 'profile',
gamertag : options.gamertag
}, callback);
}
MyAuthenticatedService.prototype.friends = function(options, callback){
this.fetch({
action : 'friends',
gamertag : options.gamertag
}, callback);
}
MyAuthenticatedService.prototype.acheivements = function(options, callback){
this.fetch({
action : 'acheivements',
gamertag : options.gamertag
}, callback);
}
MyAuthenticatedService.prototype.games = function(options, callback){
this.fetch({
action : 'games',
gamertag : options.gamertag,
ids : options.ids
}, callback);
}