emailnator.asyncio.helpers package¶
Submodules¶
emailnator.asyncio.helpers.metaclass module¶
Asynchronous initialization metaclass.
This module defines AsyncInitMeta, a metaclass that enables classes to support asynchronous initialization via an __ainit__ method. When a class uses this metaclass, calling the class returns a coroutine that must be awaited to obtain the fully constructed and initialized instance.
Typical usage example:
- class MyAsyncClass(metaclass=AsyncInitMeta):
- async def __ainit__(self, value: int) -> None:
await asyncio.sleep(1) self.value = value
- async def main():
obj = await MyAsyncClass(42) print(obj.value) # 42
- class emailnator.asyncio.helpers.metaclass.AsyncInitMeta¶
Bases:
type
emailnator.asyncio.helpers.parser module¶
Utility helper functions used across the project.
This module provides stateless helper functions for general use. Currently, it exposes the Parser class with static methods to simplify common tasks, such as parsing HTTP responses safely as JSON.
- Typical Usage Example:
import httpx from helpers import Helpers resp = httpx.Response(200, content=b’{“key”: [“value”]}’) Helpers.parse_email_response(resp, “get-items”) [‘value’]
- class emailnator.asyncio.helpers.parser.Parser¶
Bases:
objectUtility helpers used across the project.
A small container for stateless helper functions. Currently this class exposes a static method parse_json_response that validates an httpx response and returns its JSON payload, raising a RuntimeError for HTTP errors (status >= 400) or invalid JSON.
- None¶
- async static parse_email_response(response, context)¶
Parse and extract email addresses from an HTTP JSON response.
This coroutine validates the HTTP response and attempts to parse its content as JSON. It expects the JSON to contain an “email” field, which should be a list of strings (email addresses).
- Parameters:
response (httpx.Response) – The HTTP response object to parse.
context (str) – A short description of the request context, used for more informative error messages.
- Returns:
A list of email addresses extracted from the response.
- Return type:
list[str]
- Raises:
RuntimeError – If the response status code is 400 or higher.
RuntimeError – If the response content is not valid JSON.
RuntimeError – If the “email” field is missing or not a list of strings.
- async static parse_message_response(response, context)¶
Parse and validate a message list response from the API.
This coroutine checks the HTTP response for errors and attempts to parse its content as JSON. It extracts the “messageData” field, which is expected to contain a list of message objects.
- Parameters:
response (httpx.Response) – The HTTP response object to parse.
context (str) – Description of the request context, used in error messages.
- Returns:
A list of message dictionaries parsed from the response.
- Return type:
list[dict[str, str]]
- Raises:
RuntimeError – If the response has a status code >= 400.
RuntimeError – If the response body is not valid JSON.
RuntimeError – If the JSON structure does not contain a valid “messageData” list.
Module contents¶
- class emailnator.asyncio.helpers.AsyncInitMeta¶
Bases:
type
- class emailnator.asyncio.helpers.Parser¶
Bases:
objectUtility helpers used across the project.
A small container for stateless helper functions. Currently this class exposes a static method parse_json_response that validates an httpx response and returns its JSON payload, raising a RuntimeError for HTTP errors (status >= 400) or invalid JSON.
- None¶
- async static parse_email_response(response, context)¶
Parse and extract email addresses from an HTTP JSON response.
This coroutine validates the HTTP response and attempts to parse its content as JSON. It expects the JSON to contain an “email” field, which should be a list of strings (email addresses).
- Parameters:
response (httpx.Response) – The HTTP response object to parse.
context (str) – A short description of the request context, used for more informative error messages.
- Returns:
A list of email addresses extracted from the response.
- Return type:
list[str]
- Raises:
RuntimeError – If the response status code is 400 or higher.
RuntimeError – If the response content is not valid JSON.
RuntimeError – If the “email” field is missing or not a list of strings.
- async static parse_message_response(response, context)¶
Parse and validate a message list response from the API.
This coroutine checks the HTTP response for errors and attempts to parse its content as JSON. It extracts the “messageData” field, which is expected to contain a list of message objects.
- Parameters:
response (httpx.Response) – The HTTP response object to parse.
context (str) – Description of the request context, used in error messages.
- Returns:
A list of message dictionaries parsed from the response.
- Return type:
list[dict[str, str]]
- Raises:
RuntimeError – If the response has a status code >= 400.
RuntimeError – If the response body is not valid JSON.
RuntimeError – If the JSON structure does not contain a valid “messageData” list.