Skip to content

Commit 25c5942

Browse files
Extract verification of country codes to separate function
1 parent cc2ae9b commit 25c5942

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/simplejustwatchapi/query.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def prepare_search_request(
191191
Returns:
192192
JSON/dict with GraphQL POST body
193193
"""
194-
assert len(country) == 2, f"Invalid country code: {country}, code must be 2 characters long"
194+
_assert_country_code_is_valid(country)
195195
return {
196196
"operationName": "GetSearchTitles",
197197
"variables": {
@@ -239,7 +239,7 @@ def prepare_details_request(node_id: str, country: str, language: str, best_only
239239
Returns:
240240
JSON/dict with GraphQL POST body
241241
"""
242-
assert len(country) == 2, f"Invalid country code: {country}, code must be 2 characters long"
242+
_assert_country_code_is_valid(country)
243243
return {
244244
"operationName": "GetTitleNode",
245245
"variables": {
@@ -272,6 +272,10 @@ def parse_details_response(json: any) -> MediaEntry | None:
272272
return _parse_entry(json["data"]["node"]) if "errors" not in json else None
273273

274274

275+
def _assert_country_code_is_valid(code: str) -> None:
276+
assert len(code) == 2, f"Invalid country code: {code}, code must be 2 characters long"
277+
278+
275279
def _parse_entry(json: any) -> MediaEntry:
276280
entry_id = json.get("id")
277281
object_id = json.get("objectId")

0 commit comments

Comments
 (0)