Add _RecursiveSerializer class in bfxapi/labeler.py file. Add support to new pulse endpoints (with serializers and types). Add examples/rest/get_pulse_data.py demo.

This commit is contained in:
itsdeka
2023-01-24 12:10:57 +01:00
committed by Davide Casale
parent 36725a183e
commit ae42fb7d93
5 changed files with 131 additions and 4 deletions

View File

@@ -58,7 +58,7 @@ class _Requests(object):
raise RequestParametersError(f"The request was rejected with the following parameter error: <{data[2]}>")
if data[1] == None or data[1] == Error.ERR_UNK or data[1] == Error.ERR_GENERIC:
raise UnknownGenericError("The server replied to the request with a generic error with message: <{data[2]}>.")
raise UnknownGenericError(f"The server replied to the request with a generic error with message: <{data[2]}>.")
return data
@@ -255,6 +255,19 @@ class _RestPublicEndpoints(_Requests):
def conf(self, config: Config) -> Any:
return self._GET(f"conf/{config}")[0]
def get_pulse_profile(self, nickname: str) -> PulseProfile:
return serializers.PulseProfile.parse(*self._GET(f"pulse/profile/{nickname}"))
def get_pulse_history(self, end: Optional[str] = None, limit: Optional[int] = None) -> List[PulseMessage]:
messages = list()
for subdata in self._GET("pulse/hist", params={ "end": end, "limit": limit }):
subdata[18] = subdata[18][0]
message = serializers.PulseMessage.parse(*subdata)
messages.append(message)
return messages
class _RestAuthenticatedEndpoints(_Requests):
def get_wallets(self) -> List[Wallet]:
return [ serializers.Wallet.parse(*subdata) for subdata in self._POST("auth/r/wallets") ]

View File

@@ -1,6 +1,6 @@
from . import types
from .. labeler import generate_labeler_serializer
from .. labeler import generate_labeler_serializer, generate_recursive_serializer
from .. notification import _Notification
@@ -185,6 +185,51 @@ FundingStatistic = generate_labeler_serializer("FundingStatistic", klass=types.F
"FUNDING_BELOW_THRESHOLD"
])
PulseProfile = generate_labeler_serializer("PulseProfile", klass=types.PulseProfile, labels=[
"PUID",
"MTS",
"_PLACEHOLDER",
"NICKNAME",
"_PLACEHOLDER",
"PICTURE",
"TEXT",
"_PLACEHOLDER",
"_PLACEHOLDER",
"TWITTER_HANDLE",
"_PLACEHOLDER",
"FOLLOWERS",
"FOLLOWING",
"_PLACEHOLDER",
"_PLACEHOLDER",
"_PLACEHOLDER",
"TIPPING_STATUS"
])
PulseMessage = generate_recursive_serializer("PulseMessage", klass=types.PulseMessage, serializers={ "PROFILE": PulseProfile }, labels=[
"PID",
"MTS",
"_PLACEHOLDER",
"PUID",
"_PLACEHOLDER",
"TITLE",
"CONTENT",
"_PLACEHOLDER",
"_PLACEHOLDER",
"IS_PIN",
"IS_PUBLIC",
"COMMENTS_DISABLED",
"TAGS",
"ATTACHMENTS",
"META",
"LIKES",
"_PLACEHOLDER",
"_PLACEHOLDER",
"PROFILE",
"COMMENTS",
"_PLACEHOLDER",
"_PLACEHOLDER"
])
#endregion
#region Serializers definition for Rest Authenticated Endpoints

View File

@@ -152,6 +152,35 @@ class FundingStatistic(_Type):
FUNDING_AMOUNT_USED: float
FUNDING_BELOW_THRESHOLD: float
@dataclass
class PulseProfile(_Type):
PUID: str
MTS: int
NICKNAME: str
PICTURE: str
TEXT: str
TWITTER_HANDLE: str
FOLLOWERS: int
FOLLOWING: int
TIPPING_STATUS: int
@dataclass
class PulseMessage(_Type):
PID: str
MTS: int
PUID: str
TITLE: str
CONTENT: str
IS_PIN: int
IS_PUBLIC: int
COMMENTS_DISABLED: int
TAGS: List[str]
ATTACHMENTS: List[str]
META: List[JSON]
LIKES: int
PROFILE: PulseProfile
COMMENTS: int
#endregion
#region Type hinting for Rest Authenticated Endpoints