pub mod error;
pub use error::Error;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
pub struct Response {
online: bool,
}
impl Response {
pub fn build(online: bool) -> Self {
Self { online }
}
pub fn from_json(json: &str) -> Result<Self, Error> {
match serde_json::from_str::<Response>(json) {
Ok(data) => Ok(Self {
online: data.online,
}),
Err(e) => Err(Error::Json(e)),
}
}
pub fn to_json(&self) -> Result<String, Error> {
match serde_json::to_string(&self) {
Ok(json) => Ok(json),
Err(e) => Err(Error::Json(e)),
}
}
pub fn online(&self) -> bool {
self.online
}
}