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 field properties to object model #17

Closed leonhard-s closed 3 years ago

leonhard-s commented 4 years ago

Currently most data received through the object model is only available through Ps2Object.data, which is a named tuple containing the original data received.

However, all commonly used data should also be available through class @property-s. The named tuple is only for reference when making requests.

Some thoughts/tentative guidelines:

Example:

# auraxium.ps2.Character class

@property
def playtime(self) -> float:
    """Return the character's playtime in hours.

    This uses :attr:`Character.data.times.minutes_played`, divided
    by 60.
    """
    return self.data.times.minutes_played / 60.0
leonhard-s commented 3 years ago

I ended up implementing a fallback __getattr__ hook to Ps2Object to fall through to the data class for attributes and added type hints to include these attributes in the regular object's IntelliSense (21e7e6e).

This is slightly redundant, but also allows us to rename and reorganise attributes in the main classes as we desire (e.g. prestive_level being renamed or aliased to asp_rank).