1111from fastapi_cache .decorator import cache
1212from loguru import logger
1313from 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
1617app = FastAPI ()
1718app .add_middleware (
2425FastAPICache .init (InMemoryBackend ())
2526
2627
27- @app .get ("/{username}" )
28+ @app .get ("/users/ {username}" )
2829@cache (expire = 60 * 60 * 24 )
2930async 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+
115118if __name__ == "__main__" :
116119 uvicorn .run (
117120 "src.main:app" , host = get_settings ().HOST , port = get_settings ().PORT , reload = True
0 commit comments