Skip to content

Commit f0b3c97

Browse files
committed
[UPT/ADD][#52] Checks if gh api key was provided in the environment and uses it. Added rate_limit endpoint. Fix front-end v-chips (stopped saving NotFound users).
1 parent fa27930 commit f0b3c97

6 files changed

Lines changed: 5020 additions & 5004 deletions

File tree

api/.env-sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ APPLICATION_HOST=127.0.0.1
44
APPLICATION_PORT=3000
55

66
APPLICATION_ROOT=
7+
8+
GITHUB_TOKEN=

api/src/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class Config:
1717
PORT = int(os.getenv("APPLICATION_PORT", "3000"))
1818

1919
APPLICATION_ROOT = os.getenv("APPLICATION_ROOT", "")
20+
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN", "")
2021

2122

2223
class TestConfig(Config):

api/src/constants.py

Lines changed: 7 additions & 4993 deletions
Large diffs are not rendered by default.

api/src/main.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
from fastapi_cache.decorator import cache
1212
from loguru import logger
1313
from src.config import get_settings
14-
from src.constants import GH_REPOSITORIES, USER_DATA
14+
from src.constants import GITHUB_API_HEADERS
15+
from src.mocks import GH_REPOSITORIES, USER_DATA
1516

1617
app = FastAPI()
1718
app.add_middleware(
@@ -24,7 +25,7 @@
2425
FastAPICache.init(InMemoryBackend())
2526

2627

27-
@app.get("/{username}")
28+
@app.get("/users/{username}")
2829
@cache(expire=60 * 60 * 24)
2930
async def user_data(username: str):
3031
if get_settings().ENVIRONMENT == "DEV":
@@ -33,10 +34,7 @@ async def user_data(username: str):
3334
return USER_DATA
3435
return requests.get(
3536
f"https://api.github.com/users/{username}",
36-
headers={
37-
"Accept": "application/vnd.github+json",
38-
"X-GitHub-Api-Version": "2022-11-28",
39-
},
37+
headers=GITHUB_API_HEADERS,
4038
).json()
4139

4240

@@ -93,10 +91,7 @@ def parse_data(data):
9391
response = requests.get(
9492
url,
9593
params={"per_page": 25},
96-
headers={
97-
"Accept": "application/vnd.github+json",
98-
"X-GitHub-Api-Version": "2022-11-28",
99-
},
94+
headers=GITHUB_API_HEADERS,
10095
)
10196
logger.debug(f"GitHub response: {response}")
10297
# response.raise_for_status()
@@ -112,6 +107,14 @@ def parse_data(data):
112107
return data
113108

114109

110+
@app.get("/rate_limit")
111+
async def rate_limit():
112+
return requests.get(
113+
"https://api.github.com/rate_limit",
114+
headers=GITHUB_API_HEADERS,
115+
).json()
116+
117+
115118
if __name__ == "__main__":
116119
uvicorn.run(
117120
"src.main:app", host=get_settings().HOST, port=get_settings().PORT, reload=True

0 commit comments

Comments
 (0)