forked from ThomasLambert/JiveAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpersons.gs
More file actions
94 lines (74 loc) · 2.69 KB
/
persons.gs
File metadata and controls
94 lines (74 loc) · 2.69 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
//#####################################
// Title: Persons API (standard Jive REST API v3)
// Description : All API functions around the persons
// Author: Thomas Lambert
// Date : 01/26/2015
// Version : 1.0
//#####################################
function getMultiplePeopleById( userIdList , numberOfResults , logJson ){
var idsStr = "";
for( var i in userIdList ){
idsStr = idsStr + userIdList[i];
if( i < userIdList.length - 1 ) idsStr = idsStr + ",";
}
Logger.log( BASEURL + "/people/?count=100&ids=" + idsStr );
return fetch( BASEURL + "/people/?count=100&ids=" + idsStr, options("get"), logJson );
}
function disableUser(userId, logJson) {
Logger.log( userId );
// The Jive object insinde the people object will be set to non enabled
var person = fetch( BASEURL + "/people/" + userId, options("get"), logJson);
var disabled = {
"name" : person.name,
"emails" : person.emails,
"jive" : {
"username" : person.jive.username,
"enabled" : false
}
};
return fetch( BASEURL + "/people/" + userId, options( "put" , disabled ), logJson).jive.enabled;
}
function getEnabledStatus( userId , logJson ){
return fetch( BASEURL + "/people/" + userId , options("get"), logJson).jive.enabled;
}
function getPersonByEmail(email , logJson){
return fetch( BASEURL + "/people/email/" + email , options("get"), logJson);
}
function getUserId(email , logJson){
return fetch( BASEURL + "/people/email/" + email , options("get"), logJson).id;
}
function getUserEmail(email , logJson){
// the email passed in argument is actually the username which can be different than the email
// The username is based on the email, but can NEVER change. The email has sometimes changed in Lafarge
// (ext user being hired, someone get married)
return fetch( BASEURL + "/people/email/" + email , options("get"), logJson);
}
function getMembership(){
var userId = 18824;
var url = BASEURL + "/members/people/" + userId + "?count=100";
var result = fetch( url , options("get") );
for(var i in result.list )
Logger.log( result.list[i].group.displayName );
}
function createPerson(logJson){
// fill the following object and launch the function in order to create a new person in the system
// => not functionnal, returns a 500 error ??
var newPerson =
{
"emails" : [ {
"value" : "",
"type" : "work",
"primary" : true,
"jive_label" : "Email"
} ],
"jive" : {
"password" : "",
"username" : ""
},
"name" : {
"familyName" : "Contact",
"givenName" : "Test"
}
};
var result = fetch( BASEURL + "/people/", options( "post" , newPerson) , logJson );
}