Skip to content

Commit

Permalink
api: Update add_realm_filter to support url_template.
Browse files Browse the repository at this point in the history
This adds support to adding linkifiers with the new URL template syntax.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
  • Loading branch information
PIG208 committed Jul 23, 2023
1 parent ae142a3 commit 00eea3a
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions zulip/zulip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,20 +1040,24 @@ def get_realm_linkifiers(self) -> Dict[str, Any]:
method="GET",
)

def add_realm_filter(self, pattern: str, url_format_string: str) -> Dict[str, Any]:
def add_realm_filter(self, pattern: str, url_template: str) -> Dict[str, Any]:
"""
Example usage:
>>> client.add_realm_filter('#(?P<id>[0-9]+)', 'https://github.com/zulip/zulip/issues/%(id)s')
>>> client.add_realm_filter('#(?P<id>[0-9]+)', 'https://github.com/zulip/zulip/issues/{id}')
{'result': 'success', 'msg': '', 'id': 42}
"""
data = {"pattern": pattern}
if self.feature_level >= 176:
# Starting from feature level 176, we use RFC 6570 compliant URL
# templates instead.
data["url_template"] = url_template
else:
data["url_format_string"] = url_template
return self.call_endpoint(
url="realm/filters",
method="POST",
request={
"pattern": pattern,
"url_format_string": url_format_string,
},
request=data,
)

def remove_realm_filter(self, filter_id: int) -> Dict[str, Any]:
Expand Down Expand Up @@ -1809,7 +1813,7 @@ def get_realm_filters(self) -> Dict[str, Any]:
Example usage:
>>> client.get_realm_filters()
{'result': 'success', 'msg': '', 'filters': [['#(?P<id>[0-9]+)', 'https://github.com/zulip/zulip/issues/%(id)s', 1]]}
{'result': 'success', 'msg': '', 'filters': [['#(?P<id>[0-9]+)', 'https://github.com/zulip/zulip/issues/{id}', 1]]}
"""
# This interface was removed in 4d482e0ef30297f716885fd8246f4638a856ba3b
return self.call_endpoint(
Expand Down

0 comments on commit 00eea3a

Please sign in to comment.