Skip to main content

asana_cli/api/
mod.rs

1//! Asana API client module providing authenticated HTTP access, pagination,
2//! and rate-limit aware retry logic.
3
4pub mod attachments;
5pub mod auth;
6pub mod client;
7pub mod custom_fields;
8pub mod error;
9pub mod pagination;
10pub mod projects;
11pub mod sections;
12pub mod stories;
13pub mod tags;
14pub mod tasks;
15pub mod users;
16pub mod workspaces;
17
18pub use attachments::{
19    delete_attachment, download_attachment, get_attachment, list_attachments, upload_attachment,
20};
21pub use auth::{AuthToken, StaticTokenProvider, TokenProvider};
22pub use client::{ApiClient, ApiClientBuilder, ApiClientOptions};
23pub use custom_fields::{get_custom_field, list_custom_fields};
24pub use error::{ApiError, RateLimitInfo};
25pub use pagination::{ListResponse, PaginationInfo};
26pub use projects::{
27    add_members, create_project, delete_project, get_project, list_members, list_projects,
28    list_statuses, remove_members, update_member, update_project,
29};
30pub use sections::{
31    add_task_to_section, create_section, delete_section, get_section, get_section_tasks,
32    list_sections, update_section,
33};
34pub use stories::{create_story, delete_story, get_story, list_stories, update_story};
35pub use tags::{create_tag, delete_tag, get_tag, list_tags, update_tag};
36pub use tasks::{
37    add_dependencies, add_dependents, add_followers, add_project, add_tag, create_task,
38    delete_task, get_task, list_dependencies, list_dependents, list_subtasks, list_tasks,
39    remove_dependencies, remove_dependents, remove_followers, remove_project, remove_tag,
40    search_tasks, update_task,
41};
42pub use users::{get_current_user, get_user, list_users};
43pub use workspaces::{get_workspace, list_workspaces};
44
45use serde::Deserialize;
46
47/// Generic wrapper for Asana API responses that carry a single object.
48#[derive(Debug, Deserialize)]
49pub(crate) struct SingleResponse<T> {
50    pub data: T,
51}
52
53/// Fetch a single resource by path.
54pub(crate) async fn api_get<T: serde::de::DeserializeOwned>(
55    client: &ApiClient,
56    path: &str,
57) -> Result<T, ApiError> {
58    let response: SingleResponse<T> = client.get_json_with_pairs(path, vec![]).await?;
59    Ok(response.data)
60}
61
62/// Create a resource via POST.
63pub(crate) async fn api_post<T: serde::Serialize + Sync, R: serde::de::DeserializeOwned>(
64    client: &ApiClient,
65    path: &str,
66    body: &T,
67) -> Result<R, ApiError> {
68    let response: SingleResponse<R> = client.post_json(path, body).await?;
69    Ok(response.data)
70}
71
72/// Update a resource via PUT.
73pub(crate) async fn api_put<T: serde::Serialize + Sync, R: serde::de::DeserializeOwned>(
74    client: &ApiClient,
75    path: &str,
76    body: &T,
77) -> Result<R, ApiError> {
78    let response: SingleResponse<R> = client.put_json(path, body).await?;
79    Ok(response.data)
80}
81
82/// Delete a resource via DELETE.
83pub(crate) async fn api_delete(client: &ApiClient, path: &str) -> Result<(), ApiError> {
84    client.delete(path, vec![]).await
85}