-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a76f49e
commit 2617154
Showing
12 changed files
with
131 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from ..settings import env # type: ignore[attr-defined] | ||
|
||
AURORA_API_TOKEN = env("AURORA_API_TOKEN") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class Config(AppConfig): | ||
name = __name__.rpartition(".")[0] | ||
verbose_name = "Country Workspace | Aurora" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from typing import Any, Generator | ||
from urllib.parse import urljoin | ||
|
||
from django.conf import settings | ||
|
||
import requests | ||
from constance import config | ||
|
||
|
||
class AuroraClient: | ||
|
||
def __init__(self, token: str | None = None) -> None: | ||
self.token = token or settings.AURORA_API_TOKEN | ||
# temporarily for development purposes | ||
self.use_mock = True | ||
|
||
def _get_url(self, path: str) -> str: | ||
url = urljoin(config.AURORA_API_URL, path) | ||
if not url.endswith("/"): | ||
url = url + "/" | ||
return url | ||
|
||
def _load_mock_data(self, path: str) -> dict: | ||
import json | ||
from pathlib import Path | ||
|
||
file_path = ( | ||
Path(__file__).resolve().parent.parent.parent.parent.parent / "tests" / "extras" / "aurora_record.json" | ||
) | ||
if file_path.exists(): | ||
with file_path.open() as f: | ||
return json.load(f) | ||
raise FileNotFoundError(f"Mock data for {path} not found") | ||
|
||
def get(self, path: str) -> Generator[dict[str, Any], None, None]: | ||
if self.use_mock: | ||
data = self._load_mock_data(path) | ||
else: | ||
url = self._get_url(path) | ||
ret = requests.get(url, headers={"Authorization": f"Token {self.token}"}, timeout=10) | ||
if ret.status_code != 200: | ||
raise Exception(f"Error {ret.status_code} fetching {url}") | ||
data = ret.json() | ||
|
||
for record in data["results"]: | ||
yield record | ||
|
||
if not self.use_mock and "next" in data: | ||
url = data["next"] | ||
else: | ||
url = None |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters