An ebook/comic library service and web client
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.1 KiB

  1. """Model definitions for the api module."""
  2. from typing import Any, List, Optional, Dict
  3. class APIResponse: # pylint: disable=too-few-public-methods
  4. """Custom class to wrap api responses."""
  5. def __init__(self,
  6. payload: Any,
  7. status: int = 200,
  8. options: Optional[List[str]] = None) -> None:
  9. """Construct an APIResponse object."""
  10. self.payload = payload
  11. self.status = status
  12. self.options = options
  13. class APIMessage: # pylint: disable=too-few-public-methods
  14. """Simple class to encapsulate response messages."""
  15. success: bool
  16. message: Optional[str]
  17. def __init__(self,
  18. success: bool,
  19. message: Optional[str]) -> None:
  20. """Construct an APIMessage."""
  21. self.success = success
  22. self.message = message
  23. def to_dict(self) -> dict:
  24. """Serialize an APIMessage to a dict."""
  25. obj: Dict[str, Any] = {
  26. 'success': self.success
  27. }
  28. if self.message is not None:
  29. obj['message'] = self.message
  30. return obj