-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_base.py
More file actions
59 lines (47 loc) · 1.65 KB
/
_base.py
File metadata and controls
59 lines (47 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""Base classes and utilities for PostGrid API responses."""
from __future__ import annotations
from datetime import datetime
from typing import Generic, TypeVar, Optional, Any
from pydantic import BaseModel, Field
T = TypeVar('T')
class BaseResponse(BaseModel):
"""Base response model for all PostGrid API responses.
Attributes:
id: Unique identifier for the resource
object: Type of the resource (e.g., 'webhook')
created_at: When the resource was created
updated_at: When the resource was last updated
"""
id: str
object: str
created_at: datetime = Field(alias="createdAt")
updated_at: datetime = Field(alias="updatedAt")
class Config:
"""Pydantic config."""
allow_population_by_field_name = True
json_encoders = {
datetime: lambda v: v.isoformat(),
}
class ListResponse(BaseModel, Generic[T]):
"""Generic list response model for paginated results.
Attributes:
data: List of items in the current page
object: Always 'list'
count: Total number of items across all pages
limit: Maximum number of items per page
skip: Number of items skipped for pagination
"""
data: list[T]
object: str = "list"
count: int
limit: int
skip: int = 0
def __len__(self) -> int:
"""Return the number of items in the current page."""
return len(self.data)
def __getitem__(self, index: int) -> T:
"""Get an item by index."""
return self.data[index]
def __iter__(self):
"""Iterate over items in the current page."""
return iter(self.data)