C27SOF4VNFMM4X6V4FD5UBTBR7KEJEGC3X2ZYZDC7H6USIFOQZMQC }impl Toggl {pub fn new(cred: Credentials) -> Result<Self, ()> {let http = http::HttpClient::new(cred)?;Ok(Toggl { http })}pub async fn all_data(&self, since: Option<Timestamp>) -> Result<(Data, Timestamp), ()> {#[derive(Serialize)]struct Params {since: Option<Timestamp>,with_related_data: bool,}#[derive(Deserialize)]struct DataResponse {since: Timestamp,data: Data,}let params = Params {since,with_related_data: true,};let r = self.http.get("me", ¶ms).await?;let t = r.text().await.unwrap();println!("{}", &t);let o: DataResponse = serde_json::from_str(&t).unwrap();Ok((o.data, o.since))}pub async fn user_info(&self, since: Option<Timestamp>) -> Result<(UserInfo, Timestamp), ()> {#[derive(Serialize)]struct Params {since: Option<Timestamp>,with_related_data: bool,}#[derive(Deserialize)]struct UserInfoResponse {pub since: Timestamp,pub data: UserInfo,}let params = Params {since,with_related_data: false,};let r = self.http.get("me", ¶ms).await?;let t = r.text().await.unwrap();let o: UserInfoResponse = serde_json::from_str(&t).unwrap();Ok((o.data, o.since))}pub async fn projects_of_workspace(&self,workspace_id: &impl Borrow<WorkspaceId>,) -> Result<Vec<Project>, ()> {let workspace_id = workspace_id.borrow();let r = self.http.get(&format!("workspaces/{}/projects", workspace_id), &()).await?;let t = r.text().await.unwrap();let o = serde_json::from_str(&t).unwrap();Ok(o)}pub async fn time_entries(&self,start: DateTime<Utc>,end: DateTime<Utc>,) -> Result<Vec<TimeEntry>, ()> {let r = self.http.get("time_entries", &[("start_date", start), ("end_date", end)]).await?;let t = r.text().await.unwrap();let o = serde_json::from_str(&t).unwrap();Ok(o)}
use std::borrow::Borrow;use chrono::{DateTime, Utc};use serde::{Deserialize, Serialize};#[derive(Debug, Serialize, Deserialize)]pub struct UserInfo {id: u32,pub email: String,pub fullname: String,pub workspaces: Vec<Workspace>,}#[derive(Debug, Serialize, Deserialize)]pub struct Data {#[serde(default)]pub workspaces: Vec<Workspace>,#[serde(default)]pub time_entries: Vec<TimeEntry>,#[serde(default)]pub projects: Vec<Project>,}#[derive(Serialize, Deserialize)]pub struct Workspace {pub id: WorkspaceId,pub name: String,pub api_token: Option<String>,}impl std::fmt::Debug for Workspace {fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {f.debug_struct("Workspace").field("id", &self.id).field("name", &self.name).finish()}}impl Borrow<WorkspaceId> for Workspace {fn borrow(&self) -> &WorkspaceId {&self.id}}#[repr(transparent)]#[derive(Debug, Serialize, Deserialize)]#[serde(transparent)]pub struct WorkspaceId(u32);impl std::fmt::Display for WorkspaceId {fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {self.0.fmt(f)}}#[derive(Debug, Serialize, Deserialize)]pub struct Project {id: ProjectId,name: String,}impl Borrow<ProjectId> for Project {fn borrow(&self) -> &ProjectId {&self.id}}#[repr(transparent)]#[derive(Debug, Serialize, Deserialize)]#[serde(transparent)]pub struct ProjectId(u32);#[derive(Debug, Serialize, Deserialize)]pub struct TimeEntry {id: TimeEntryId,description: String,wid: WorkspaceId,pid: Option<ProjectId>,start: DateTime<Utc>,stop: Option<DateTime<Utc>>,server_deleted_at: Option<DateTime<Utc>>,}impl Borrow<TimeEntryId> for TimeEntry {fn borrow(&self) -> &TimeEntryId {&self.id}}#[repr(transparent)]#[derive(Debug, Serialize, Deserialize)]#[serde(transparent)]pub struct TimeEntryId(u32);
name = "num-integer"version = "0.1.44"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"dependencies = ["autocfg","num-traits",][[package]]name = "num-traits"version = "0.2.14"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"dependencies = ["autocfg",][[package]]