Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More

@unicsmcr/unics_social_api_client

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@unicsmcr/unics_social_api_client

networking for CS students at the University of Manchester


Version published
Weekly downloads
3
Maintainers
4
Weekly downloads
 
Created

UniCS Social: API Client

Tests Lint codecov

⚠️ Warning! This module is still unstable and will likely have major breaking changes in later versions.

A TypeScript API Client for UniCS's networking platform for Computer Sciences students at the University of Manchester.

Example

import { APIClient, GatewayPacketType } from '@unicsmcr/unics_social_api_client';

const api = new APIClient();

await api.authenticate({
	email: prompt('Email'),
	password: prompt('Password')
});

api.initGateway();

// It's bad practice to have an event handler that returns a Promise, but this is just for demo purposes
api.gateway.on(GatewayPacketType.Hello, async () => {
	alert('Connected to gateway!');

	// Fetch the list of events
	const events = await api.getEvents();

	// Get the user/profile information for the authenticated user
	const me = await api.getMe();

	// Send a message to the channel of the first-listed event
	await api.createMessage({
		content: `Hi! I'm ${me.forename} :)`,
		channelID: events[0].channelID
	});
});

// Event listener for whenever a message is created in a channel that the user has access to
api.gateway.on(GatewayPacketType.MessageCreate, async data => {
	const { message } = data;
	console.log(`${message.authorID} sent ${message.content} in ${message.channelID}`);
});

// Event listener for whenever a message is deleted in a channel that the user has access to
api.gateway.on(GatewayPacketType.MessageDelete, async data => {
	const { channelID, messageID } = data;
	console.log(`${messageID} was deleted in ${channelID}`);
});

api.gateway.on('reconnecting', () => {
	alert('Connection dropped, attempting to reconnect.');
});

License

Copyright 2020 UniCS

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

FAQs

Package last updated on 30 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts