node-groupme
Version:
The only GroupMe API library that isn't a million years old.
59 lines • 2.24 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const events_1 = __importDefault(require("events"));
const __1 = require("..");
const rest_1 = __importDefault(require("../rest/rest"));
const Websocket_1 = __importDefault(require("../websocket/Websocket"));
const ClientUser_1 = __importDefault(require("./ClientUser"));
class Client extends events_1.default {
constructor(token, options) {
super();
this.options = {
websocket: true,
fetchPartials: {
user: true,
group: true,
member: true,
message: true,
calendar: true,
poll: true,
},
};
this.login = async () => {
const me = await this.rest.api('GET', 'users/me');
this.user = new ClientUser_1.default(this, {
avatar_url: me.image_url,
id: me.user_id,
name: me.name,
});
if (this.options.websocket)
await this.ws.init();
return this;
};
this.logout = async () => {
await this.ws.close();
};
this.token = token;
this.relationships = new __1.RelationshipManager(this);
this.groups = new __1.GroupManager(this);
this.users = new __1.UserManager(this);
this.chats = new __1.ChatManager(this);
this.rest = new rest_1.default(this);
this.ws = new Websocket_1.default(this);
if (typeof options !== 'undefined') {
if (options.websocket === false)
this.options.websocket = false;
let key;
for (key in this.options.fetchPartials)
if (typeof options.fetchPartials === 'boolean')
this.options.fetchPartials[key] = options.fetchPartials;
else if (options.fetchPartials)
this.options.fetchPartials[key] = options.fetchPartials.includes(key);
}
}
}
exports.default = Client;
//# sourceMappingURL=Client.js.map