diff options
Diffstat (limited to 'cli/src/api')
-rw-r--r-- | cli/src/api/client.rs | 6 | ||||
-rw-r--r-- | cli/src/api/connection.rs | 8 |
2 files changed, 14 insertions, 0 deletions
diff --git a/cli/src/api/client.rs b/cli/src/api/client.rs index c77063b..df0ca96 100644 --- a/cli/src/api/client.rs +++ b/cli/src/api/client.rs @@ -28,6 +28,12 @@ impl Client { Ok(conn.get("clients")?) } + pub fn update(conn: Connection, client_id: u32, data: &str) -> Result<(), Box<dyn Error>> { + let resp = conn.patch(&format!("clients?id=eq.{}", client_id), data)?; + println!("{}", resp); + Ok(()) + } + pub fn save(&self, conn: Connection) -> Result<(), Box<dyn Error>> { // By default the `id` of a newly created client will be 0, // which will cause the API to add the client with id=0. This works once 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()?) + } } |