js_examples: Migrate and test add_subscriptions example.

This commit is contained in:
Kartik Srivastava
2020-06-22 03:07:53 +05:30
committed by Tim Abbott
parent cf6e1de0de
commit db303ccaef
2 changed files with 30 additions and 30 deletions

View File

@@ -13,36 +13,7 @@
More examples and documentation can be found [here](https://github.com/zulip/zulip-js).
```js
const zulip = require('zulip-js');
// Pass the path to your zuliprc file here.
const config = {
zuliprc: 'zuliprc',
};
zulip(config).then((client) => {
// Subscribe to the streams "Verona" and "Denmark"
const meParams = {
subscriptions: JSON.stringify([
{'name': 'Verona'},
{'name': 'Denmark'}
]),
};
client.users.me.subscriptions.add(meParams).then(console.log);
// To subscribe another user to a stream, you may pass in
// the `principals` parameter, like so:
const anotherUserParams = {
subscriptions: JSON.stringify([
{'name': 'Verona'},
{'name': 'Denmark'}
]),
principals: JSON.stringify(['ZOE@zulip.org']),
};
client.users.me.subscriptions.add(anotherUserParams).then(console.log);
});
```
{generate_code_example(javascript)|/users/me/subscriptions:post|example}
{tab|curl}

View File

@@ -48,6 +48,7 @@ const ExamplesHandler = function () {
await generate_validation_data(client, examples.register_queue);
await generate_validation_data(client, examples.render_message);
await generate_validation_data(client, examples.set_typing_status);
await generate_validation_data(client, examples.add_subscriptions);
console.log(JSON.stringify(response_data));
return;
@@ -228,4 +229,32 @@ add_example('set_typing_status', '/typing:post', 200, async (client) => {
// {code_example|end}
});
add_example('add_subscriptions', '/users/me/subscriptions:post', 200, async (client) => {
// {code_example|start}
// Subscribe to the streams "Verona" and "Denmark"
const meParams = {
subscriptions: JSON.stringify([
{name: 'Verona'},
{name: 'Denmark'},
]),
};
const result_1 = await client.users.me.subscriptions.add(meParams);
// {code_example|end}
// {code_example|start}
// To subscribe another user to a stream, you may pass in
// the `principals` parameter, like so:
const user_id = 7;
const anotherUserParams = {
subscriptions: JSON.stringify([
{name: 'Verona'},
{name: 'Denmark'},
]),
principals: JSON.stringify([user_id]),
};
const result_2 = await client.users.me.subscriptions.add(anotherUserParams);
// {code_example|end}
return [result_1, result_2];
});
main();