diff --git a/README.md b/README.md index c7bd575..435f22e 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ zulip.callEndpoint('/messages', 'POST', params); | `zulip.users.create()` | POST `/users` | create a new user. | | `zulip.users.me.subscriptions.remove()` | DELETE `/users/me/subscriptions` | remove subscriptions. | | `zulip.users.me.pointer.update()` | POST `users/me/pointer` | updates the pointer for the user, for moving the home view. Accepts a message id. This has the side effect of marking some messages as read. Will not return success if the message id is invalid. Will always succeed if the id is less than the current value of the pointer (the id of the last message read). | - +| `zulip.server.settings()` | GET `/server_settings` | returns a dictionary of server settings. | # Testing Use `npm test` to run the tests. diff --git a/examples/server.js b/examples/server.js new file mode 100644 index 0000000..2be1714 --- /dev/null +++ b/examples/server.js @@ -0,0 +1,11 @@ +const zulip = require('../lib/'); + +const config = { + username: process.env.ZULIP_USERNAME, + apiKey: process.env.ZULIP_API_KEY, + realm: process.env.ZULIP_REALM, +}; + +zulip(config).then((z) => { + z.server.settings().then(console.log); +}).catch(err => console.log(err.messag)); diff --git a/src/index.js b/src/index.js index ecdbebd..66112ed 100644 --- a/src/index.js +++ b/src/index.js @@ -13,6 +13,7 @@ const users = require('./resources/users'); const emojis = require('./resources/emojis'); const typing = require('./resources/typing'); const reactions = require('./resources/reactions'); +const server = require('./resources/server'); function callEndpoint(endpoint, method = 'GET', params) { let finalendpoint = endpoint; @@ -36,6 +37,7 @@ function resources(config) { emojis: emojis(config), typing: typing(config), reactions: reactions(config), + server: server(config), }; } diff --git a/src/resources/server.js b/src/resources/server.js new file mode 100644 index 0000000..83d5f95 --- /dev/null +++ b/src/resources/server.js @@ -0,0 +1,12 @@ +const api = require('../api'); + +function server(config) { + return { + settings: (params) => { + const url = `${config.apiURL}/server_settings`; + return api(url, config, 'GET', params); + }, + }; +} + +module.exports = server; diff --git a/test/resources/server.js b/test/resources/server.js new file mode 100644 index 0000000..aab21a6 --- /dev/null +++ b/test/resources/server.js @@ -0,0 +1,44 @@ +const server = require('../../lib/resources/server'); +const common = require('../common'); +const chai = require('chai'); +chai.use(require('chai-as-promised')); + +chai.should(); + +describe('Server', () => { + it('should fetch server settings', (done) => { + const validator = (url, options) => { + url.should.contain(`${common.config.apiURL}/server_settings`); + options.should.not.have.property('body'); + options.method.should.be.equal('GET'); + }; + const output = { + realm_name: 'Zulip Community', + realm_icon: '/user_avatars/2/realm/icon.png?version=2', + realm_description: '

Welcome to the Zulip development and user community!

\n

Join to get a quick Zulip demo, observe a healthy Zulip community, offer feedback to the Zulip core team, or get involved in as a contributor.

\n\n

Note that this server runs a bleeding-edge version of Zulip, so you may encounter bugs. Please report them!

', + require_email_format_usernames: true, + result: 'success', + authentication_methods: { + password: true, + ldap: false, + remoteuser: false, + dev: false, + github: true, + email: true, + google: true, + }, + zulip_version: '1.9.0-rc1+git', + realm_uri: 'https://chat.zulip.org', + email_auth_enabled: true, + push_notifications_enabled: true, + msg: '', + }; + const stubs = common.getStubs(validator, output); + server(common.config).settings() + .then((data) => { + data.should.have.property('result', 'success'); + common.restoreStubs(stubs); + done(); + }).catch(done); + }); +});