Skip to content

Commit

Permalink
Updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
Tert0 committed Aug 16, 2021
1 parent a04f696 commit 1c57ef8
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ You can find the Example in `expamples/`
```py
from typing import List

from fastapi import FastAPI, Depends
from fastapi import Depends, FastAPI
from fastapi.responses import JSONResponse
from fastapi_discord import DiscordOAuthClient, Unauthorized, RateLimited, User

from fastapi_discord import DiscordOAuthClient, RateLimited, Unauthorized, User
from fastapi_discord.models import GuildPreview

app = FastAPI()
Expand All @@ -35,7 +34,11 @@ async def callback(code: str):
return {"access_token": token, "refresh_token": refresh_token}


@app.get("/authenticated", dependencies=[Depends(discord.requires_authorization)], response_model=bool)
@app.get(
"/authenticated",
dependencies=[Depends(discord.requires_authorization)],
response_model=bool,
)
async def isAuthenticated(token: str = Depends(discord.get_token)):
try:
auth = await discord.isAuthenticated(token)
Expand All @@ -51,15 +54,22 @@ async def unauthorized_error_handler(_, __):

@app.exception_handler(RateLimited)
async def rate_limit_error_handler(_, e: RateLimited):
return JSONResponse({"error": "RateLimited", "retry": e.retry_after, "message": e.message}, status_code=429)
return JSONResponse(
{"error": "RateLimited", "retry": e.retry_after, "message": e.message},
status_code=429,
)


@app.get("/user", dependencies=[Depends(discord.requires_authorization)], response_model=User)
async def get_user(user: User = Depends(discord.user)):
return user


@app.get("/guilds", dependencies=[Depends(discord.requires_authorization)], response_model=List[GuildPreview])
@app.get(
"/guilds",
dependencies=[Depends(discord.requires_authorization)],
response_model=List[GuildPreview],
)
async def get_guilds(guilds: List = Depends(discord.guilds)):
return guilds
```
Expand Down

0 comments on commit 1c57ef8

Please sign in to comment.