summaryrefslogtreecommitdiff
path: root/ui/lib/apiServer.js
blob: c65b7436e8e972436a7926d0f4bc80579b1a9ac2 (plain)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import axios from 'axios';

export const apiServer = axios.create({
  baseURL: '/api/',
  validateStatus: () => true
});

export async function boot() {
  return apiServer.get('/boot');
}

export async function setup(name, password) {
  return apiServer.post('/setup', { name, password });
}

export async function logIn(name, password) {
  return apiServer.post('/auth/login', { name, password });
}

export async function logOut() {
  return apiServer.post('/auth/logout', {});
}

export async function changePassword(password, to) {
  return apiServer.post('/password', { password, to });
}

export async function createChannel(name) {
  return apiServer.post('/channels', { name });
}

export async function postToChannel(channelId, body) {
  return apiServer.post(`/channels/${channelId}`, { body });
}

export async function deleteMessage(messageId) {
  return apiServer.delete(`/messages/${messageId}`, {});
}

export async function createInvite() {
  return apiServer.post(`/invite`, {});
}

export async function getInvite(inviteId) {
  return apiServer.get(`/invite/${inviteId}`);
}

export async function acceptInvite(inviteId, username, password) {
  const data = {
    name: username,
    password
  };
  return apiServer.post(`/invite/${inviteId}`, data);
}

export function subscribeToEvents(resumePoint) {
  const eventsUrl = apiServer.getUri({
    url: '/events',
    params: {
      resume_point: resumePoint
    }
  });
  return new EventSource(eventsUrl);
}