Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gianklug opened this issue Aug 1, 2023 · 0 comments
Open
Assignees
Labels
breaking breaking change / removal feature feature request / implementation
Milestone

Comments

@gianklug
Copy link
Member

gianklug commented Aug 1, 2023

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.

@gianklug gianklug changed the title feat: Make everything an Object instead of feat: Make everything an Object instead of a dict Aug 1, 2023
@gianklug gianklug changed the title feat: Make everything an Object instead of a dict feat: Make everything an object instead of a dict Aug 1, 2023
@gianklug gianklug changed the title feat: Make everything an object instead of a dict feat: Make everything an object of a custom class instead of a dict Aug 1, 2023
@c0rydoras c0rydoras added feature feature request / implementation breaking breaking change / removal labels Nov 14, 2023
@c0rydoras c0rydoras added this to the libtimed v1 milestone Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking breaking change / removal feature feature request / implementation
Projects
None yet
Development

No branches or pull requests

2 participants