leonhard-s / auraxium

A high-level Python wrapper for the PlanetSide 2 API.
https://auraxium.readthedocs.io/
MIT License
28 stars 8 forks source link

Add Event subclasses #34

Closed leonhard-s closed 3 years ago

leonhard-s commented 3 years ago

Currently, there is a single Event class representing any payloads returned by the websocket API.

It would be beneficial to return a custom data class for each of the ~20 event types. I do not want to replace the EventType enum values as listing the subclasses defined for a given base is more hassle than just looking at the enum values.

leonhard-s commented 3 years ago

(Continuing here to keep it with the issue itself)

@LordFlashmeow Feel free to take this one, it has been bugging me for a while too. I originally pushed this back because I was already working on moving to pydantic for the rest of the object model at the time and wanted to figure that out first.

Here are some thoughts I've written down for myself, for inspiration:

When implementing the MetagameEvent sub class, be wary of the zone_id field; it does not actually get sent with payloads anymore. We can handle this in two ways: Either we don't include it at all and instead add a zone_id property that returns the appropriate value as per the reference in the Wiki, or we make it an optional field that defaults to -1, then add a pydantic validator that performs the same lookup and replacement if the value hasn't been changed. This also allows new alerts to just work in case the field ever gets fixed.

So yeah - if you want to help with this one, I'd appreciate it 👍

leonhard-s commented 3 years ago

Gonna try my hand at implementing the above; I don't want to have to write the event handler docs twice. :D

leonhard-s commented 3 years ago

Added in a24a7f08

LordFlashmeow commented 3 years ago

Nice, that's simpler than what I did. I'll make a draft pr so you can see what I was thinking.