baronet2 / FirstCyclingAPI

An unofficial Python API wrapper for firstcycling.com
https://firstcyclingapi.readthedocs.io/en/latest/
MIT License
25 stars 3 forks source link

Convert endpoints to properties #14

Open baronet2 opened 2 years ago

baronet2 commented 2 years ago

Returning Endpoint instances rather than storing these as properties introduces unnecessary complexity to the Rider and Race sections. It would be better to return the relevant result directly, or return the raw response if it is not being parsed.

For example,Race(XX).victory_table().table should become Race(XX).victory_table.

Such calls should automatically update properties common to all endpoints of that instance, such as Race(XX).header_details. To avoid losing data, all raw responses should be accessible somehow.

Where we accept parameters for the methods, we can separate these into separate attributes or use dictionary syntax instead. For example, Rider(XX).year_results(2020).results_df should become Rider(XX).year_results[2020].

baronet2 commented 2 years ago

The basic case can be implemented by converting methods to cached_propertys.

To achieve the dictionary syntax, we can inherit from CachedDict below.

class CachedDict(dict):
    def __getitem__(self, key):
        if key not in self:
            value = self.compute_value(key)
            self[key] = value
        return self.get(key)

    def compute_value(self, key):
        # Override this method with desired behaviour
        return None

Not sure yet what the best logical way to store raw responses is.