reefapi 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.
reefapi/_errors.py ADDED
@@ -0,0 +1,58 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any, Dict, Optional
4
+
5
+ __all__ = ["ReefAPIError"]
6
+
7
+
8
+ class ReefAPIError(Exception):
9
+ """Raised when a ReefAPI call does not return ``ok: true``.
10
+
11
+ Attributes:
12
+ code: Machine-readable error code from the gateway (``AUTH_FAILED``, ``INVALID_PARAM``,
13
+ ``MISSING_PARAM``, ``RATE_LIMITED``, ``QUOTA_EXCEEDED``, ``TARGET_BLOCKED``,
14
+ ``UPSTREAM_TIMEOUT``, ``NOT_FOUND``, ...). Errors raised by the SDK itself use
15
+ ``TIMEOUT``, ``NETWORK_ERROR``, ``MISSING_API_KEY``, ``INVALID_RESPONSE`` or ``HTTP_<status>``.
16
+ message: Human-readable explanation.
17
+ retryable: ``True`` when the same call may succeed if repeated later.
18
+ status: HTTP status code, or ``None`` when no response was received.
19
+ request_id: The gateway's ``meta.request_id`` (quote it when contacting support).
20
+ meta: The response ``meta`` object, if any.
21
+ details: Optional extra ``error.details`` sent by the gateway.
22
+
23
+ Failed calls are not charged.
24
+ """
25
+
26
+ def __init__(
27
+ self,
28
+ code: str,
29
+ message: str,
30
+ retryable: bool = False,
31
+ status: Optional[int] = None,
32
+ *,
33
+ request_id: Optional[str] = None,
34
+ meta: Optional[Dict[str, Any]] = None,
35
+ details: Any = None,
36
+ ) -> None:
37
+ super().__init__(message)
38
+ self.code = code
39
+ self.message = message
40
+ self.retryable = retryable
41
+ self.status = status
42
+ self.request_id = request_id
43
+ self.meta: Dict[str, Any] = meta or {}
44
+ self.details = details
45
+
46
+ def __str__(self) -> str:
47
+ parts = [f"{self.code}: {self.message}"]
48
+ if self.status is not None:
49
+ parts.append(f"(HTTP {self.status})")
50
+ if self.request_id:
51
+ parts.append(f"[request_id={self.request_id}]")
52
+ return " ".join(parts)
53
+
54
+ def __repr__(self) -> str:
55
+ return (
56
+ f"ReefAPIError(code={self.code!r}, message={self.message!r}, "
57
+ f"retryable={self.retryable!r}, status={self.status!r})"
58
+ )
reefapi/_types.py ADDED
@@ -0,0 +1,57 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass, field
4
+ from typing import Any, Dict, List, Mapping, TypedDict
5
+
6
+ __all__ = ["ReefResponse", "Category", "ParamSpec", "ActionInfo", "EngineInfo"]
7
+
8
+
9
+ @dataclass
10
+ class ReefResponse:
11
+ """The full envelope of a successful call (``client.call_raw``).
12
+
13
+ ``data`` is the payload ``client.call`` returns; ``meta`` carries ``request_id``,
14
+ ``latency_ms``, ``record_count`` and, for paged actions, ``pagination``.
15
+ """
16
+
17
+ data: Any
18
+ meta: Dict[str, Any] = field(default_factory=dict)
19
+ status: int = 200
20
+ headers: Mapping[str, str] = field(default_factory=dict)
21
+
22
+
23
+ class Category(TypedDict, total=False):
24
+ id: str
25
+ title: str
26
+
27
+
28
+ class ParamSpec(TypedDict, total=False):
29
+ name: str
30
+ type: str
31
+ required: bool
32
+ description: str
33
+ default: Any
34
+ example: Any
35
+ allowed_values: List[Dict[str, Any]]
36
+ aliases: List[str]
37
+ minimum: float
38
+ maximum: float
39
+
40
+
41
+ class ActionInfo(TypedDict, total=False):
42
+ name: str
43
+ description: str
44
+ required_params: List[str]
45
+ optional_params: List[str]
46
+ params: List[ParamSpec]
47
+ example_params: Dict[str, Any]
48
+ returns: str
49
+
50
+
51
+ class EngineInfo(TypedDict, total=False):
52
+ name: str
53
+ title: str
54
+ version: str
55
+ category: Category
56
+ base_path: str
57
+ actions: List[ActionInfo]
reefapi/_version.py ADDED
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0"
reefapi/py.typed ADDED
File without changes