Skip to content

Commit

Permalink
Merge pull request #72 from ReVanced/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Ushie authored Aug 19, 2023
2 parents eef2a33 + f51ccd5 commit 751624c
Show file tree
Hide file tree
Showing 14 changed files with 387 additions and 234 deletions.
5 changes: 3 additions & 2 deletions api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from api.github import github
from api.ping import ping
from api.socials import socials
from api.compat import github as old
from api.info import info
from api.compat import github as compat
from api.donations import donations

api = Blueprint.group(ping, github, socials, donations, old, url_prefix="/")
api = Blueprint.group(ping, github, info, socials, donations, compat, url_prefix="/")
34 changes: 17 additions & 17 deletions api/backends/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@

class GithubRepository(Repository):
"""
A repository class that represents a Github repository.
A repository class that represents a GitHub repository.
Args:
owner (str): The username of the owner of the Github repository.
name (str): The name of the Github repository.
owner (str): The username of the owner of the GitHub repository.
name (str): The name of the GitHub repository.
"""

def __init__(self, owner: str, name: str):
"""
Initializes a new instance of the GithubRepository class.
Args:
owner (str): The username of the owner of the Github repository.
name (str): The name of the Github repository.
owner (str): The username of the owner of the GitHub repository.
name (str): The name of the GitHub repository.
"""
super().__init__(Github())
self.owner = owner
Expand All @@ -44,18 +44,18 @@ def __init__(self, owner: str, name: str):

class Github(Backend):
"""
A backend class that interacts with the Github API.
A backend class that interacts with the GitHub API.
Attributes:
name (str): The name of the Github backend.
base_url (str): The base URL of the Github API.
token (str): The Github access token used for authentication.
headers (dict[str, str]): The HTTP headers to be sent with each request to the Github API.
name (str): The name of the GitHub backend.
base_url (str): The base URL of the GitHub API.
token (str): The GitHub access token used for authentication.
headers (dict[str, str]): The HTTP headers to be sent with each request to the GitHub API.
"""

def __init__(self):
"""
Initializes a new instance of the Github class.
Initializes a new instance of the GitHub class.
"""
super().__init__(repo_name, base_url)
self.token: Optional[str] = os.getenv("GITHUB_TOKEN")
Expand Down Expand Up @@ -121,10 +121,10 @@ async def list_releases(
self, repository: GithubRepository, per_page: int = 30, page: int = 1
) -> list[Release]:
"""
Returns a list of Release objects for a given Github repository.
Returns a list of Release objects for a given GitHub repository.
Args:
repository (GithubRepository): The Github repository for which to retrieve the releases.
repository (GithubRepository): The GitHub repository for which to retrieve the releases.
per_page (int): The number of releases to return per page.
page (int): The page number of the releases to return.
Expand All @@ -148,10 +148,10 @@ async def get_release_by_tag_name(
self, repository: GithubRepository, tag_name: str
) -> Release:
"""
Retrieves a specific release for a given Github repository by its tag name.
Retrieves a specific release for a given GitHub repository by its tag name.
Args:
repository (GithubRepository): The Github repository for which to retrieve the release.
repository (GithubRepository): The GitHub repository for which to retrieve the release.
tag_name (str): The tag name of the release to retrieve.
Returns:
Expand All @@ -171,7 +171,7 @@ async def get_latest_release(
"""Get the latest release for a given repository.
Args:
repository (GithubRepository): The Github repository for which to retrieve the release.
repository (GithubRepository): The GitHub repository for which to retrieve the release.
Returns:
Release: The latest release for the given repository.
Expand All @@ -190,7 +190,7 @@ async def get_latest_pre_release(
"""Get the latest pre-release for a given repository.
Args:
repository (GithubRepository): The Github repository for which to retrieve the release.
repository (GithubRepository): The GitHub repository for which to retrieve the release.
Returns:
Release: The latest pre-release for the given repository.
Expand Down
17 changes: 9 additions & 8 deletions api/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
This module provides endpoints for compatibility with the old API.
Routes:
- GET /<repo:str>/releases: Retrieve a list of releases for a Github repository.
- GET /<repo:str>/releases/latest: Retrieve the latest release for a Github repository.
- GET /<repo:str>/releases/tag/<tag:str>: Retrieve a specific release for a Github repository by its tag name.
- GET /<repo:str>/contributors: Retrieve a list of contributors for a Github repository.
- GET /<repo:str>/releases: Retrieve a list of releases for a GitHub repository.
- GET /<repo:str>/releases/latest: Retrieve the latest release for a GitHub repository.
- GET /<repo:str>/releases/tag/<tag:str>: Retrieve a specific release for a GitHub repository by its tag name.
- GET /<repo:str>/contributors: Retrieve a list of contributors for a GitHub repository.
- GET /patches/<tag:str>: Retrieve a list of patches for a given release tag.
"""
Expand All @@ -31,10 +31,10 @@
)
async def tools(request: Request) -> JSONResponse:
"""
Retrieve a list of releases for a Github repository.
Retrieve a list of releases for a GitHub repository.
**Args:**
- repo (str): The name of the Github repository to retrieve releases for.
- repo (str): The name of the GitHub repository to retrieve releases for.
**Query Parameters:**
- per_page (int): The number of releases to retrieve per page.
Expand All @@ -52,7 +52,8 @@ async def tools(request: Request) -> JSONResponse:
repositories=[
GithubRepository(owner=owner, name=repo)
for repo in compat_repositories
if repo not in ["revanced-releases-api", "revanced-website"]
if repo
not in ["revanced-api", "revanced-releases-api", "revanced-website"]
],
dev=True if request.args.get("dev") else False,
)
Expand All @@ -67,7 +68,7 @@ async def tools(request: Request) -> JSONResponse:
)
async def contributors(request: Request) -> JSONResponse:
"""
Retrieve a list of releases for a Github repository.
Retrieve a list of releases for a GitHub repository.
**Returns:**
- JSONResponse: A Sanic JSONResponse object containing the list of releases.
Expand Down
26 changes: 13 additions & 13 deletions api/github.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""
This module provides endpoints for interacting with the Github API.
This module provides endpoints for interacting with the GitHub API.
Routes:
- GET /<repo:str>/releases: Retrieve a list of releases for a Github repository.
- GET /<repo:str>/releases/latest: Retrieve the latest release for a Github repository.
- GET /<repo:str>/releases/tag/<tag:str>: Retrieve a specific release for a Github repository by its tag name.
- GET /<repo:str>/contributors: Retrieve a list of contributors for a Github repository.
- GET /<repo:str>/releases: Retrieve a list of releases for a GitHub repository.
- GET /<repo:str>/releases/latest: Retrieve the latest release for a GitHub repository.
- GET /<repo:str>/releases/tag/<tag:str>: Retrieve a specific release for a GitHub repository by its tag name.
- GET /<repo:str>/contributors: Retrieve a list of contributors for a GitHub repository.
- GET /patches/<tag:str>: Retrieve a list of patches for a given release tag.
"""
Expand All @@ -30,10 +30,10 @@
)
async def list_releases(request: Request, repo: str) -> JSONResponse:
"""
Retrieve a list of releases for a Github repository.
Retrieve a list of releases for a GitHub repository.
**Args:**
- repo (str): The name of the Github repository to retrieve releases for.
- repo (str): The name of the GitHub repository to retrieve releases for.
**Query Parameters:**
- per_page (int): The number of releases to retrieve per page.
Expand Down Expand Up @@ -67,10 +67,10 @@ async def list_releases(request: Request, repo: str) -> JSONResponse:
)
async def latest_release(request: Request, repo: str) -> JSONResponse:
"""
Retrieve the latest release for a Github repository.
Retrieve the latest release for a GitHub repository.
**Args:**
- repo (str): The name of the Github repository to retrieve the release for.
- repo (str): The name of the GitHub repository to retrieve the release for.
**Query Parameters:**
- dev (bool): Whether or not to retrieve the latest development release.
Expand Down Expand Up @@ -103,17 +103,17 @@ async def latest_release(request: Request, repo: str) -> JSONResponse:

@github.get("/<repo:str>/releases/tag/<tag:str>")
@openapi.definition(
summary="Retrieve a release for a Github repository by its tag name.",
summary="Retrieve a release for a GitHub repository by its tag name.",
response=SingleReleaseResponseModel,
)
async def get_release_by_tag_name(
request: Request, repo: str, tag: str
) -> JSONResponse:
"""
Retrieve a release for a Github repository by its tag name.
Retrieve a release for a GitHub repository by its tag name.
**Args:**
- repo (str): The name of the Github repository to retrieve the release for.
- repo (str): The name of the GitHub repository to retrieve the release for.
- tag (str): The tag for the release to be retrieved.
**Returns:**
Expand Down Expand Up @@ -142,7 +142,7 @@ async def get_contributors(request: Request, repo: str) -> JSONResponse:
Retrieve a list of contributors for a repository.
**Args:**
- repo (str): The name of the Github repository to retrieve the contributors for.
- repo (str): The name of the GitHub repository to retrieve the contributors for.
**Returns:**
- JSONResponse: A Sanic JSONResponse object containing the list of contributors.
Expand Down
31 changes: 31 additions & 0 deletions api/info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
This module provides a blueprint for the info endpoint.
Routes:
- GET /info: Get info about the owner of the API.
"""

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

from api.models.info import InfoResponseModel
from config import api_version, default_info

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


@info.get("/info")
@openapi.definition(
summary="Information about the API",
response=[InfoResponseModel],
)
async def root(request: Request) -> JSONResponse:
"""
Returns a JSONResponse with a dictionary containing info about the owner of the API.
**Returns:**
- JSONResponse: A Sanic JSONResponse instance containing a dictionary with the info about the owner of the API.
"""
data: dict[str, dict] = {"info": default_info}
return json(data, status=200)
31 changes: 31 additions & 0 deletions api/models/info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from api.models.donations import DonationFields
from api.models.socials import SocialFields
from pydantic import BaseModel


class ContactFields(BaseModel):
"""
Implements the fields for the API owner contact info.
"""

email: str


class InfoFields(BaseModel):
"""
Implements the fields for the API owner info.
"""

name: str
about: str
contact: ContactFields
socials: list[SocialFields]
donations: DonationFields


class InfoResponseModel(BaseModel):
"""
A Pydantic BaseModel that represents a dictionary of info.
"""

info: InfoFields
4 changes: 2 additions & 2 deletions api/models/socials.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pydantic import BaseModel


class SocialField(BaseModel):
class SocialFields(BaseModel):
"""
Implements the fields for a social network link.
"""
Expand All @@ -15,7 +15,7 @@ class SocialsResponseModel(BaseModel):
A Pydantic BaseModel that represents a dictionary of social links.
"""

socials: list[SocialField]
socials: list[SocialFields]
"""
A dictionary where the keys are the names of the social networks, and
the values are the links to the profiles or pages.
Expand Down
Loading

0 comments on commit 751624c

Please sign in to comment.