Skip to content

Commit

Permalink
Add max_results to all HTTPAsyncIterators
Browse files Browse the repository at this point in the history
  • Loading branch information
chillymosh committed May 12, 2024
1 parent 2d63cf2 commit 0de13e2
Show file tree
Hide file tree
Showing 3 changed files with 234 additions and 86 deletions.
53 changes: 38 additions & 15 deletions twitchio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ async def fetch_clips(
featured: bool | None = None,
token_for: str | None = None,
first: int = 20,
max_results: int | None = None,
) -> HTTPAsyncIterator[Clip]:
"""
Fetches clips by clip id or game id.
Expand All @@ -480,6 +481,9 @@ async def fetch_clips(
first: int
Maximum number of items to return per page. Default is 20.
Min is 1 and Max is 100.
max_results: int | None
Maximum number of total results to return. When this is set to None (default), then everything found is returned.
Returns
--------
Expand Down Expand Up @@ -508,11 +512,12 @@ async def fetch_clips(
started_at=started_at,
ended_at=ended_at,
is_featured=featured,
max_results=max_results,
token_for=token_for,
)

async def fetch_extension_transactions(
self, extension_id: str, *, ids: list[str] | None = None, first: int = 20
self, extension_id: str, *, ids: list[str] | None = None, first: int = 20, max_results: int | None = None
) -> HTTPAsyncIterator[ExtensionTransaction]:
"""
Fetches global emotes from the twitch API
Expand All @@ -529,6 +534,8 @@ async def fetch_extension_transactions(
first: int
Maximum number of items to return per page. Default is 20.
Min is 1 and Max is 100.
max_results: int | None
Maximum number of total results to return. When this is set to None (default), then everything found is returned.
Returns
--------
Expand All @@ -541,9 +548,7 @@ async def fetch_extension_transactions(
raise ValueError("You can only provide a mximum of 100 IDs")

return await self._http.get_extension_transactions(
extension_id=extension_id,
ids=ids,
first=first,
extension_id=extension_id, ids=ids, first=first, max_results=max_results
)

async def fetch_emotes(self, *, token_for: str | None = None) -> list[GlobalEmote]:
Expand Down Expand Up @@ -572,6 +577,7 @@ async def fetch_streams(
type: Literal["all", "live"] = "all",
token_for: str | None = None,
first: int = 20,
max_results: int | None = None,
) -> HTTPAsyncIterator[Stream]:
"""
Fetches live streams from the helix API
Expand All @@ -593,6 +599,8 @@ async def fetch_streams(
first: int
Maximum number of items to return per page. Default is 20.
Min is 1 and Max is 100.
max_results: int | None
Maximum number of total results to return. When this is set to None (default), then everything found is returned.
Returns
--------
Expand All @@ -609,6 +617,7 @@ async def fetch_streams(
languages=languages,
type=type,
token_for=token_for,
max_results=max_results,
)

async def fetch_team(
Expand Down Expand Up @@ -643,10 +652,7 @@ async def fetch_team(
return Team(data["data"][0], http=self._http)

async def fetch_top_games(
self,
*,
token_for: str | None = None,
first: int = 20,
self, *, token_for: str | None = None, first: int = 20, max_results: int | None = None
) -> HTTPAsyncIterator[Game]:
"""
Fetches information about all broadcasts on Twitch.
Expand All @@ -658,6 +664,8 @@ async def fetch_top_games(
first: int
Maximum number of items to return per page. Default is 20.
Min is 1 and Max is 100.
max_results: int | None
Maximum number of total results to return. When this is set to None (default), then everything found is returned.
Returns
--------
Expand All @@ -666,10 +674,7 @@ async def fetch_top_games(

first = max(1, min(100, first))

return await self._http.get_top_games(
first=first,
token_for=token_for,
)
return await self._http.get_top_games(first=first, token_for=token_for, max_results=max_results)

async def fetch_games(
self,
Expand Down Expand Up @@ -763,7 +768,12 @@ async def fetch_game(
return Game(data["data"][0], http=self._http)

async def search_categories(
self, query: str, *, token_for: str | None = None, first: int = 20
self,
query: str,
*,
token_for: str | None = None,
first: int = 20,
max_results: int | None = None,
) -> HTTPAsyncIterator[Game]:
"""
Searches Twitch categories.
Expand All @@ -775,6 +785,8 @@ async def search_categories(
first: int
Maximum number of items to return per page. Default is 20.
Min is 1 and Max is 100.
max_results: int | None
Maximum number of total results to return. When this is set to None (default), then everything found is returned.
token_for: str | None
An optional user token to use instead of the default app token.
Returns
Expand All @@ -787,6 +799,7 @@ async def search_categories(
return await self._http.get_search_categories(
query=query,
first=first,
max_results=max_results,
token_for=token_for,
)

Expand Down Expand Up @@ -850,6 +863,7 @@ async def fetch_videos(
sort: Literal["time", "trending", "views"] = "time",
type: Literal["all", "archive", "highlight", "upload"] = "all",
first: int = 20,
max_results: int | None = None,
token_for: str | None = None,
) -> HTTPAsyncIterator[Video]:
"""
Expand All @@ -872,6 +886,10 @@ async def fetch_videos(
sort: Literal["time", "trending", "views"]
type: Literal["all", "archive", "highlight", "upload"]
first: int
Maximum number of items to return per page. Default is 20.
Min is 1 and Max is 100.
max_results: int | None
Maximum number of total results to return. When this is set to None (default), then everything found is returned.
token_for: str | None
An optional user token to use instead of the default app token.
Expand Down Expand Up @@ -904,6 +922,7 @@ async def fetch_videos(
sort=sort,
type=type,
first=first,
max_results=max_results,
token_for=token_for,
)

Expand Down Expand Up @@ -937,7 +956,7 @@ async def delete_videos(self, *, ids: list[str | int], token_for: str) -> list[s
return resp

async def fetch_stream_markers(
self, *, video_id: str, token_for: str, first: int = 20
self, *, video_id: str, token_for: str, first: int = 20, max_results: int | None = None
) -> HTTPAsyncIterator[VideoMarkers]:
"""
Fetches markers from the user's most recent stream or from the specified VOD/video.
Expand All @@ -959,14 +978,18 @@ async def fetch_stream_markers(
first: int
The maximum number of items to return per page in the response.
The minimum page size is 1 item per page and the maximum is 100 items per page. The default is 20.
max_results: int | None
Maximum number of total results to return. When this is set to None (default), then everything found is returned.
Returns
-------
HTTPAsyncIterator[VideoMarkers]
HTTPAsyncIterator of VideoMarkers objects.
"""
first = max(1, min(100, first))
return await self._http.get_stream_markers(video_id=video_id, token_for=token_for, first=first)
return await self._http.get_stream_markers(
video_id=video_id, token_for=token_for, first=first, max_results=max_results
)

async def _create_conduit(self, shard_count: int, /) -> list[Conduit]:
data: ConduitPayload = await self._http.create_conduit(shard_count)
Expand Down

0 comments on commit 0de13e2

Please sign in to comment.