-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGitHubStatusUpdater.ts
46 lines (40 loc) · 1.31 KB
/
GitHubStatusUpdater.ts
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
import fetch from 'node-fetch';
import nodeEmoji from 'node-emoji';
export class GitHubStatusUpdater {
protected readonly baseurl = 'https://api.github.com/graphql';
protected authToken: string;
constructor (authToken: string) {
this.authToken = authToken;
}
async updateStatus (emojiString: string, message: string, limitedAvailability: boolean = false) {
let emoji = null;
if (emojiString) {
emoji = nodeEmoji.get(emojiString);
}
const clientMutationId = 'test';
const query = `mutation ChangeUserStatus($input: ChangeUserStatusInput!) {
changeUserStatus(input: $input) {
clientMutationId
}
}`;
return await fetch(this.baseurl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer ' + this.authToken
},
body: JSON.stringify({
query,
variables: {
input: {
emoji,
message,
limitedAvailability,
clientMutationId
}
}
})
});
}
}