111 lines
3.2 KiB
Python
111 lines
3.2 KiB
Python
import datetime
|
|
from collections.abc import Mapping
|
|
from typing import Any, TypeVar, Union, cast
|
|
|
|
from attrs import define as _attrs_define
|
|
from attrs import field as _attrs_field
|
|
from dateutil.parser import isoparse
|
|
|
|
from ..types import UNSET, Unset
|
|
|
|
T = TypeVar("T", bound="ClientModel")
|
|
|
|
|
|
@_attrs_define
|
|
class ClientModel:
|
|
"""The Client holds information about a device which can receive notifications (and other stuff).
|
|
|
|
Attributes:
|
|
id (int): The client id. Example: 5.
|
|
name (str): The client name. This is how the client should be displayed to the user. Example: Android Phone.
|
|
token (str): The client token. Can be used as `clientToken`. See Authentication. Example: CWH0wZ5r0Mbac.r.
|
|
last_used (Union[None, Unset, datetime.datetime]): The last time the client token was used. Example: 2019-01-01
|
|
00:00:00+00:00.
|
|
"""
|
|
|
|
id: int
|
|
name: str
|
|
token: str
|
|
last_used: Union[None, Unset, datetime.datetime] = UNSET
|
|
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
|
|
|
|
def to_dict(self) -> dict[str, Any]:
|
|
id = self.id
|
|
|
|
name = self.name
|
|
|
|
token = self.token
|
|
|
|
last_used: Union[None, Unset, str]
|
|
if isinstance(self.last_used, Unset):
|
|
last_used = UNSET
|
|
elif isinstance(self.last_used, datetime.datetime):
|
|
last_used = self.last_used.isoformat()
|
|
else:
|
|
last_used = self.last_used
|
|
|
|
field_dict: dict[str, Any] = {}
|
|
field_dict.update(self.additional_properties)
|
|
field_dict.update(
|
|
{
|
|
"id": id,
|
|
"name": name,
|
|
"token": token,
|
|
}
|
|
)
|
|
if last_used is not UNSET:
|
|
field_dict["lastUsed"] = last_used
|
|
|
|
return field_dict
|
|
|
|
@classmethod
|
|
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
|
|
d = dict(src_dict)
|
|
id = d.pop("id")
|
|
|
|
name = d.pop("name")
|
|
|
|
token = d.pop("token")
|
|
|
|
def _parse_last_used(data: object) -> Union[None, Unset, datetime.datetime]:
|
|
if data is None:
|
|
return data
|
|
if isinstance(data, Unset):
|
|
return data
|
|
try:
|
|
if not isinstance(data, str):
|
|
raise TypeError()
|
|
last_used_type_1 = isoparse(data)
|
|
|
|
return last_used_type_1
|
|
except: # noqa: E722
|
|
pass
|
|
return cast(Union[None, Unset, datetime.datetime], data)
|
|
|
|
last_used = _parse_last_used(d.pop("lastUsed", UNSET))
|
|
|
|
client_model = cls(
|
|
id=id,
|
|
name=name,
|
|
token=token,
|
|
last_used=last_used,
|
|
)
|
|
|
|
client_model.additional_properties = d
|
|
return client_model
|
|
|
|
@property
|
|
def additional_keys(self) -> list[str]:
|
|
return list(self.additional_properties.keys())
|
|
|
|
def __getitem__(self, key: str) -> Any:
|
|
return self.additional_properties[key]
|
|
|
|
def __setitem__(self, key: str, value: Any) -> None:
|
|
self.additional_properties[key] = value
|
|
|
|
def __delitem__(self, key: str) -> None:
|
|
del self.additional_properties[key]
|
|
|
|
def __contains__(self, key: str) -> bool:
|
|
return key in self.additional_properties
|