diff --git a/src/reportmonster_client/client.py b/src/reportmonster_client/client.py index ae787b4..ac015c7 100644 --- a/src/reportmonster_client/client.py +++ b/src/reportmonster_client/client.py @@ -41,15 +41,21 @@ class ReportMonsterClient: async def connect(self): self._socket_reader, self._socket_writer = await asyncio.open_connection(self.host, self.port) - identification = await self.read() + identification = await self.read(wrap=False) return identification - async def read(self): - content = await self._socket_reader.readuntil(b"\n> ") - return content.decode().rstrip().rstrip(">").rstrip() + async def auth(self): + response = await self.write(f"login {self.username} {self.password}") + return response - async def write(self, message): + async def read(self, wrap=True): + content = await self._socket_reader.readuntil(b"\n> ") + stripped = content.decode().rstrip().rstrip(">").rstrip() + return ReportMonsterResponse(stripped) if wrap else stripped + + async def write(self, message, read=True, wrap=True): await self._socket_writer.write(message.encode()) + return self.read(wrap=wrap) if read else None async def disconnect(self): if self._socket_writer: