use serde_json::json;
use crate::api::client::{ApiError, GitHub};
use crate::api::model::NodeId;
use crate::api::raw;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct NewStatus {
pub emoji: Option<String>,
pub message: String,
pub busy: bool,
pub expires_at: Option<String>,
}
impl GitHub {
pub async fn follow(&self, id: &NodeId, org: bool, on: bool) -> Result<(), ApiError> {
let query = match (org, on) {
(false, true) => raw::FOLLOW_USER,
(false, false) => raw::UNFOLLOW_USER,
(true, true) => raw::FOLLOW_ORG,
(true, false) => raw::UNFOLLOW_ORG,
};
self.mutate_json(query, json!({ "id": id })).await
}
pub async fn set_status(&self, status: Option<&NewStatus>) -> Result<(), ApiError> {
let vars = match status {
Some(s) => json!({
"emoji": s.emoji,
"message": s.message,
"busy": s.busy,
"expires": s.expires_at,
}),
None => json!({ "emoji": null, "message": null, "busy": false, "expires": null }),
};
self.mutate_json(raw::CHANGE_STATUS, vars).await
}
}