Add Clients

This commit is contained in:
Joshua Coles 2024-07-15 16:42:18 +01:00
parent f447cabed1
commit 29a8865bd5
2 changed files with 41 additions and 3 deletions

View File

@ -10,5 +10,5 @@ async fn main() {
sensitive::WORKSPACE_ID,
);
dbg!(api.get_projects().await);
dbg!(api.get_clients().await);
}

View File

@ -97,6 +97,18 @@ impl TogglApi {
.send().await?).await
}
pub async fn get_clients(&self) -> Result<Vec<types::TrackingClient>, 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<T: DeserializeOwned>(response: Response) -> Result<T, TogglError> {
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<Utc>,
@ -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<Utc>,
/// Indicates whether the client is archived or not.
pub archived: bool,
pub creator_id: i64,
pub integration_provider: Option<String>,
pub notes: Option<String>,
/// 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<DateTime<Utc>>,
/// The Workspace ID associated with the client.
#[serde(rename = "wid")]
pub workspace_id: i32,
}
}
#[derive(Debug, thiserror::Error)]