mirror of https://github.com/zulip/zulip.git
js_examples: Migrate and test remove_subscriptions example.
This commit is contained in:
parent
db303ccaef
commit
cc4086e98a
|
@ -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}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue