Skip to content

Commit

Permalink
feat: add duration to Task object
Browse files Browse the repository at this point in the history
  • Loading branch information
eitchtee authored Sep 7, 2023
1 parent cf8393c commit 8d67f1c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 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,6 +189,7 @@ def to_dict(self):
"section_id": self.section_id,
"sync_id": self.sync_id,
"url": self.url,
"duration": self.duration
}

@classmethod
Expand Down Expand Up @@ -421,3 +428,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,
}

0 comments on commit 8d67f1c

Please sign in to comment.