1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//! Workspace API endpoints.
use crate::types::Workspace;
use crate::{Client, Error};
/// API for workspace operations.
pub struct WorkspacesApi<'a> {
client: &'a Client,
}
impl<'a> WorkspacesApi<'a> {
/// Create a new workspaces API instance.
pub fn new(client: &'a Client) -> Self {
Self { client }
}
/// List all workspaces accessible to the authenticated user.
///
/// # Example
///
/// ```rust,no_run
/// # use asanaclient::Client;
/// # async fn example() -> Result<(), asanaclient::Error> {
/// let client = Client::from_env()?;
/// let workspaces = client.workspaces().list().await?;
/// for ws in workspaces {
/// println!("{}: {}", ws.gid, ws.name);
/// }
/// # Ok(())
/// # }
/// ```
pub async fn list(&self) -> Result<Vec<Workspace>, Error> {
self.client.get_all("/workspaces", &[]).await
}
/// Get a single workspace by its GID.
///
/// # Example
///
/// ```rust,no_run
/// # use asanaclient::Client;
/// # async fn example() -> Result<(), asanaclient::Error> {
/// let client = Client::from_env()?;
/// let workspace = client.workspaces().get("12345").await?;
/// println!("Workspace: {}", workspace.name);
/// # Ok(())
/// # }
/// ```
pub async fn get(&self, gid: &str) -> Result<Workspace, Error> {
let path = format!("/workspaces/{}", gid);
self.client.get(&path, &[]).await
}
}
impl Client {
/// Access the workspaces API.
pub fn workspaces(&self) -> WorkspacesApi<'_> {
WorkspacesApi::new(self)
}
}