hosteday-python 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. hosteday/__init__.py +111 -0
  2. hosteday/_version.py +3 -0
  3. hosteday/auth/__init__.py +34 -0
  4. hosteday/auth/hosteday_auth.py +444 -0
  5. hosteday/auth/hosteday_auth_storage.py +130 -0
  6. hosteday/auth/hosteday_session.py +184 -0
  7. hosteday/auth/hosteday_token_provider.py +82 -0
  8. hosteday/auth/hosteday_user.py +223 -0
  9. hosteday/cli/__init__.py +5 -0
  10. hosteday/cli/setup.py +163 -0
  11. hosteday/config/__init__.py +15 -0
  12. hosteday/config/hosteday_config.py +576 -0
  13. hosteday/config/hosteday_option_keys.py +60 -0
  14. hosteday/config/hosteday_url_resolver.py +255 -0
  15. hosteday/connectivity/__init__.py +5 -0
  16. hosteday/connectivity/hosteday_connectivity.py +147 -0
  17. hosteday/exceptions.py +233 -0
  18. hosteday/features/__init__.py +5 -0
  19. hosteday/features/hosteday_features.py +78 -0
  20. hosteday/hosteday.py +346 -0
  21. hosteday/hosteday_client.py +579 -0
  22. hosteday/http/__init__.py +18 -0
  23. hosteday/http/hosteday_http_client.py +340 -0
  24. hosteday/http/hosteday_response_reader.py +171 -0
  25. hosteday/http/query_builder.py +204 -0
  26. hosteday/jobs/__init__.py +9 -0
  27. hosteday/jobs/hosteday_job_response.py +76 -0
  28. hosteday/jobs/hosteday_jobs_client.py +109 -0
  29. hosteday/notifications/__init__.py +13 -0
  30. hosteday/notifications/hosteday_notification_client.py +290 -0
  31. hosteday/notifications/hosteday_notification_response.py +79 -0
  32. hosteday/py.typed +1 -0
  33. hosteday/reactive/__init__.py +5 -0
  34. hosteday/reactive/observable_state.py +67 -0
  35. hosteday/realtime/__init__.py +31 -0
  36. hosteday/realtime/connection_state.py +14 -0
  37. hosteday/realtime/hosteday_channel.py +258 -0
  38. hosteday/realtime/hosteday_channel_auth.py +163 -0
  39. hosteday/realtime/hosteday_channel_type.py +68 -0
  40. hosteday/realtime/hosteday_realtime_client.py +790 -0
  41. hosteday/realtime/hosteday_realtime_event.py +130 -0
  42. hosteday/web/__init__.py +5 -0
  43. hosteday/web/server.py +637 -0
  44. hosteday_python/__init__.py +6 -0
  45. hosteday_python/py.typed +1 -0
  46. hosteday_python-0.1.0.dist-info/METADATA +205 -0
  47. hosteday_python-0.1.0.dist-info/RECORD +50 -0
  48. hosteday_python-0.1.0.dist-info/WHEEL +4 -0
  49. hosteday_python-0.1.0.dist-info/entry_points.txt +2 -0
  50. hosteday_python-0.1.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,130 @@
1
+ """Normalized realtime event payload model."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from collections.abc import Mapping
7
+ from dataclasses import dataclass
8
+ from typing import Any
9
+
10
+
11
+ @dataclass(frozen=True)
12
+ class HostedayRealtimeEvent:
13
+ """Represents a realtime event received through HosteDay WebSocket channels."""
14
+
15
+ name: str
16
+ channel_name: str
17
+ payload: dict[str, Any]
18
+ raw: Any = None
19
+
20
+ @classmethod
21
+ def from_raw(
22
+ cls,
23
+ *,
24
+ name: str,
25
+ channel_name: str,
26
+ data: Any,
27
+ raw: Any = None,
28
+ ) -> HostedayRealtimeEvent:
29
+ return cls(
30
+ name=name,
31
+ channel_name=channel_name,
32
+ payload=_normalize_payload(data),
33
+ raw=raw,
34
+ )
35
+
36
+ @property
37
+ def data(self) -> dict[str, Any]:
38
+ return self.payload
39
+
40
+ def __getitem__(self, key: str) -> Any:
41
+ return self.payload[key]
42
+
43
+ def __contains__(self, key: object) -> bool:
44
+ return key in self.payload
45
+
46
+ @property
47
+ def message(self) -> str | None:
48
+ return self._string_value("message")
49
+
50
+ @property
51
+ def id(self) -> str | None:
52
+ return self._string_value("id")
53
+
54
+ @property
55
+ def title(self) -> str | None:
56
+ return self._string_value("title")
57
+
58
+ @property
59
+ def type(self) -> str | None:
60
+ return self._string_value("type")
61
+
62
+ @property
63
+ def user(self) -> dict[str, Any] | None:
64
+ val = self.payload.get("user")
65
+ if isinstance(val, Mapping):
66
+ return dict(val)
67
+ return None
68
+
69
+ @property
70
+ def user_id(self) -> str | None:
71
+ u = self.user
72
+ if u is None or u.get("id") is None:
73
+ return None
74
+ return str(u["id"])
75
+
76
+ @property
77
+ def user_name(self) -> str | None:
78
+ u = self.user
79
+ if u is None or u.get("name") is None:
80
+ return None
81
+ return str(u["name"])
82
+
83
+ @property
84
+ def user_email(self) -> str | None:
85
+ u = self.user
86
+ if u is None or u.get("email") is None:
87
+ return None
88
+ return str(u["email"])
89
+
90
+ def to_json(self) -> dict[str, Any]:
91
+ return {
92
+ "name": self.name,
93
+ "channel": self.channel_name,
94
+ "payload": self.payload,
95
+ }
96
+
97
+ def _string_value(self, key: str) -> str | None:
98
+ value = self.payload.get(key)
99
+ if value is None:
100
+ return None
101
+ text = str(value).strip()
102
+ return text if text else None
103
+
104
+
105
+ def _normalize_payload(data: Any) -> dict[str, Any]:
106
+ if data is None:
107
+ return {}
108
+ if isinstance(data, Mapping):
109
+ return dict(data)
110
+ if isinstance(data, str):
111
+ return _normalize_string_payload(data)
112
+ return {"data": data}
113
+
114
+
115
+ def _normalize_string_payload(data: str, *, depth: int = 0) -> dict[str, Any]:
116
+ trimmed = data.strip()
117
+ if not trimmed:
118
+ return {}
119
+ try:
120
+ decoded = json.loads(trimmed)
121
+ except json.JSONDecodeError:
122
+ return {"message": data}
123
+
124
+ if decoded is None:
125
+ return {}
126
+ if isinstance(decoded, Mapping):
127
+ return dict(decoded)
128
+ if isinstance(decoded, str) and depth < 2:
129
+ return _normalize_string_payload(decoded, depth=depth + 1)
130
+ return {"data": decoded}
@@ -0,0 +1,5 @@
1
+ """Embedded high-level web server facade powered internally by FastAPI and Uvicorn."""
2
+
3
+ from hosteday.web.server import HostedayWebApp, HostedayWebError
4
+
5
+ __all__ = ["HostedayWebApp", "HostedayWebError"]