pub struct Client { /* private fields */ }Expand description
Low-level client for interacting with the Toggl API.
Implementations§
Source§impl Client
impl Client
Sourcepub fn new(token: String) -> Result<Self, Error>
pub fn new(token: String) -> Result<Self, Error>
Creates a new client with the given API token.
Examples found in repository?
examples/api.rs (line 7)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6 let token = env::var("TOGGL_API_TOKEN").expect("missing TOGGL_API_TOKEN environment variable");
7 let client = api::Client::new(token)?;
8 let workspaces = client.get_workspaces()?;
9
10 if Confirm::new().with_prompt("Print workspaces?").interact()? {
11 println!("{workspaces:#?}");
12 }
13
14 for w in workspaces {
15 let projects = client.get_projects(&w.id)?;
16 let projects: Vec<_> = projects.iter().filter(|p| p.active).collect();
17
18 if Confirm::new()
19 .with_prompt("Print active projects?")
20 .interact()?
21 {
22 println!("{projects:#?}");
23 }
24
25 let time_entries = client.get_time_entries(None)?;
26
27 if Confirm::new()
28 .with_prompt("Print recent time entries?")
29 .interact()?
30 {
31 println!("{time_entries:#?}");
32 }
33 }
34
35 Ok(())
36}Sourcepub fn get_time_entries(
&self,
start_end_dates: Option<(NaiveDate, NaiveDate)>,
) -> Result<Vec<TimeEntry>, Error>
pub fn get_time_entries( &self, start_end_dates: Option<(NaiveDate, NaiveDate)>, ) -> Result<Vec<TimeEntry>, Error>
Examples found in repository?
examples/api.rs (line 25)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6 let token = env::var("TOGGL_API_TOKEN").expect("missing TOGGL_API_TOKEN environment variable");
7 let client = api::Client::new(token)?;
8 let workspaces = client.get_workspaces()?;
9
10 if Confirm::new().with_prompt("Print workspaces?").interact()? {
11 println!("{workspaces:#?}");
12 }
13
14 for w in workspaces {
15 let projects = client.get_projects(&w.id)?;
16 let projects: Vec<_> = projects.iter().filter(|p| p.active).collect();
17
18 if Confirm::new()
19 .with_prompt("Print active projects?")
20 .interact()?
21 {
22 println!("{projects:#?}");
23 }
24
25 let time_entries = client.get_time_entries(None)?;
26
27 if Confirm::new()
28 .with_prompt("Print recent time entries?")
29 .interact()?
30 {
31 println!("{time_entries:#?}");
32 }
33 }
34
35 Ok(())
36}pub fn get_current_entry(&self) -> Result<Option<TimeEntry>, Error>
pub fn create_time_entry(&self, entry: NewTimeEntry) -> Result<TimeEntry, Error>
pub fn stop_time_entry( &self, workspace_id: &Number, time_entry_id: &Number, ) -> Result<TimeEntry, Error>
Sourcepub fn get_projects(&self, workspace_id: &Number) -> Result<Vec<Project>, Error>
pub fn get_projects(&self, workspace_id: &Number) -> Result<Vec<Project>, Error>
Examples found in repository?
examples/api.rs (line 15)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6 let token = env::var("TOGGL_API_TOKEN").expect("missing TOGGL_API_TOKEN environment variable");
7 let client = api::Client::new(token)?;
8 let workspaces = client.get_workspaces()?;
9
10 if Confirm::new().with_prompt("Print workspaces?").interact()? {
11 println!("{workspaces:#?}");
12 }
13
14 for w in workspaces {
15 let projects = client.get_projects(&w.id)?;
16 let projects: Vec<_> = projects.iter().filter(|p| p.active).collect();
17
18 if Confirm::new()
19 .with_prompt("Print active projects?")
20 .interact()?
21 {
22 println!("{projects:#?}");
23 }
24
25 let time_entries = client.get_time_entries(None)?;
26
27 if Confirm::new()
28 .with_prompt("Print recent time entries?")
29 .interact()?
30 {
31 println!("{time_entries:#?}");
32 }
33 }
34
35 Ok(())
36}Sourcepub fn get_workspaces(&self) -> Result<Vec<Workspace>, Error>
pub fn get_workspaces(&self) -> Result<Vec<Workspace>, Error>
Examples found in repository?
examples/api.rs (line 8)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6 let token = env::var("TOGGL_API_TOKEN").expect("missing TOGGL_API_TOKEN environment variable");
7 let client = api::Client::new(token)?;
8 let workspaces = client.get_workspaces()?;
9
10 if Confirm::new().with_prompt("Print workspaces?").interact()? {
11 println!("{workspaces:#?}");
12 }
13
14 for w in workspaces {
15 let projects = client.get_projects(&w.id)?;
16 let projects: Vec<_> = projects.iter().filter(|p| p.active).collect();
17
18 if Confirm::new()
19 .with_prompt("Print active projects?")
20 .interact()?
21 {
22 println!("{projects:#?}");
23 }
24
25 let time_entries = client.get_time_entries(None)?;
26
27 if Confirm::new()
28 .with_prompt("Print recent time entries?")
29 .interact()?
30 {
31 println!("{time_entries:#?}");
32 }
33 }
34
35 Ok(())
36}Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more