aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/zulip/index.js
blob: 8bad3cf524e4fe10eabe46506b5ab0426a5f389a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module.exports = Ferdi => class Zulip extends Ferdi {
  async validateUrl(url) {
    const baseUrl = new window.URL(url);
    const apiVersion = 'api/v1';
    try {
      const resp = await window.fetch(`${baseUrl.origin}/${apiVersion}/server_settings`, {
        method: 'GET',
        headers: {
          'Content-Type': 'application/json',
        },
      });
      const data = await resp.json();

      return Object.hasOwnProperty.call(data, 'realm_uri');
    } catch (error) {
      console.error(error);
    }

    return false;
  }
};