Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added branding #104

Merged
merged 6 commits into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions api/branding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
This module provides a blueprint for the branding endpoint.

Routes:
- GET /branding: Get ReVanced branding.
"""

from sanic import Blueprint, Request
from sanic.response import JSONResponse, json
from sanic_ext import openapi

from api.models.branding import BrandingResponseModel
from config import branding_links, api_version

branding: Blueprint = Blueprint("branding", version=api_version)


@branding.get("/branding")
@openapi.definition(
summary="Get ReVanced branding",
response=[BrandingResponseModel],
)
async def root(request: Request) -> JSONResponse:
"""
Returns a JSONResponse with a dictionary containing ReVanced branding links.

**Returns:**
- JSONResponse: A Sanic JSONResponse instance containing a dictionary with the branding links.
"""
data: dict[str, dict] = {"branding": branding_links}
return json(data, status=200)
18 changes: 18 additions & 0 deletions api/models/branding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from pydantic import BaseModel


class BrandingFields(BaseModel):
"""
Implements the fields for a brand link.
"""

assettype: str
url: str


class BrandingResponseModel(BaseModel):
"""
A Pydantic BaseModel that represents a dictionary of branding links.
"""

branding: list[BrandingFields]
2 changes: 2 additions & 0 deletions api/models/info.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from api.models.branding import BrandingFields
Fixed Show fixed Hide fixed
from api.models.donations import DonationFields
from api.models.socials import SocialFields
from pydantic import BaseModel
Expand All @@ -19,6 +20,7 @@ class InfoFields(BaseModel):
name: str
about: str
contact: ContactFields
branding: list[BrandingFields]
socials: list[SocialFields]
donations: DonationFields

Expand Down
25 changes: 25 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,31 @@
"revanced-releases-api",
]

# Branding

branding_links: dict[str, str] = {
Fixed Show fixed Hide fixed
{
"assettype": "logo",
"url": "https://github.com/ReVanced/revanced-branding/raw/main/assets/revanced-logo/revanced-logo.svg",
},
{
"assettype": "horizontal-light",
"url": "https://github.com/ReVanced/revanced-branding/raw/main/assets/revanced-headline/revanced-headline-horizontal-light.svg",
},
{
"assettype": "horizontal-dark",
"url": "https://github.com/ReVanced/revanced-branding/raw/main/assets/revanced-headline/revanced-headline-horizontal-dark.svg",
},
{
"assettype": "vertical-light",
"url": "https://github.com/ReVanced/revanced-branding/raw/main/assets/revanced-headline/revanced-headline-vertical-light.svg",
},
{
"assettype": "vertical-dark",
"url": "https://github.com/ReVanced/revanced-branding/raw/main/assets/revanced-headline/revanced-headline-vertical-dark.svg",
},
}

# Social Links

social_links: list[dict[str, str | bool]] = [
Expand Down
15 changes: 15 additions & 0 deletions tests/test_branding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest
from sanic import Sanic

from api.models.branding import BrandingResponseModel

from config import api_version

# branding


@pytest.mark.asyncio
async def test_branding(app: Sanic):
_, response = await app.asgi_client.get(f"/{api_version}/branding")
assert response.status == 200
assert BrandingResponseModel(**response.json)