Skip to content

Commit cc2ae9b

Browse files
Update docstrings to use code snippets
1 parent c5fd864 commit cc2ae9b

2 files changed

Lines changed: 24 additions & 18 deletions

File tree

src/simplejustwatchapi/justwatch.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,20 @@ def search(
1919
title: str, country: str = "US", language: str = "en", count: int = 4, best_only: bool = True
2020
) -> list[MediaEntry]:
2121
"""Search JustWatch for given title.
22-
Returns a list of entries up to count.
22+
Returns a list of entries up to ``count``.
23+
``best_only`` allows filtering out redundant offers, e.g. when if provide offers service
24+
in 4K, HD and SD, using ``best_only = True`` returns only 4K option, ``best_only = False``
25+
returns all three.
2326
2427
Args:
2528
title: title to search
26-
country: country to search for offers, "US" by default
27-
language: language of responses, "en" by default
29+
country: country to search for offers, ``US`` by default
30+
language: language of responses, ``en`` by default
2831
count: how many responses should be returned
29-
best_only: return only best offers if True, return all offers if False
32+
best_only: return only best offers if ``True``, return all offers if ``False``
3033
3134
Returns:
32-
List of MediaEntry NamedTuples parsed from JustWatch response
35+
List of ``MediaEntry`` NamedTuples parsed from JustWatch response
3336
"""
3437
request = prepare_search_request(title, country, language, count, best_only)
3538
response = post(_GRAPHQL_API_URL, json=request)
@@ -41,12 +44,15 @@ def details(
4144
node_id: str, country: str = "US", language: str = "en", best_only: bool = True
4245
) -> MediaEntry:
4346
"""Get details of entry for a given ID.
47+
``best_only`` allows filtering out redundant offers, e.g. when if provide offers service
48+
in 4K, HD and SD, using ``best_only = True`` returns only 4K option, ``best_only = False``
49+
returns all three.
4450
4551
Args:
4652
node_id: ID of entry to look up
47-
country: country to search for offers, "US" by default
48-
language: language of responses, "en" by default
49-
best_only: return only best offers if True, return all offers if False
53+
country: country to search for offers, ``US`` by default
54+
language: language of responses, ``en`` by default
55+
best_only: return only best offers if ``True``, return all offers if ``False``
5056
5157
Returns:
5258
MediaEntry NamedTuple with data about requested entry.

src/simplejustwatchapi/query.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,15 @@ def prepare_search_request(
178178
title: str, country: str, language: str, count: int, best_only: bool
179179
) -> dict:
180180
"""Prepare search request for JustWatch GraphQL API.
181-
Creates a "GetSearchTitles" GraphQL query.
181+
Creates a ``GetSearchTitles`` GraphQL query.
182182
Country code should be two uppercase letters, however it will be auto-converted to uppercase.
183183
184184
Args:
185185
title: title to search
186186
country: country to search for offers
187187
language: language of responses
188188
count: how many responses should be returned
189-
best_only: return only best offers if True, return all offers if False
189+
best_only: return only best offers if ``True``, return all offers if ``False``
190190
191191
Returns:
192192
JSON/dict with GraphQL POST body
@@ -211,14 +211,14 @@ def prepare_search_request(
211211

212212
def parse_search_response(json: dict) -> list[MediaEntry]:
213213
"""Parse response from search query from JustWatch GraphQL API.
214-
Parses response for "GetSearchTitles" query.
214+
Parses response for ``GetSearchTitles`` query.
215215
If API didn't return any data, then an empty list is returned.
216216
217217
Args:
218218
json: JSON returned by JustWatch GraphQL API
219219
220220
Returns:
221-
Parsed received JSON as a list of MediaEntry NamedTuples
221+
Parsed received JSON as a list of ``MediaEntry`` NamedTuples
222222
"""
223223
nodes = json["data"]["popularTitles"]["edges"]
224224
entries = [_parse_entry(node["node"]) for node in nodes]
@@ -227,14 +227,14 @@ def parse_search_response(json: dict) -> list[MediaEntry]:
227227

228228
def prepare_details_request(node_id: str, country: str, language: str, best_only: bool) -> dict:
229229
"""Prepare a details request for specified node ID to JustWatch GraphQL API.
230-
Creates a "GetTitleNode" GraphQL query.
230+
Creates a ``GetTitleNode`` GraphQL query.
231231
Country code should be two uppercase letters, however it will be auto-converted to uppercase.
232232
233233
Args:
234234
node_id: node ID of entry to get details for
235235
country: country to search for offers
236236
language: language of responses
237-
best_only: return only best offers if True, return all offers if False
237+
best_only: return only best offers if ``True``, return all offers if ``False``
238238
239239
Returns:
240240
JSON/dict with GraphQL POST body
@@ -258,16 +258,16 @@ def prepare_details_request(node_id: str, country: str, language: str, best_only
258258

259259
def parse_details_response(json: any) -> MediaEntry | None:
260260
"""Parse response from details query from JustWatch GraphQL API.
261-
Parses response for "GetTitleNode" query.
261+
Parses response for ``GetTitleNode`` query.
262262
If API responded with an internal error (mostly due to not found node ID),
263-
then "None" will be returned instead.
263+
then ``None`` will be returned instead.
264264
265265
Args:
266266
json: JSON returned by JustWatch GraphQL API
267267
268268
Returns:
269-
Parsed received JSON as a MediaEntry NamedTuple,
270-
or None in case data for a given node ID was not found
269+
Parsed received JSON as a ``MediaEntry`` NamedTuple,
270+
or ``None`` in case data for a given node ID was not found
271271
"""
272272
return _parse_entry(json["data"]["node"]) if "errors" not in json else None
273273

0 commit comments

Comments
 (0)