api: Add example for managing alert words.
This example makes use of get_alert_words, add_alert_words and remove_alert_words, three methods that interact with the /users/me/alert_words REST API endpoint.
This commit is contained in:
parent
3070106365
commit
04d6c58cc4
|
@ -897,6 +897,9 @@ class Client(object):
|
||||||
|
|
||||||
def get_alert_words(self):
|
def get_alert_words(self):
|
||||||
# type: () -> Dict[str, Any]
|
# type: () -> Dict[str, Any]
|
||||||
|
'''
|
||||||
|
See examples/alert-words for example usage.
|
||||||
|
'''
|
||||||
return self.call_endpoint(
|
return self.call_endpoint(
|
||||||
url='users/me/alert_words',
|
url='users/me/alert_words',
|
||||||
method='GET'
|
method='GET'
|
||||||
|
@ -904,6 +907,9 @@ class Client(object):
|
||||||
|
|
||||||
def add_alert_words(self, alert_words):
|
def add_alert_words(self, alert_words):
|
||||||
# type: (List[str]) -> Dict[str, Any]
|
# type: (List[str]) -> Dict[str, Any]
|
||||||
|
'''
|
||||||
|
See examples/alert-words for example usage.
|
||||||
|
'''
|
||||||
return self.call_endpoint(
|
return self.call_endpoint(
|
||||||
url='users/me/alert_words',
|
url='users/me/alert_words',
|
||||||
method='POST',
|
method='POST',
|
||||||
|
@ -914,6 +920,9 @@ class Client(object):
|
||||||
|
|
||||||
def remove_alert_words(self, alert_words):
|
def remove_alert_words(self, alert_words):
|
||||||
# type: (List[str]) -> Dict[str, Any]
|
# type: (List[str]) -> Dict[str, Any]
|
||||||
|
'''
|
||||||
|
See examples/alert-words for example usage.
|
||||||
|
'''
|
||||||
return self.call_endpoint(
|
return self.call_endpoint(
|
||||||
url='users/me/alert_words',
|
url='users/me/alert_words',
|
||||||
method='DELETE',
|
method='DELETE',
|
||||||
|
|
31
zulip/zulip/examples/alert-words
Executable file
31
zulip/zulip/examples/alert-words
Executable file
|
@ -0,0 +1,31 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
import zulip
|
||||||
|
|
||||||
|
usage = """alert-words (get | add | remove) [words] [options]
|
||||||
|
|
||||||
|
|
||||||
|
Example: alert-words get
|
||||||
|
Example: alert-words add foo bar
|
||||||
|
Example: alert-words remove banana
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
parser = zulip.add_default_arguments(argparse.ArgumentParser(usage=usage))
|
||||||
|
parser.add_argument('operation', choices=['get', 'add', 'remove'], type=str)
|
||||||
|
parser.add_argument('words', type=str, nargs='*')
|
||||||
|
options = parser.parse_args()
|
||||||
|
|
||||||
|
client = zulip.init_from_options(options)
|
||||||
|
|
||||||
|
if options.operation == 'get':
|
||||||
|
result = client.get_alert_words()
|
||||||
|
elif options.operation == 'add':
|
||||||
|
result = client.add_alert_words(options.words)
|
||||||
|
elif options.operation == 'remove':
|
||||||
|
result = client.remove_alert_words(options.words)
|
||||||
|
|
||||||
|
print(result)
|
Loading…
Reference in a new issue