API host as env var
This commit is contained in:
parent
83a889cf61
commit
91077270f7
19
src/api.py
19
src/api.py
@ -1,5 +1,6 @@
|
||||
|
||||
import logging
|
||||
from os import getenv
|
||||
|
||||
import aiohttp
|
||||
|
||||
@ -13,14 +14,26 @@ class APIException(Exception):
|
||||
class NotCreatedException(APIException):
|
||||
pass
|
||||
|
||||
|
||||
class BadStatusException(APIException):
|
||||
pass
|
||||
|
||||
|
||||
def normalize_api_host(host: str):
|
||||
|
||||
if not host:
|
||||
raise ValueError("host cannot be empty")
|
||||
|
||||
if not host.endswith("/"):
|
||||
host += "/"
|
||||
|
||||
return host
|
||||
|
||||
|
||||
class API:
|
||||
"""Interactions with the API."""
|
||||
|
||||
API_HOST = "http://localhost:8000/"
|
||||
API_HOST = normalize_api_host(getenv("API_HOST"))
|
||||
API_ENDPOINT = API_HOST + "api/"
|
||||
|
||||
RSS_FEED_ENDPOINT = API_ENDPOINT + "rssfeed/"
|
||||
@ -78,11 +91,11 @@ class API:
|
||||
form = aiohttp.FormData({
|
||||
"name": name,
|
||||
"url": url,
|
||||
"discord_server_id": discord_server_id
|
||||
"discord_server_id": str(discord_server_id)
|
||||
})
|
||||
form.add_field("image", image_data, filename="file.jpg")
|
||||
|
||||
data = (await self.make_response("POST", self.RSS_FEED_ENDPOINT, data=form))["json"]
|
||||
data = (await self.make_request("POST", self.RSS_FEED_ENDPOINT, data=form))["json"]
|
||||
return data
|
||||
|
||||
async def get_rssfeed(self, uuid: str) -> dict:
|
||||
|
Loading…
x
Reference in New Issue
Block a user