diff options
author | Jesse Luehrs <doy@tozt.net> | 2020-04-19 23:00:47 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2020-04-19 23:00:47 -0400 |
commit | 6f10a47adc2fb42ffc965b954b9285123a82c094 (patch) | |
tree | 725b2b8cce4fe6e7c0b51f96d3d65a43928d1f2f /src/actions.rs | |
parent | 7a32c43713514c02f783d3c8e0835229e7f59a83 (diff) | |
download | rbw-6f10a47adc2fb42ffc965b954b9285123a82c094.tar.gz rbw-6f10a47adc2fb42ffc965b954b9285123a82c094.zip |
implement adding into a folder
Diffstat (limited to 'src/actions.rs')
-rw-r--r-- | src/actions.rs | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/src/actions.rs b/src/actions.rs index f0d5d21..67a9523 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -78,9 +78,18 @@ pub fn add( password: Option<&str>, notes: Option<&str>, uris: &[String], + folder_id: Option<&str>, ) -> Result<(Option<String>, ())> { with_exchange_refresh_token(access_token, refresh_token, |access_token| { - add_once(access_token, name, username, password, notes, uris) + add_once( + access_token, + name, + username, + password, + notes, + uris, + folder_id, + ) }) } @@ -91,11 +100,20 @@ fn add_once( password: Option<&str>, notes: Option<&str>, uris: &[String], + folder_id: Option<&str>, ) -> Result<()> { let config = crate::config::Config::load()?; let client = crate::api::Client::new(&config.base_url(), &config.identity_url()); - client.add(access_token, name, username, password, notes, uris)?; + client.add( + access_token, + name, + username, + password, + notes, + uris, + folder_id.as_deref(), + )?; Ok(()) } @@ -156,6 +174,39 @@ fn remove_once(access_token: &str, id: &str) -> Result<()> { Ok(()) } +pub fn list_folders( + access_token: &str, + refresh_token: &str, +) -> Result<(Option<String>, Vec<(String, String)>)> { + with_exchange_refresh_token(access_token, refresh_token, |access_token| { + list_folders_once(access_token) + }) +} + +fn list_folders_once(access_token: &str) -> Result<Vec<(String, String)>> { + let config = crate::config::Config::load()?; + let client = + crate::api::Client::new(&config.base_url(), &config.identity_url()); + client.folders(access_token) +} + +pub fn create_folder( + access_token: &str, + refresh_token: &str, + name: &str, +) -> Result<(Option<String>, String)> { + with_exchange_refresh_token(access_token, refresh_token, |access_token| { + create_folder_once(access_token, name) + }) +} + +fn create_folder_once(access_token: &str, name: &str) -> Result<String> { + let config = crate::config::Config::load()?; + let client = + crate::api::Client::new(&config.base_url(), &config.identity_url()); + client.create_folder(access_token, name) +} + fn with_exchange_refresh_token<F, T>( access_token: &str, refresh_token: &str, |