FirstCyclingAPI icon indicating copy to clipboard operation
FirstCyclingAPI copied to clipboard

Convert endpoints to properties

Open baronet2 opened this issue 3 years ago • 1 comments

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 avatar Dec 18 '21 04:12 baronet2

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.

baronet2 avatar Dec 18 '21 04:12 baronet2