adfinis / adfinis/libtimed

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

Open
#14 0 comments 0 reactions 1 assignee View on GitHub

@c0rydoras is already working on this.

Since Aug 1, 2023.

breaking feature
Dominant language
Python
Stars
2
Forks
1
Avg merge
3m
Merged PRs (30d)
1

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.