Skip to content

Commit

Permalink
add autocomplete usernames endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Anupya committed Oct 22, 2023
1 parent c65d17c commit bdacfd1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ Most of the API is available:
client.users.get_live_streamers
client.users.get_rating_history
client.users.get_crosstable
client.users.get_autocomplete
client.users.get_user_performance
Details for each function can be found in the `documentation <https://lichess-org.github.io/berserk/>`_.
20 changes: 20 additions & 0 deletions berserk/clients/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,26 @@ def get_crosstable(
path, params=params, fmt=JSON_LIST, converter=models.User.convert
)

def get_autocomplete(
self,
incomplete_username: str,
only_followed_players: bool,
should_return_object: bool = False,
) -> Dict[str, Any]:
"""Provides autocomplete options for an incomplete username.
:param incomplete_username: beginning of a username, must be >=3 characters
:param only_followed_players: whether to return matching followed players only, if any exist
:param should_return_object: whether to return an object with matching users
"""
path = "/api/player/auto-complete"
params = {
"term": incomplete_username,
"object": should_return_object,
"friend": only_followed_players,
}
return self._r.get(path=path, params=params)

def get_user_performance(self, username: str, perf: str) -> List[Dict[str, Any]]:
"""Read performance statistics of a user, for a single performance.
Expand Down

0 comments on commit bdacfd1

Please sign in to comment.