Skip to content

Commit 3b09e36

Browse files
authored
Add blocklist CRUD (#39)
1 parent fecbcf5 commit 3b09e36

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

stream_chat/client.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,47 @@ def send_file(self, uri, url, name, user, content_type=None):
321321
headers=headers,
322322
)
323323
return self._parse_response(response)
324+
325+
def create_blocklist(self, name, words):
326+
"""
327+
Create a blocklist
328+
329+
:param name: the name of the blocklist
330+
:param words: list of blocked words
331+
:return:
332+
"""
333+
return self.post("blocklists", data={"name": name, "words": words})
334+
335+
def list_blocklists(self):
336+
"""
337+
List blocklists
338+
339+
:return: list of blocklists
340+
"""
341+
return self.get("blocklists")
342+
343+
def get_blocklist(self, name):
344+
"""Get a blocklist by name
345+
346+
:param name: the name of the blocklist
347+
:return: blocklist dict representation
348+
"""
349+
return self.get("blocklists/{}".format(name))
350+
351+
def update_blocklist(self, name, words):
352+
"""
353+
Update a blocklist
354+
355+
:param name: the name of the blocklist
356+
:param words: the list of blocked words (replaces the current list)
357+
:return:
358+
"""
359+
return self.put("blocklists/{}".format(name), data={"words": words})
360+
361+
def delete_blocklist(self, name):
362+
"""Delete a blocklist by name
363+
364+
:param: the name of the blocklist
365+
:return:
366+
"""
367+
return self.delete("blocklists/{}".format(name))

stream_chat/tests/test_client.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,25 @@ def test_query_channels_members_in(self, client, fellowship_of_the_ring):
223223
assert len(response["channels"]) == 1
224224
assert response["channels"][0]["channel"]["id"] == "fellowship-of-the-ring"
225225
assert len(response["channels"][0]["members"]) == 9
226+
227+
def test_create_blocklist(self, client):
228+
response = client.create_blocklist(name="Foo", words=["fudge", "heck"])
229+
230+
def test_list_blocklists(self, client):
231+
response = client.list_blocklists()
232+
assert len(response["blocklists"]) == 2
233+
blocklist_names = {blocklist["name"] for blocklist in response["blocklists"]}
234+
assert "Foo" in blocklist_names
235+
236+
def test_get_blocklist(self, client):
237+
response = client.get_blocklist("Foo")
238+
assert response["blocklist"]["name"] == "Foo"
239+
assert response["blocklist"]["words"] == ["fudge", "heck"]
240+
241+
def test_update_blocklist(self, client):
242+
client.update_blocklist("Foo", words=["dang"])
243+
response = client.get_blocklist("Foo")
244+
assert response["blocklist"]["words"] == ["dang"]
245+
246+
def test_delete_blocklist(self, client):
247+
client.delete_blocklist("Foo")

0 commit comments

Comments
 (0)