forked from ThomasLambert/JiveAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbunchball.gs
More file actions
96 lines (79 loc) · 3.04 KB
/
bunchball.gs
File metadata and controls
96 lines (79 loc) · 3.04 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
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
//#####################################
// Title: Bunchball API
// Description : Bunchball is the gamification motor in Jive
// Author: Thomas Lambert
// Date : 01/26/2015
// Version : 1.0
// In order to use this script you have to fill in the API key and the userId in BunchballLogin() function.
//#####################################
function getGroup( groupName ){
var method = 'group.getUsers&returnCount=100&groupName=' + groupName;
var sk = bunchballLogin();
var result;
var users = [];
var url='https://solutions.nitro.bunchball.net/nitro/json?method=' + method + '&sessionKey=' + sk;
result = bunchballLaunch(url);
if( result.Nitro.res = "ok"){
var table = result.Nitro.users.User
for( var i in table ){
users[i] = table[i].userId;
}
}
return users;
}
function userMgmt(userId, groupName , quit) {
// add or removes a user to/from a group
if( quit == false){
var method = "user.leaveGroup"; // choose the method corresponding to desired action
}else{
var method = "user.joinGroup";
}
var sk = bunchballLogin();
var url='https://solutions.nitro.bunchball.net/nitro/json?method=' + method + '&userId=' + userId + '&groupName=' + groupName + '&sessionKey=' + sk;
var result = bunchballLaunch(url);
Logger.log( userId + " " + method + " " + groupName + " " + result.Nitro.res );
return result.Nitro.res
}
function logAction( userId , action , value ) {
// Test the result of a bunchball action
var sk = bunchballLogin();
var method = 'user.logAction&userId=' + userId + '&tags=' + action;
if( typeof value != 'undefined' ) method = method + "&value=" + value;
var url='https://solutions.nitro.bunchball.net/nitro/json?method=' + method + '&sessionKey=' + sk;
var result = bunchballLaunch(url);
Logger.log(result);
return result.Nitro.res;
}
function getPoints( pointsCategory) {
var sk = bunchballLogin();
var method = 'user.getPointsBalance&start=0&criteria=credits&pointCategory=' + pointsCategory;
var url='https://solutions.nitro.bunchball.net/nitro/json?method=' + method + '&sessionKey=' + sk;
bunchballLaunch(url);
}
function bunchballLogin() {
// Authenticate the user in "userID". Return the session key.
var method = 'user.login';
var apiKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
var userId = 'xxxxxx';
var url='https://solutions.nitro.bunchball.net/nitro/json?method=' + method + '&apiKey=' + apiKey + '&userId=' + userId;
var options = {
"contentType" : "application/json",
"method" : "get",
"muteHttpExceptions":true,
};
var json = UrlFetchApp.fetch(url, options).getContentText();
var dataJson = Utilities.jsonParse(json)
var sessionKey = dataJson.Nitro.Login.sessionKey
return sessionKey
}
function bunchballLaunch( url ){
// Executes the API command and returns json data
var options = {
"contentType" : "application/json",
"method" : "get",
"muteHttpExceptions":true,
};
var json = UrlFetchApp.fetch(url, options).getContentText();
var dataJson = Utilities.jsonParse(json);
return dataJson;
}