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: add duration to Task object #109

Merged
merged 3 commits into from
May 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions todoist_api_python/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,21 @@ class Task(object):
project_id: str
section_id: str | None
url: str
duration: Duration | None

sync_id: str | None = None

@classmethod
def from_dict(cls, obj):
due: Due | None = None
duration: Duration | None = None

if obj.get("due"):
due = Due.from_dict(obj["due"])

if obj.get("duration"):
duration = Duration.from_dict(obj["duration"])

return cls(
assignee_id=obj.get("assignee_id"),
assigner_id=obj.get("assigner_id"),
Expand All @@ -156,6 +161,7 @@ def from_dict(cls, obj):
project_id=obj["project_id"],
section_id=obj["section_id"],
url=obj["url"],
duration=duration
)

def to_dict(self):
Expand Down Expand Up @@ -183,15 +189,20 @@ def to_dict(self):
"section_id": self.section_id,
"sync_id": self.sync_id,
"url": self.url,
"duration": self.duration
}

@classmethod
def from_quick_add_response(cls, obj):
due: Due | None = None
duration: Duration | None = None

if obj.get("due"):
due = Due.from_quick_add_response(obj)

if obj.get("duration"):
duration = Duration.from_dict(obj["duration"])

return cls(
assignee_id=obj.get("responsible_uid"),
assigner_id=obj.get("assigned_by_uid"),
Expand All @@ -202,6 +213,7 @@ def from_quick_add_response(cls, obj):
creator_id=obj["added_by_uid"],
description=obj["description"],
due=due,
duration=duration,
id=obj["id"],
labels=obj["labels"],
order=obj["child_order"],
Expand Down Expand Up @@ -421,3 +433,22 @@ def from_dict(cls, obj: dict[str, Any]) -> CompletedItems:
has_more=obj["has_more"],
next_cursor=obj.get("next_cursor"),
)


@dataclass
class Duration(object):
amount: int
unit: str

@classmethod
def from_dict(cls, obj):
return cls(
amount=obj["amount"],
unit=obj["unit"],
)

def to_dict(self):
return {
"amount": self.amount,
"unit": self.unit,
}
Loading