chore: removed unneeded field, sorted methods
This commit is contained in:
parent
81c005bef5
commit
822a6426ab
1 changed files with 25 additions and 26 deletions
|
@ -20,7 +20,6 @@ class AppService:
|
||||||
as_token: str
|
as_token: str
|
||||||
hs_token: str
|
hs_token: str
|
||||||
homeserver: str
|
homeserver: str
|
||||||
user_id: str
|
|
||||||
use_http: bool
|
use_http: bool
|
||||||
|
|
||||||
logger: logging.Logger
|
logger: logging.Logger
|
||||||
|
@ -30,7 +29,6 @@ class AppService:
|
||||||
as_token: str,
|
as_token: str,
|
||||||
hs_token: str,
|
hs_token: str,
|
||||||
homeserver: str,
|
homeserver: str,
|
||||||
user_id: str,
|
|
||||||
use_http: bool = False,
|
use_http: bool = False,
|
||||||
logger: logging.Logger | None = None,
|
logger: logging.Logger | None = None,
|
||||||
):
|
):
|
||||||
|
@ -41,16 +39,15 @@ class AppService:
|
||||||
self.as_token = as_token
|
self.as_token = as_token
|
||||||
self.hs_token = hs_token
|
self.hs_token = hs_token
|
||||||
self.homeserver = homeserver
|
self.homeserver = homeserver
|
||||||
self.user_id = user_id
|
|
||||||
self.use_http = use_http
|
self.use_http = use_http
|
||||||
|
|
||||||
self.logger = logger if logger is not None else logging.getLogger(__file__)
|
self.logger = logger if logger is not None else logging.getLogger(__file__)
|
||||||
|
|
||||||
self._app.add_routes([
|
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)
|
self.logger.debug("handling webhook callback %s", request)
|
||||||
hs_token = request.query.getone("access_token")
|
hs_token = request.query.getone("access_token")
|
||||||
if not hs_token:
|
if not hs_token:
|
||||||
|
@ -78,12 +75,24 @@ class AppService:
|
||||||
return func
|
return func
|
||||||
return wrapper
|
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
|
@property
|
||||||
def client_api(self) -> str:
|
def api_headers(self) -> dict[str, str]:
|
||||||
if self.use_http:
|
return {
|
||||||
return "http://" + self.homeserver + self._CLIENT_API_ROOT
|
"Authorization": f"Bearer {self.as_token}",
|
||||||
else:
|
"Content-Type": "application/json",
|
||||||
return "https://" + self.homeserver + self._CLIENT_API_ROOT
|
}
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def media_api(self) -> str:
|
def media_api(self) -> str:
|
||||||
|
@ -107,12 +116,13 @@ class AppService:
|
||||||
doc = await res.json()
|
doc = await res.json()
|
||||||
return doc["content_uri"]
|
return doc["content_uri"]
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def api_headers(self) -> dict[str, str]:
|
def client_api(self) -> str:
|
||||||
return {
|
if self.use_http:
|
||||||
"Authorization": f"Bearer {self.as_token}",
|
return "http://" + self.homeserver + self._CLIENT_API_ROOT
|
||||||
"Content-Type": "application/json",
|
else:
|
||||||
}
|
return "https://" + self.homeserver + self._CLIENT_API_ROOT
|
||||||
|
|
||||||
async def get_user(self, mxid: str) -> User | None:
|
async def get_user(self, mxid: str) -> User | None:
|
||||||
async with self._client.request(
|
async with self._client.request(
|
||||||
|
@ -224,14 +234,3 @@ class AppService:
|
||||||
) as res:
|
) as res:
|
||||||
res.raise_for_status()
|
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()
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue