diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2024-04-25 17:41:52 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2024-04-25 17:41:52 +0200 |
commit | 975c0b735be0808883116616d934ee257a24fb08 (patch) | |
tree | d71dd46bb034674978cb204964f1cfa13dd5d5f1 /cli/src/api/connection.rs | |
parent | b7ff847c3c44df876fcc21e946ffff1eb781a4d9 (diff) | |
download | faktura-975c0b735be0808883116616d934ee257a24fb08.tar.gz faktura-975c0b735be0808883116616d934ee257a24fb08.tar.bz2 faktura-975c0b735be0808883116616d934ee257a24fb08.zip |
cli: Add command to edit clients.
Not entirely happy with this one. Specially the patch method of the
Connection struct. While the other method take (or return) an object
that can be serialized to json, the patch method takes a string slice
directly, and passing it to the API.
Diffstat (limited to 'cli/src/api/connection.rs')
-rw-r--r-- | cli/src/api/connection.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/cli/src/api/connection.rs b/cli/src/api/connection.rs index f1d7f1c..5505afb 100644 --- a/cli/src/api/connection.rs +++ b/cli/src/api/connection.rs @@ -33,4 +33,12 @@ impl Connection { .send_json(&data)? .into_string()?) } + + pub fn patch(&self, resource: &str, data: &str) -> Result<String, Box<dyn Error>> { + Ok(ureq::patch(&format!("{}/{}", &self.url, resource)) + .set("Authorization", &format!("Bearer {}", self.jwt_token)) + .set("Content-Type", "application/json") + .send_string(&data)? + .into_string()?) + } } |