From 3765d4f2edc5933f61fd46ab130e366774556cf5 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 18 Apr 2020 04:24:26 -0400 Subject: implement remove --- src/api.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/api.rs') diff --git a/src/api.rs b/src/api.rs index 9588b4c..f40ff6d 100644 --- a/src/api.rs +++ b/src/api.rs @@ -159,6 +159,7 @@ struct SyncResCipher { impl SyncResCipher { fn to_entry(&self) -> crate::db::Entry { crate::db::Entry { + id: self.id.clone(), name: self.name.clone(), username: self.login.username.clone(), password: self.login.password.clone(), @@ -310,6 +311,24 @@ impl Client { } } + pub fn remove(&self, access_token: &str, id: &str) -> Result<()> { + let client = reqwest::blocking::Client::new(); + let res = client + .delete(&self.api_url(&format!("/ciphers/{}", id))) + .header("Authorization", format!("Bearer {}", access_token)) + .send() + .context(crate::error::Reqwest)?; + match res.status() { + reqwest::StatusCode::OK => Ok(()), + reqwest::StatusCode::UNAUTHORIZED => { + Err(Error::RequestUnauthorized) + } + _ => Err(Error::RequestFailed { + status: res.status().as_u16(), + }), + } + } + pub fn exchange_refresh_token( &self, refresh_token: &str, -- cgit v1.2.3-54-g00ecf