diff --git a/src/main.rs b/src/main.rs index 72bc097..8e584a0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,5 +10,5 @@ async fn main() { sensitive::WORKSPACE_ID, ); - dbg!(api.get_projects().await); + dbg!(api.get_clients().await); } diff --git a/src/toggl/mod.rs b/src/toggl/mod.rs index 9a1ce69..b123e04 100644 --- a/src/toggl/mod.rs +++ b/src/toggl/mod.rs @@ -97,6 +97,18 @@ impl TogglApi { .send().await?).await } + pub async fn get_clients(&self) -> Result, TogglError> { + let url = format!( + "{base_url}/workspaces/{workspace_id}/clients", + base_url = BASE_URL, + workspace_id = self.workspace_id + ); + + Self::parse(self.client.get(&url) + .headers(self.headers.clone()) + .send().await?).await + } + async fn parse(response: Response) -> Result { let data = response.text().await?; let result = serde_json_path_to_error::from_str(&data); @@ -178,7 +190,7 @@ mod types { name: String, color: String, - status: Status, + status: ProjectStatus, active: bool, at: DateTime, @@ -193,13 +205,39 @@ mod types { #[derive(Serialize, Deserialize, Debug, Clone)] #[serde(rename_all = "lowercase")] - pub enum Status { + pub enum ProjectStatus { Upcoming, Active, Archived, Ended, Deleted, } + + #[derive(Serialize, Deserialize, Debug, Clone)] + pub struct TrackingClient { + /// The unique identifier for the client. + pub id: i64, + + /// Represents the timestamp of the last update made to the client. + pub at: DateTime, + + /// Indicates whether the client is archived or not. + pub archived: bool, + + pub creator_id: i64, + pub integration_provider: Option, + pub notes: Option, + + /// The name of the client. + pub name: String, + + /// Indicates the timestamp when the client was deleted. If the client is not deleted, this property will be null. + pub server_deleted_at: Option>, + + /// The Workspace ID associated with the client. + #[serde(rename = "wid")] + pub workspace_id: i32, + } } #[derive(Debug, thiserror::Error)]