js_examples: Migrate and test remove_subscriptions example.

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

View File

@ -12,29 +12,8 @@
{tab|js}
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) => {
// Unsubscribe from the stream "Denmark"
const meParams = {
subscriptions: JSON.stringify(['Denmark']),
};
client.users.me.subscriptions.remove(meParams).then(console.log);
// Unsubscribe Zoe from the stream "Denmark"
const zoeParams = {
subscriptions: JSON.stringify(['Denmark']),
principals: JSON.stringify(['ZOE@zulip.org']),
};
client.users.me.subscriptions.remove(zoeParams).then(console.log);
});
```
{generate_code_example(javascript)|/users/me/subscriptions:delete|example}
{tab|curl}

View File

@ -49,6 +49,7 @@ const ExamplesHandler = function () {
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);
await generate_validation_data(client, examples.remove_subscriptions);
console.log(JSON.stringify(response_data));
return;
@ -257,4 +258,25 @@ add_example('add_subscriptions', '/users/me/subscriptions:post', 200, async (cli
return [result_1, result_2];
});
add_example('remove_subscriptions', '/users/me/subscriptions:delete', 200, async (client) => {
// {code_example|start}
// Unsubscribe from the stream "Denmark"
const meParams = {
subscriptions: JSON.stringify(['Denmark']),
};
const result_1 = await client.users.me.subscriptions.remove(meParams);
// {code_example|end}
// {code_example|start}
const user_id = 7;
// Unsubscribe Zoe from the stream "Denmark"
const zoeParams = {
subscriptions: JSON.stringify(['Denmark']),
principals: JSON.stringify([user_id]),
};
const result_2 = await client.users.me.subscriptions.remove(zoeParams);
// {code_example|end}
return [result_1, result_2];
});
main();