todoist_api/
lib.rs

1//! # Todoist-api
2//!
3//! A Rust wrapper for the Todoist REST API v2.
4//!
5//! ## Features
6//!
7//! - Async/await support
8//! - Full CRUD operations for tasks
9//! - Project and label management
10//! - Comprehensive error handling with anyhow
11//! - Serde serialization/deserialization
12//!
13//! ## Example
14//!
15//! ```rust,no_run
16//! use todoist_api::TodoistWrapper;
17//!
18//! #[tokio::main]
19//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
20//!     let todoist = TodoistWrapper::new("your-api-token".to_string());
21//!     
22//!     // Get all tasks
23//!     let tasks = todoist.get_tasks().await?;
24//!     println!("Found {} tasks", tasks.len());
25//!     
26//!     // Create a new task
27//!     let new_task = todoist.create_simple_task("Buy groceries", None).await?;
28//!     println!("Created task: {}", new_task.content);
29//!     
30//!     Ok(())
31//! }
32//! ```
33
34pub mod models;
35pub mod wrapper;
36
37pub use models::*;
38pub use wrapper::TodoistWrapper;
39
40// Re-export commonly used types
41pub use anyhow::Result;
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn test_todoist_wrapper_creation() {
49        let _wrapper = TodoistWrapper::new("test-token".to_string());
50        // Test that the wrapper was created successfully without panicking
51        // We can't access private fields, so we just verify creation works
52        assert!(true); // Placeholder assertion
53    }
54
55    #[test]
56    fn test_library_exports() {
57        // Test that all main types are properly exported
58        let _task: Task = Task {
59            id: "test".to_string(),
60            content: "test".to_string(),
61            description: "test".to_string(),
62            project_id: "test".to_string(),
63            section_id: None,
64            parent_id: None,
65            order: 1,
66            priority: 1,
67            is_completed: false,
68            labels: vec![],
69            created_at: "2024-01-01T00:00:00Z".to_string(),
70            due: None,
71            deadline: None,
72            duration: None,
73            assignee_id: None,
74            url: "https://todoist.com".to_string(),
75            comment_count: 0,
76        };
77
78        let _project: Project = Project {
79            id: "test".to_string(),
80            name: "test".to_string(),
81            comment_count: 0,
82            order: 1,
83            color: "blue".to_string(),
84            is_shared: false,
85            is_favorite: false,
86            is_inbox_project: false,
87            is_team_inbox: false,
88            view_style: "list".to_string(),
89            url: "https://todoist.com".to_string(),
90            parent_id: None,
91        };
92
93        let _label: Label = Label {
94            id: "test".to_string(),
95            name: "test".to_string(),
96            color: "red".to_string(),
97            order: 1,
98            is_favorite: false,
99        };
100
101        let _wrapper: TodoistWrapper = TodoistWrapper::new("test".to_string());
102
103        // Test that Result is properly exported
104        let _result: Result<()> = Ok(());
105    }
106
107    #[test]
108    fn test_argument_types() {
109        // Test that argument types can be created and used
110        let task_args = CreateTaskArgs {
111            content: "Test task".to_string(),
112            priority: Some(3),
113            ..Default::default()
114        };
115
116        assert_eq!(task_args.content, "Test task");
117        assert_eq!(task_args.priority, Some(3));
118
119        let project_args = CreateProjectArgs {
120            name: "Test project".to_string(),
121            color: Some("blue".to_string()),
122            ..Default::default()
123        };
124
125        assert_eq!(project_args.name, "Test project");
126        assert_eq!(project_args.color, Some("blue".to_string()));
127    }
128}