chore: removed unneeded field, sorted methods

This commit is contained in:
əlemi 2024-01-31 04:58:29 +01:00
parent 81c005bef5
commit 822a6426ab
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -20,7 +20,6 @@ class AppService:
as_token: str
hs_token: str
homeserver: str
user_id: str
use_http: bool
logger: logging.Logger
@ -30,7 +29,6 @@ class AppService:
as_token: str,
hs_token: str,
homeserver: str,
user_id: str,
use_http: bool = False,
logger: logging.Logger | None = None,
):
@ -41,16 +39,15 @@ class AppService:
self.as_token = as_token
self.hs_token = hs_token
self.homeserver = homeserver
self.user_id = user_id
self.use_http = use_http
self.logger = logger if logger is not None else logging.getLogger(__file__)
self._app.add_routes([
web.put('/transactions/{transaction}', lambda req: self.handler(req))
web.put('/transactions/{transaction}', lambda req: self._handler(req))
])
async def handler(self, request: web.Request) -> web.Response:
async def _handler(self, request: web.Request) -> web.Response:
self.logger.debug("handling webhook callback %s", request)
hs_token = request.query.getone("access_token")
if not hs_token:
@ -78,12 +75,24 @@ class AppService:
return func
return wrapper
async def start(self, host: str = "localhost", port: int = 25511):
runner = web.AppRunner(self._app)
await runner.setup()
self._site = web.TCPSite(runner, host, port)
await self._site.start()
async def stop(self):
await self._site.stop()
await self._tx.close()
@property
def client_api(self) -> str:
if self.use_http:
return "http://" + self.homeserver + self._CLIENT_API_ROOT
else:
return "https://" + self.homeserver + self._CLIENT_API_ROOT
def api_headers(self) -> dict[str, str]:
return {
"Authorization": f"Bearer {self.as_token}",
"Content-Type": "application/json",
}
@property
def media_api(self) -> str:
@ -107,12 +116,13 @@ class AppService:
doc = await res.json()
return doc["content_uri"]
@property
def api_headers(self) -> dict[str, str]:
return {
"Authorization": f"Bearer {self.as_token}",
"Content-Type": "application/json",
}
def client_api(self) -> str:
if self.use_http:
return "http://" + self.homeserver + self._CLIENT_API_ROOT
else:
return "https://" + self.homeserver + self._CLIENT_API_ROOT
async def get_user(self, mxid: str) -> User | None:
async with self._client.request(
@ -224,14 +234,3 @@ class AppService:
) as res:
res.raise_for_status()
async def start(self, host: str = "localhost", port: int = 25511):
runner = web.AppRunner(self._app)
await runner.setup()
self._site = web.TCPSite(runner, host, port)
await self._site.start()
async def stop(self):
await self._site.stop()
await self._tx.close()