-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed video pagination. New exceptions for error handling. Improved m…
…odel relation links. Resource pagination (wip).
- Loading branch information
1 parent
24785d7
commit 1431c45
Showing
14 changed files
with
159 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
from .helix import Helix | ||
from .v5 import V5 | ||
|
||
|
||
name = "twitch" | ||
|
||
__all__ = [Helix, V5, Chat] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,42 @@ | ||
from typing import TypeVar, Generic, Generator, List, Any | ||
from typing import TypeVar, Generic, Generator, List | ||
|
||
from twitch.api import API | ||
|
||
T = TypeVar('T') | ||
|
||
|
||
class Resource(Generic[T]): | ||
FIRST_API_LIMIT: int = 100 | ||
|
||
def __init__(self, path: str, api: API, data: List[T] = None): | ||
self._path: str = path | ||
self._api: API = api | ||
self._data: List[T] = data or [] | ||
self._cursor: str = None | ||
self._kwargs: Any = None | ||
self._kwargs: dict = {} | ||
|
||
def __iter__(self) -> Generator[T, None, None]: | ||
for entry in self._data: | ||
yield entry | ||
# Yield available data | ||
if self._data: | ||
for entry in self._data: | ||
yield entry | ||
return | ||
|
||
# Stream data from API | ||
|
||
# Set start cursor | ||
self._cursor = self._kwargs or self._cursor or '0' | ||
|
||
# Set 'first' to limit | ||
self._kwargs['first'] = Resource.FIRST_API_LIMIT | ||
|
||
# Paginate | ||
while self._cursor: | ||
# API Response | ||
response: dict = self._api.get(self._path, params=self._kwargs) | ||
|
||
# Set pagination cursor | ||
self._cursor = response.get('pagination', {}).get('cursor', None) | ||
|
||
def __getitem__(self, item: int) -> T: | ||
return self._data[item] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters