Skip to content

Commit

Permalink
Rewrite FSM to the state design pattern (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
radeklat authored Nov 11, 2023
1 parent c051ada commit 4449509
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 185 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ Types of changes are:

## [Unreleased]

### Breaking changes

- Rewritten the state logic to the state design pattern for easier understanding and extensibility. This has resulted in changing how the data is stored in the sync cache. Please [reset the cache](README.md#resetting-sync-cache) before upgrading to this version.

### Fixes

- Tasks deleted in habitica being stuck in a loop and logging errors.
- Recurring tasks completed forever in Todoist being stuck in a loop.

## [2.1.10] - 2023-11-01

### Fixes
Expand Down Expand Up @@ -142,7 +151,7 @@ Types of changes are:
- Initial release

[Unreleased]: https://github.com/radeklat/todoist-habitica-sync/compare/2.1.10...HEAD
[2.1.10]: https://github.com/radeklat/todoist-habitica-sync/compare/2.1.0...2.1.10
[2.1.10]: https://github.com/radeklat/todoist-habitica-sync/compare/2.1.9...2.1.10
[2.1.9]: https://github.com/radeklat/todoist-habitica-sync/compare/2.1.8...2.1.9
[2.1.8]: https://github.com/radeklat/todoist-habitica-sync/compare/2.1.7...2.1.8
[2.1.7]: https://github.com/radeklat/todoist-habitica-sync/compare/2.1.6...2.1.7
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,9 @@ Sometimes certain changes require to reset the sync cache. The cache holds stat
To reset the cache:
1. Stop the application.
2. Remove the `.sync_cache/sync_cache.json` file or any other location given in the [`DATABASE_FILE`](#database_file) config option.
3. Start to application again.
4. You should see all existing Todoist tasks loaded again either as `HIDDEN` (finished tasks) or `TODOIST_ACTIVE` (not completed yet).
3. Optionally, [update the application](#update).
4. Start to application again.
5. You should see all existing Todoist tasks loaded again either as `HIDDEN` (finished tasks) or `TODOIST_ACTIVE` (not completed yet).
# Planned work
Expand Down
14 changes: 13 additions & 1 deletion src/habitica_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from typing import Final
from typing import Any, Final

import requests
from pydantic import BaseModel, ConfigDict, Field
Expand Down Expand Up @@ -74,3 +74,15 @@ def __call__(self, **kwargs):
res.raise_for_status()

return res.json()["data"]

def create_task(self, text: str, priority: float) -> dict[str, Any]:
"""See https://habitica.com/apidoc/#api-Task-CreateUserTasks."""
return self.user.tasks(type="todo", text=text, priority=priority, _method="post")

def score_task(self, task_id: str, direction: str = "up") -> None:
"""See https://habitica.com/apidoc/#api-Task-ScoreTask."""
return self.user.tasks(_id=task_id, _direction=direction, _method="post")

def delete_task(self, task_id: str) -> None:
"""See https://habitica.com/apidoc/#api-Task-DeleteTask."""
return self.user.tasks(_id=task_id, _method="delete")
Loading

0 comments on commit 4449509

Please sign in to comment.