BetterDiscordApp-v2/client/src/modules/bdwebapi.js

83 lines
1.9 KiB
JavaScript
Raw Normal View History

2018-08-06 12:31:49 +02:00
/**
* BetterDiscord Web Apis
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks
* All rights reserved.
* https://betterdiscord.net
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
2018-12-04 08:22:04 +01:00
import ServerEmu from '../dev/serveremu';
2018-08-06 12:31:49 +02:00
import { request } from 'vendor';
const APIBASE = 'ifyouareinwebtestthenyouknowwhatthisshouldbe'; // Do not push
const ENDPOINTS = {
'themes': `${APIBASE}/themes`,
2018-08-06 16:05:36 +02:00
'theme': id => `${APIBASE}/theme/${id}`,
2018-08-06 12:31:49 +02:00
'users': `${APIBASE}/users`,
2018-08-06 16:05:36 +02:00
'user': id => `${APIBASE}/user/${id}`,
2018-08-06 12:31:49 +02:00
'statistics': `${APIBASE}/statistics`
};
export default class BdWebApi {
2018-08-06 16:05:36 +02:00
static get themes() {
return {
get: this.getThemes
};
2018-08-06 12:31:49 +02:00
}
2018-12-05 09:58:43 +01:00
static get plugins() {
return {
get: this.getPlugins
};
}
2018-08-06 16:05:36 +02:00
static get users() {
return {
get: this.getUsers
};
2018-08-06 12:31:49 +02:00
}
2018-08-06 16:05:36 +02:00
static get statistics() {
return {
get: this.getStatistics,
patch: this.patchStatistics
};
}
static getThemes(args) {
2018-12-04 08:22:04 +01:00
return ServerEmu.themes(args);
2018-12-06 10:23:31 +01:00
// return dummyThemes();
2018-12-02 03:13:57 +01:00
/*
2018-08-06 16:05:36 +02:00
if (!args) return request.get(ENDPOINTS.themes);
const { id } = args;
if (id) return request.get(ENDPOINTS.theme(id));
return request.get(ENDPOINTS.themes);
2018-12-02 03:13:57 +01:00
*/
2018-08-06 16:05:36 +02:00
}
2018-12-05 09:58:43 +01:00
static getPlugins(args) {
return ServerEmu.plugins(args);
}
2018-08-06 16:05:36 +02:00
static getUsers(args) {
if (!args) return request.get(ENDPOINTS.users);
const { id } = args;
if (id) return request.get(ENDPOINTS.user(id));
return request.get(ENDPOINTS.users);
}
static getStatistics() {
return request.get(ENDPOINTS.statistics);
}
static patchStatistics(json) {
return request({ method: 'PATCH', url: ENDPOINTS.statistics, json });
2018-08-06 12:31:49 +02:00
}
}