Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ef0484b

Browse files
committed
add rest
1 parent a590c8e commit ef0484b

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

‎public/js/rest.js‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
class RestClient {
2+
constructor(key, authType, api) {
3+
this.api = api || "/api/v1";
4+
this._key = key;
5+
this.authType = authType;
6+
}
7+
8+
fetchUser(user) {
9+
return fetch(`${this.api}/users/${user}`, {
10+
headers: this.computedHeaders
11+
});
12+
}
13+
14+
fetchPromotions() {
15+
return fetch(`${this.api}/promotions`);
16+
}
17+
18+
fetchRooms() {
19+
return fetch(`${this.api}/rooms`);
20+
}
21+
22+
switchBlob(newBlob) {
23+
return fetch(`${this.api}/blobs/switch`, {
24+
method: "POST",
25+
headers: this.computedHeaders,
26+
body: JSON.stringify({ newBlob })
27+
});
28+
}
29+
30+
redeemDailyBonus() {
31+
return fetch(`${this.api}/daily`, {
32+
method: "POST",
33+
headers: this.computedHeaders
34+
});
35+
}
36+
37+
ping() {
38+
const before = Date.now();
39+
return fetch(`${this.api}/ping`).then(() => Date.now() - before);
40+
}
41+
42+
get key() {
43+
return this.authType + " " + this._key;
44+
}
45+
46+
get computedHeaders() {
47+
return {
48+
"Content-Type": "application/json",
49+
Authorization: this.key
50+
}
51+
}
52+
53+
static extractSessionID() {
54+
return document.cookie.split(/;*/).find(v => v.startsWith("session=")).split("=")[1];
55+
}
56+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /