use reqwest::StatusCode;
use super::client::DexcomClient;
impl DexcomClient {
pub(crate) fn post(
&self,
endpoint: &str,
json: serde_json::Value,
params: Vec<(&str, &str)>,
) -> Result<reqwest::blocking::Response, Box<dyn std::error::Error>> {
let resp = self.reqwest_client
.post(format!("{}/{}", self.base_url, endpoint))
.header("Accept-Encoding", "application/json")
.json(&json)
.query(¶ms)
.send();
match resp {
Ok(r) => {
if r.status() != StatusCode::OK {
println!("Error: {:?}", r.text().unwrap());
return Err("server-side dexcom error".into());
}
Ok(r)
},
Err(e) => Err(Box::new(e)),
}
}
}