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

new methods are added for Get_popular_teams and search_teams #38

Merged
merged 7 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ Most of the API is available:
client.teams.accept_join_request
client.teams.get_team
client.teams.teams_of_player
client.teams.get_popular
client.teams.search

client.tournaments.get
client.tournaments.get_tournament
Expand Down
3 changes: 2 additions & 1 deletion berserk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


from .clients import Client
from .types import Team, OpeningStatistic
from .types import Team, OpeningStatistic, PaginatedTeams
from .session import TokenSession
from .session import Requestor
from .enums import PerfType
Expand All @@ -32,6 +32,7 @@
"Client",
"TokenSession",
"Team",
"PaginatedTeams",
"OpeningStatistic",
"Requestor",
"PerfType",
Expand Down
23 changes: 22 additions & 1 deletion berserk/clients/teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Iterator, Any, cast, List, Dict

from .. import models
from ..types import Team
from ..types import Team, PaginatedTeams
from ..formats import NDJSON, JSON_LIST
from .base import BaseClient

Expand Down Expand Up @@ -90,3 +90,24 @@ def teams_of_player(self, username: str) -> List[Team]:
"""
path = f"/api/team/of/{username}"
return cast(List[Team], self._r.get(path))

def get_popular(self, page: int = 1) -> PaginatedTeams:
"""Get the most popular teams

:param page: the page number that needs to be returned (Optional)
:return: A paginated list of the most popular teams.
"""
path = "/api/team/all"
params = {"page": page}
return cast(PaginatedTeams, self._r.get(path, params=params))

def search(self, text: str, page: int = 1) -> PaginatedTeams:
"""Search for teams

:param text: the query text to search for
:param page: the page number that needs to be returned (Optional)
:return: The paginated list of teams.
"""
path = "/api/team/search"
params = {"text": text, "page": page}
return cast(PaginatedTeams, self._r.get(path, params=params))
3 changes: 2 additions & 1 deletion berserk/types/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from .team import Team
from .team import Team, PaginatedTeams
from .opening_explorer import (
OpeningStatistic,
OpeningExplorerVariant,
Expand All @@ -10,6 +10,7 @@

__all__ = [
"Team",
"PaginatedTeams",
"OpeningStatistic",
"OpeningExplorerVariant",
"Speed",
Expand Down
17 changes: 17 additions & 0 deletions berserk/types/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,20 @@ class LightUser(TypedDict):
title: NotRequired[Title]
# The patron of the user
patron: NotRequired[bool]


class PaginatedTeams(TypedDict):
# The current page
currentPage: int
# The maximum number of teams per page
maxPerPage: int
# The teams on the current page
currentPageResults: List[Team]
# The total number of teams
nbResults: int
# The previous page
previousPage: int | None
# The next page
nextPage: int | None
# The total number of pages
nbPages: int

Large diffs are not rendered by default.

561 changes: 561 additions & 0 deletions tests/clients/cassettes/test_teams/TestLichessGames.test_search.yaml

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion tests/clients/test_teams.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from berserk import Client, Team
from berserk import Client, Team, PaginatedTeams
from typing import List
from utils import validate, skip_if_older_3_dot_10

Expand All @@ -17,3 +17,15 @@ def test_get_team(self):
def test_teams_of_player(self):
res = Client().teams.teams_of_player("Lichess")
validate(List[Team], res)

@skip_if_older_3_dot_10
@pytest.mark.vcr
def test_get_popular(self):
res = Client().teams.get_popular()
validate(PaginatedTeams, res)

@skip_if_older_3_dot_10
@pytest.mark.vcr
def test_search(self):
res = Client().teams.search("lichess")
validate(PaginatedTeams, res)