Skip to content

Commit

Permalink
Merge branch 'feature/backend' into feat/backend-exceptions
Browse files Browse the repository at this point in the history
Signed-off-by: Neil <[email protected]>
  • Loading branch information
ItsNeil17 authored Jun 9, 2024
2 parents cc35c97 + 089da9c commit 91bc960
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 63 deletions.
53 changes: 0 additions & 53 deletions backend.py

This file was deleted.

22 changes: 19 additions & 3 deletions backend/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,30 @@
__all__ = ("API",)


from typing import Dict

__all__ = ("API",)


class API:
def __init__(self, api_key: str):
self.api_key = api_key
self.headers = {"API-Key": api_key}

def request(self, route: Route, data: dict = None) -> dict:
def request(
self, route: Route, *, query_params: dict = None, json: dict = None, **kwargs
):
method = route.method
url = route.url

headers: Dict[str, str] = {
"User-Agent": "WillofSteel API Client/1.0",
"Content-Type": "application/json",
"API-Key": self.api_key,
}

response = requests.request(
route.method, route.path, headers=self.headers, json=data
method, url, headers=headers, params=query_params, json=json, **kwargs

)
if response.status_code == 403:
raise AccessForbidden(response.status_code)
Expand Down
4 changes: 2 additions & 2 deletions backend/route.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__all__ = "Route"

API_URL = "https://api.willofsteel.me"

__all__ = ("Route",)


class Route:
def __init__(self, path, method):
Expand Down
2 changes: 1 addition & 1 deletion models/alliance.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from datetime import datetime
from typing import NamedTuple

__all__ = ["Alliance"]
__all__ = ("Alliance",)


class Alliance(NamedTuple):
Expand Down
2 changes: 1 addition & 1 deletion models/characteristics.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import NamedTuple

__all__ = ["Characteristics"]
__all__ = ("Characteristics",)


class Characteristics(NamedTuple):
Expand Down
2 changes: 1 addition & 1 deletion models/order.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import NamedTuple

__all__ = ["MarketOrder"]
__all__ = ("MarketOrder",)


class MarketOrder(NamedTuple):
Expand Down
2 changes: 1 addition & 1 deletion models/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .units import UnitType
from .alliance import Alliance

__all__ = ["Player", "EventPlayer"]
__all__ = ("Player", "EventPlayer")


class Player(NamedTuple):
Expand Down
2 changes: 1 addition & 1 deletion models/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import emote

__all__ = ["UnitType"]
__all__ = ("UnitType",)


class UnitProperties(NamedTuple):
Expand Down

0 comments on commit 91bc960

Please sign in to comment.