Skip to content

feat: Make everything an object of a custom class instead of a dict #14

Description

@gianklug

Currently if I do a timed.tasks.get() I get greeted with a dict of many values.
If I want to get the ID of the associated task I'd have to do the following:

print(timed.reports.get()[0]["relationships"]["task"]["data"]["id"])

This isn't very readable and clutters the codebase of end-user applications like timedctl.

My approach would be the following (code example):

>>> reports = timed.reports.get()
>>> some_report = reports[0]
>>> type(some_report)
<class 'libtimed.Report'>
>>> task = some_report.task
>>> type(task)
<class 'libtimed.Task'>
>>> print(task.id)
1234

basically we also want a class for the singular version of each datatype; Task for Tasks, etc.

This way we have a much cleaner code base and an easier development flow as people don't have to look at the raw dicts that the API would return.

However, to maintain backwards compatibility we also need the __dict__ method of each object to still return the dict how it used to be.

Metadata

Metadata

Assignees

Labels

breakingbreaking change / removalfeaturefeature request / implementation

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions