Skip to content

Commit

Permalink
Merge pull request #5 from EdoDodo/master
Browse files Browse the repository at this point in the history
Add a method for current_game API endpoint.
  • Loading branch information
cyanfish committed Oct 11, 2020
2 parents 7cb2d0f + 8fc0d38 commit 340fd6a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lichess/api.py
Expand Up @@ -280,6 +280,12 @@ def user_games(username, **kwargs):
"""
return _api_get('/api/games/user/{}'.format(username), kwargs, object_type=lichess.format.GAME_STREAM_OBJECT)


def current_game(username, **kwargs):
"""Wrapper for the `GET /api/user/<username>/current-game` endpoint.
Returns a single game."""
return _api_get('/api/user/{}/current-game'.format(username), kwargs, object_type=lichess.format.GAME_OBJECT)

def games_by_team(team, **kwargs):
"""Wrapper for the `GET /api/games/team/<teamId> <https://github.com/ornicar/lila#get-apigamesteamteamid-fetch-games-between-players-of-a-team>`_ endpoint.
Returns a generator that makes requests for additional pages as needed."""
Expand Down
4 changes: 4 additions & 0 deletions test.py
Expand Up @@ -36,6 +36,10 @@ def test_user_activity(self):
activity = lichess.api.user_activity('thibault')
self.assertEqual(type(activity), list)

def test_current_game(self):
game = lichess.api.current_game('cyanfish')
self.assertEqual(type(game['moves']), type(u''))

def test_game(self):
game = lichess.api.game('Qa7FJNk2')
self.assertEqual(type(game['moves']), type(u''))
Expand Down

0 comments on commit 340fd6a

Please sign in to comment.