-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathusers.js
More file actions
80 lines (59 loc) · 1.47 KB
/
users.js
File metadata and controls
80 lines (59 loc) · 1.47 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
/*
# Users features
## Setup
```javascript
const GitHubClient = require('../libs/GitHubClient.js').GitHubClient;
const users = require('../libs/features/users');
let githubCli = new GitHubClient({
baseUri: "http://github.at.home/api/v3",
token: process.env.TOKEN_GHITHUB_ENTERPRISE
}, users); //<-- add users features
```
*/
/*
## fetchUser
- parameter: `handle`
- return: `Promise`
### Description
`fetchUser` gets the information of a user (`handle`)
*/
function fetchUser({handle}) { // get user data
return this.getData({path:`/users/${handle}`})
.then(response => {
return response.data;
});
}
/*
## suspendUser
- parameter: `handle`
- return: `Promise`
### Description
`suspendUser` suspends a user (`handle`)
*/
function suspendUser({handle}) { //https://developer.github.com/v3/users/administration/#suspend-a-user
this.headers["Content-Length"] = 0;
return this.putData({path:`/users/${handle}/suspended`, data:null})
.then(response => {
delete this.headers["Content-Length"];
return response
})
}
/*
## unsuspendUser
- parameter: `handle`
- return: `Promise`
### Description
`unsuspendUser` cancels a user suspension (`handle`)
*/
function unsuspendUser({handle}) {
return this.deleteData({path:`/users/${handle}/suspended`})
.then(response => {
delete this.headers["Content-Length"];
return response
})
}
module.exports = {
fetchUser: fetchUser,
suspendUser: suspendUser,
unsuspendUser: unsuspendUser
};