From 99bf9f07fae72a26325f53a3ae04b0244f44f659 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Thu, 22 Jun 2023 11:18:03 +0300 Subject: [PATCH] Add method to send and get the order. --- src/api/v2/cart_api.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/api/v2/cart_api.py b/src/api/v2/cart_api.py index ead031f..a697fca 100644 --- a/src/api/v2/cart_api.py +++ b/src/api/v2/cart_api.py @@ -56,3 +56,23 @@ class CartAPI: case {"error": error_message}: return error_message + async def get_order(self, username: str): + endpoint = f"/api/v2/order?matrixUsername={username}" + + status, json_data = await self.__fetcher.fetch_json(endpoint) + + if status == 200: + return {"ok": json_data} + + return {"error": "Сталася помилка, спробуйте пізніше."} + + async def get_order_message(self, username: str) -> str: + response = await self.get_order(username) + + match response: + case {"ok": json_data}: + return self.__formatter.format(json_data) + + case {"error": error_message}: + return error_message +