From c9a14a6b08f5f565a14bfee6313000aa92a5bfa6 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Wed, 18 Nov 2020 06:58:23 -0500 Subject: [PATCH] fix switchcounter bindings --- backend/src/web/switchcounter.rs | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/backend/src/web/switchcounter.rs b/backend/src/web/switchcounter.rs index 2b9e970..cdd6e7b 100644 --- a/backend/src/web/switchcounter.rs +++ b/backend/src/web/switchcounter.rs @@ -47,13 +47,22 @@ impl Client { #[instrument(err, skip(self))] pub fn status(&self) -> Result { - let resp = - ureq::post(&self.webhook_url).send_json(serde_json::to_value(FrontAsk::default())?); + #[derive(Serialize, Debug)] + struct Wrapper { + pub webhook: FrontAsk, + } + + let resp = ureq::post(&self.webhook_url).send_json(serde_json::to_value(Wrapper { + webhook: FrontAsk::default(), + })?); if resp.ok() { Ok(resp.into_json_deserialize()?) } else { Err(match resp.synthetic_error() { - Some(why) => Error::UReq(why.to_string()), + Some(why) => { + error!("ureq error: {}", why); + Error::UReq(why.to_string()) + } None => Error::HttpStatus(resp.status()), }) } @@ -61,9 +70,16 @@ impl Client { #[instrument(err, skip(self))] pub fn switch(&self, member_name: String) -> Result { - let resp = ureq::post(&self.webhook_url).send_json(serde_json::to_value(SwitchCommand { - command: "switch".to_string(), - member_name: member_name, + #[derive(Serialize, Debug)] + struct Wrapper { + pub webhook: SwitchCommand, + } + + let resp = ureq::post(&self.webhook_url).send_json(serde_json::to_value(Wrapper { + webhook: SwitchCommand { + command: "switch".to_string(), + member_name: member_name, + }, })?); if resp.ok() {