From e0b26f13b19d7a5c6c68c231985e7d4ba5200b01 Mon Sep 17 00:00:00 2001 From: vtexier <vit@free.fr> Date: Wed, 30 Oct 2019 16:51:53 +0100 Subject: [PATCH] [enh] #58 new method receive_json in WSConnection class --- duniterpy/api/client.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/duniterpy/api/client.py b/duniterpy/api/client.py index 4f2df122..78612071 100644 --- a/duniterpy/api/client.py +++ b/duniterpy/api/client.py @@ -129,7 +129,7 @@ class WSConnection: await self.connection.send_str(data) return None - async def receive_str(self, timeout: Optional[float] = None) -> Optional[str]: + async def receive_str(self, timeout: Optional[float] = None) -> str: """ Wait for a data string from the web socket connection @@ -141,6 +141,18 @@ class WSConnection: return await self.connection.receive_str(timeout=timeout) + async def receive_json(self, timeout: Optional[float] = None) -> Any: + """ + Wait for json data from the web socket connection + + :param timeout: Timeout in seconds + :return: + """ + if self.connection is None: + raise Exception("Connection property is empty") + + return await self.connection.receive_json(timeout=timeout) + async def init_connection(self): """ Mandatory for aiohttp library to avoid the use of the with statement -- GitLab