forked from UPCnet/angular-maxclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMAXClient.js
85 lines (74 loc) · 2.66 KB
/
MAXClient.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
'use strict';
/**
* @ngdoc function
* @name MAXClient
* @description
* # Factories for accessing to a MAXServer.
*/
var MAXClient = angular.module('MAXClient', []);
MAXClient.factory('Contexts', ['$resource', 'MAXInfo', function($resource, MAXInfo) {
return $resource(MAXInfo.max_server+'/contexts', null, {
search: {method:'GET', params: {tags:'@tags', hash:'@hash'}, headers:MAXInfo.headers, isArray: true},
});
}]);
MAXClient.factory('ApiInfo', ['$resource', 'MAXInfo', function($resource, MAXInfo) {
return $resource(MAXInfo.max_server+'/info/api', null, {
query: {method:'GET'},
by_category: {method:'GET', params: {by_category:'1'}, isArray: true},
});
}]);
MAXClient.factory('ContextActivities', ['$http', 'MAXInfo', function($http, MAXInfo) {
// Head requests should be used with $http, as the values are in headers.
var self = this;
self.get_count = function(hash) {
return $http.head(MAXInfo.max_server+'/contexts/' + hash + '/activities',
{headers:MAXInfo.headers});
};
return self;
}]);
MAXClient.factory('UserActivities', ['$http', 'MAXInfo', function($http, MAXInfo) {
// Head requests should be used with $http, as the values are in headers.
var self = this;
self.get_count = function(username) {
return $http.head(MAXInfo.max_server+'/people/' + username + '/activities',
{headers:MAXInfo.headers});
};
return self;
}]);
MAXClient.factory('MAXInfo', ['MAXSession', '_MAXUI', function(MAXSession, _MAXUI) {
var maxinfo = {};
if (_MAXUI) {
maxinfo.headers = {'X-Oauth-Username': _MAXUI.username,
'X-Oauth-Token': _MAXUI.oauth_token,
'X-Oauth-Scope': 'widgetcli'};
maxinfo.max_server = _MAXUI.max_server;
} else {
maxinfo.headers = {'X-Oauth-Username': MAXSession.username,
'X-Oauth-Token': MAXSession.oauth_token,
'X-Oauth-Scope': 'widgetcli'};
maxinfo.max_server = MAXSession.max_server;
}
return maxinfo;
}]);
MAXClient.value('MAXSession', {
username: '',
oauth_token: '',
max_server: ''
});
MAXClient.factory('_MAXUI', [function() {
if (window._MAXUI !== undefined) {
return window._MAXUI;
} else {
return false;
}
}]);
MAXClient.directive('oauthinfo', [function() {
return {
restrict: 'E',
controller: function($scope, $element, $attrs, MAXSession) {
MAXSession.username = $attrs.username;
MAXSession.oauth_token = $attrs.oauthToken;
MAXSession.max_server = $attrs.maxServer;
}
};
}]);