twitchAPI.helper

Helper functions

twitchAPI.helper.extract_uuid_str_from_url(url: str) Optional[str]

Extracts a UUID string from a URL

Parameters

url (str) – The URL to parse

Returns

UUID string extracted from given URL or None if no UUID found

Return type

Union[str, None]

twitchAPI.helper.build_url(url: str, params: dict, remove_none=False, split_lists=False, enum_value=True) str

Build a valid url string

Parameters
  • url – base URL

  • params – dictionary of URL parameter

  • remove_none (bool) – if set all params that have a None value get removed

    Default: False

  • split_lists (bool) – if set all params that are a list will be split over multiple url parameter with the same name

    Default: False

  • enum_value (bool) – if true, automatically get value string from Enum values

    Default: True

Returns

URL

Return type

str

twitchAPI.helper.get_uuid()

Returns a random UUID

Return type

UUID

async twitchAPI.helper.get_json(request: aiohttp.web_request.Request) Optional[Union[list, dict]]

Tries to retrieve the json object from the body

Parameters

request – the request

Returns

the object in the body or None

twitchAPI.helper.make_fields_datetime(data: Union[dict, list], fields: List[str])

Itterates over dict or list recursivly to replace string fields with datetime

Parameters
  • data (union[dict, list]) – dict or list

  • fields (list[str]) – list of keys to be replaced

Return type

union[dict, list]

twitchAPI.helper.build_scope(scopes: List[twitchAPI.types.AuthScope]) str

Builds a valid scope string from list

Parameters

scopes (list[AuthScope]) – list of AuthScope

Return type

str

Returns

the valid auth scope string

twitchAPI.helper.fields_to_enum(data: Union[dict, list], fields: List[str], _enum: Type[enum.Enum], default: Optional[enum.Enum]) Union[dict, list]

Itterates a dict or list and tries to replace every dict entry with key in fields with the correct Enum value

Parameters
  • data (Union[dict, list]) – dict or list

  • fields (list[str]) – list of keys to be replaced

  • _enum – Type of Enum to be replaced

  • default – The default value if _enum does not contain the field value

Return type

dict or list

twitchAPI.helper.remove_none_values(d: dict) dict

Removes items where the value is None from the dict. This returns a new dict and does not manipulate the one given.