Skip to content

Commit 554ba9d

Browse files
committed
Add endpoint to get realm emojis.
1 parent 901466d commit 554ba9d

File tree

5 files changed

+62
-0
lines changed

5 files changed

+62
-0
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ zulip.callEndpoint('/messages', 'POST', params);
110110
| `zulip.users.create()` | POST `/users` | create a new user. |
111111
| `zulip.users.me.subscriptions.remove()` | DELETE `/users/me/subscriptions` | remove subscriptions. |
112112
| `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). |
113+
| `zulip.realm.retrieve()` | GET `realm/emoji` | returns a dictionary of all the emojis in a realm |
113114

114115
# Testing
115116

Diff for: examples/realm.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const zulip = require('../lib/');
2+
3+
const config = {
4+
username: process.env.ZULIP_USERNAME,
5+
apiKey: process.env.ZULIP_API_KEY,
6+
realm: process.env.ZULIP_REALM,
7+
};
8+
9+
zulip(config).then((z) => {
10+
z.realm.retrieve().then(console.log);
11+
}).catch(err => console.log(err.message));

Diff for: src/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const users = require('./resources/users');
1313
const emojis = require('./resources/emojis');
1414
const typing = require('./resources/typing');
1515
const reactions = require('./resources/reactions');
16+
const realm = require('./resources/realm');
1617

1718
function callEndpoint(endpoint, method = 'GET', params) {
1819
let finalendpoint = endpoint;
@@ -36,6 +37,7 @@ function resources(config) {
3637
emojis: emojis(config),
3738
typing: typing(config),
3839
reactions: reactions(config),
40+
realm: realm(config),
3941
};
4042
}
4143

Diff for: src/resources/realm.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const api = require('../api');
2+
3+
function realm(config) {
4+
return {
5+
retrieve: (params) => {
6+
const url = `${config.apiURL}/realm/emoji`;
7+
return api(url, config, 'GET', params);
8+
},
9+
};
10+
}
11+
12+
module.exports = realm;

Diff for: test/resources/realm.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const realm = require('../../lib/resources/realm');
2+
const common = require('../common');
3+
const chai = require('chai');
4+
chai.use(require('chai-as-promised'));
5+
6+
chai.should();
7+
8+
describe('Realm', () => {
9+
it('should fetch realm emojis', (done) => {
10+
const validator = (url, options) => {
11+
url.should.equal(`${common.config.apiURL}/realm/emoji`);
12+
options.should.not.have.property('body');
13+
options.method.should.be.equal('GET');
14+
};
15+
const output = {
16+
emoji: {
17+
3: {
18+
author: null,
19+
deactivated: false,
20+
name: 'jenkins',
21+
id: '3',
22+
source_url: '/user_avatars/2/emoji/images/3.png',
23+
},
24+
},
25+
msg: '',
26+
result: 'success',
27+
};
28+
const stubs = common.getStubs(validator, output);
29+
realm(common.config).retrieve()
30+
.then((data) => {
31+
data.should.have.property('result', 'success');
32+
common.restoreStubs(stubs);
33+
done();
34+
}).catch(done);
35+
});
36+
});

0 commit comments

Comments
 (0)