Skip to content

Commit ee8dc64

Browse files
Tweak docstrings
Update type hints, add raised exceptions.
1 parent 204db1d commit ee8dc64

5 files changed

Lines changed: 116 additions & 101 deletions

File tree

docs/simplejustwatchapi.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,34 @@ Module contents
1212
Submodules
1313
----------
1414

15-
simplejustwatchapi.graphql module
16-
---------------------------------
15+
simplejustwatchapi.justwatch module
16+
-----------------------------------
1717

18-
.. automodule:: simplejustwatchapi.graphql
18+
.. automodule:: simplejustwatchapi.justwatch
1919
:members:
2020
:undoc-members:
2121
:show-inheritance:
2222

23-
simplejustwatchapi.justwatch module
24-
-----------------------------------
23+
simplejustwatchapi.tuples module
24+
--------------------------------
2525

26-
.. automodule:: simplejustwatchapi.justwatch
26+
.. automodule:: simplejustwatchapi.tuples
2727
:members:
2828
:undoc-members:
2929
:show-inheritance:
3030

31-
simplejustwatchapi.query module
32-
-------------------------------
31+
simplejustwatchapi.graphql module
32+
---------------------------------
3333

34-
.. automodule:: simplejustwatchapi.query
34+
.. automodule:: simplejustwatchapi.graphql
3535
:members:
3636
:undoc-members:
3737
:show-inheritance:
3838

39-
simplejustwatchapi.tuples module
40-
--------------------------------
39+
simplejustwatchapi.query module
40+
-------------------------------
4141

42-
.. automodule:: simplejustwatchapi.tuples
42+
.. automodule:: simplejustwatchapi.query
4343
:members:
4444
:undoc-members:
4545
:show-inheritance:

src/simplejustwatchapi/graphql.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def graphql_search_query() -> str:
266266
The query is GetSearchTitles query + details fragment + offers fragment.
267267
268268
Returns:
269-
str with full GraphQL "search" query
269+
str: Full GraphQL "search" query.
270270
271271
"""
272272
return _GRAPHQL_SEARCH_QUERY + _GRAPHQL_DETAILS_FRAGMENT + _GRAPHQL_OFFER_FRAGMENT
@@ -281,7 +281,7 @@ def graphql_details_query() -> str:
281281
it just won't return full season/episodes list.
282282
283283
Returns:
284-
str with full GraphQL "get details" query
284+
str: Full GraphQL "get details" query.
285285
286286
"""
287287
return _GRAPHQL_DETAILS_QUERY + _GRAPHQL_DETAILS_FRAGMENT + _GRAPHQL_OFFER_FRAGMENT
@@ -297,7 +297,7 @@ def graphql_seasons_query() -> str:
297297
relevant data for seasons.
298298
299299
Returns:
300-
str with full GraphQL "get seasons" query
300+
str: Full GraphQL "get seasons" query.
301301
302302
"""
303303
return _GRAPHQL_SEASONS_QUERY + _GRAPHQL_DETAILS_FRAGMENT + _GRAPHQL_OFFER_FRAGMENT
@@ -313,7 +313,7 @@ def graphql_episodes_query() -> str:
313313
relevant data for episodes.
314314
315315
Returns:
316-
str with full GraphQL "get episodes" query
316+
str: Full GraphQL "get episodes" query.
317317
318318
"""
319319
return _GRAPHQL_EPISODES_QUERY + _GRAPHQL_DETAILS_FRAGMENT + _GRAPHQL_OFFER_FRAGMENT
@@ -331,10 +331,10 @@ def graphql_offers_for_countries_query(countries: set[str]) -> str:
331331
the set is not empty; it performs no additional verification.
332332
333333
Args:
334-
countries: set of 2-letter country codes
334+
countries (set[str]): 2-letter country codes.
335335
336336
Returns:
337-
str with full GraphQL "get offers per country" query
337+
str: Full GraphQL "get offers per country" query.
338338
339339
"""
340340
offer_requests = [

src/simplejustwatchapi/justwatch.py

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
from httpx import post
44

55
from simplejustwatchapi.query import (
6-
Episode,
7-
MediaEntry,
8-
Offer,
96
parse_details_response,
107
parse_episodes_response,
118
parse_offers_for_countries_response,
@@ -17,6 +14,7 @@
1714
prepare_search_request,
1815
prepare_seasons_request,
1916
)
17+
from simplejustwatchapi.tuples import Episode, MediaEntry, Offer
2018

2119
_GRAPHQL_API_URL = "https://apis.justwatch.com/graphql"
2220

@@ -33,19 +31,22 @@ def search(
3331
3432
Returns a list of entries up to ``count``.
3533
36-
``best_only`` allows filtering out redundant offers, e.g. when if provide offers service
34+
``best_only`` allows filtering out redundant offers, e.g. when service provides offers
3735
in 4K, HD and SD, using ``best_only = True`` returns only 4K option, ``best_only = False``
3836
returns all three.
3937
4038
Args:
41-
title: title to search
42-
country: country to search for offers, ``US`` by default
43-
language: language of responses, ``en`` by default
44-
count: how many responses should be returned
45-
best_only: return only best offers if ``True``, return all offers if ``False``
39+
title (str): Title to search.
40+
country (str): Country to search for offers, ``US`` by default.
41+
language (str): Language of responses, ``en`` by default.
42+
count (int): How many responses should be returned.
43+
best_only (bool): Return only best offers if ``True``, return all offers if ``False``.
4644
4745
Returns:
48-
List of ``MediaEntry`` NamedTuples parsed from JustWatch response
46+
list[MediaEntry]: List of ``MediaEntry`` NamedTuples parsed from JustWatch response.
47+
48+
Raises:
49+
httpx.HTTPStatusError: If JustWatch API doesn't respond with success code.
4950
5051
"""
5152
request = prepare_search_request(title, country, language, count, best_only)
@@ -68,15 +69,18 @@ def details(
6869
returns all three.
6970
7071
Args:
71-
node_id: ID of entry to look up
72-
country: country to search for offers, ``US`` by default
73-
language: language of responses, ``en`` by default
74-
best_only: return only best offers if ``True``, return all offers if ``False``
72+
node_id (str): ID of entry to look up.
73+
country (str): Country to search for offers, ``US`` by default.
74+
language (str): Language of responses, ``en`` by default.
75+
best_only (bool): Return only best offers if ``True``, return all offers if ``False``.
7576
7677
Returns:
77-
``MediaEntry`` NamedTuple with data about requested entry,
78+
MediaEntry | None: ``MediaEntry`` NamedTuple with data about requested entry,
7879
or None in case data for a given node ID was not found
7980
81+
Raises:
82+
httpx.HTTPStatusError: If JustWatch API doesn't respond with success code.
83+
8084
"""
8185
request = prepare_details_request(node_id, country, language, best_only)
8286
response = post(_GRAPHQL_API_URL, json=request)
@@ -95,15 +99,18 @@ def seasons(
9599
returns all three.
96100
97101
Args:
98-
show_id: ID of show to look up seasons for
99-
country: country to search for offers, ``US`` by default
100-
language: language of responses, ``en`` by default
101-
best_only: return only best offers if ``True``, return all offers if ``False``
102+
show_id (str): ID of show to look up seasons for.
103+
country (str): Country to search for offers, ``US`` by default.
104+
language (str): Language of responses, ``en`` by default.
105+
best_only (bool): Return only best offers if ``True``, return all offers if ``False``.
102106
103107
Returns:
104-
``MediaEntry`` NamedTuple with data about requested entry,
108+
list[MediaEntry] | None: List of ``MediaEntry`` NamedTuples with data about requested entry,
105109
or None in case data for a given node ID was not found
106110
111+
Raises:
112+
httpx.HTTPStatusError: If JustWatch API doesn't respond with success code.
113+
107114
"""
108115
request = prepare_seasons_request(show_id, country, language, best_only)
109116
response = post(_GRAPHQL_API_URL, json=request)
@@ -122,14 +129,17 @@ def episodes(
122129
returns all three.
123130
124131
Args:
125-
season_id: ID of season to look up episodes for
126-
country: country to search for offers, ``US`` by default
127-
language: language of responses, ``en`` by default
128-
best_only: return only best offers if ``True``, return all offers if ``False``
132+
season_id (str): ID of season to look up episodes for.
133+
country (str): Country to search for offers, ``US`` by default.
134+
language (str): Language of responses, ``en`` by default.
135+
best_only (bool): Return only best offers if ``True``, return all offers if ``False``.
129136
130137
Returns:
131-
``MediaEntry`` NamedTuple with data about requested entry,
132-
or None in case data for a given node ID was not found
138+
list[Episode] | None: List of ``Episode`` NamedTuples with data about requested entry,
139+
or None in case data for a given node ID was not found.
140+
141+
Raises:
142+
httpx.HTTPStatusError: If JustWatch API doesn't respond with success code.
133143
134144
"""
135145
request = prepare_episodes_request(season_id, country, language, best_only)
@@ -176,14 +186,17 @@ def offers_for_countries(
176186
returns all three.
177187
178188
Args:
179-
node_id: ID of entry to look up offers for
180-
countries: set of country codes to search for offers
181-
language: language of responses, ``en`` by default
182-
best_only: return only best offers if ``True``, return all offers if ``False``
189+
node_id (str): ID of entry to look up offers for.
190+
countries (set[str]): 2-letter country codes to search for offers.
191+
language (str): Language of responses, ``en`` by default.
192+
best_only (bool): Return only best offers if ``True``, return all offers if ``False``.
183193
184194
Returns:
185-
``dict`` where keys match values in ``countries`` and keys are all found offers for their
186-
respective countries
195+
dict[str, list[Offer]]: ``dict`` where keys match values in ``countries``
196+
and keys are all found offers for their respective countries.
197+
198+
Raises:
199+
httpx.HTTPStatusError: If JustWatch API doesn't respond with success code.
187200
188201
"""
189202
if not countries:

0 commit comments

Comments
 (0)