Source code for codegrade.models.refreshed_heartbeat_response
"""The module that defines the ``RefreshedHeartbeatResponse`` model.
SPDX-License-Identifier: AGPL-3.0-only OR BSD-3-Clause-Clear
"""
from __future__ import annotations
import datetime
import typing as t
from dataclasses import dataclass, field
import cg_request_args as rqa
from ..utils import to_dict
[docs]
@dataclass(kw_only=True)
class RefreshedHeartbeatResponse:
"""The heartbeat was accepted and the session refreshed."""
#: Discriminator.
tag: t.Literal["refreshed"]
#: The session's expires_at after the refresh. When heartbeat enforcement
#: is not active, this is the unchanged current value.
expires_at: datetime.datetime
raw_data: t.Optional[t.Dict[str, t.Any]] = field(init=False, repr=False)
data_parser: t.ClassVar[t.Any] = rqa.Lazy(
lambda: rqa.FixedMapping(
rqa.RequiredArgument(
"tag",
rqa.StringEnum("refreshed"),
doc="Discriminator.",
),
rqa.RequiredArgument(
"expires_at",
rqa.RichValue.DateTime,
doc="The session's expires_at after the refresh. When heartbeat enforcement is not active, this is the unchanged current value.",
),
)
)
def to_dict(self) -> t.Dict[str, t.Any]:
res: t.Dict[str, t.Any] = {
"tag": to_dict(self.tag),
"expires_at": to_dict(self.expires_at),
}
return res
@classmethod
def from_dict(
cls: t.Type[RefreshedHeartbeatResponse], d: t.Dict[str, t.Any]
) -> RefreshedHeartbeatResponse:
parsed = cls.data_parser.try_parse(d)
res = cls(
tag=parsed.tag,
expires_at=parsed.expires_at,
)
res.raw_data = d
return res