use serde::Deserialize;
use crate::client::LinearClient;
use crate::error::Result;
use crate::ids::{OrganizationId, UserId};
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct Viewer {
pub id: UserId,
pub name: String,
pub display_name: String,
pub email: String,
pub active: bool,
pub admin: bool,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct Organization {
pub id: OrganizationId,
pub name: String,
pub url_key: String,
}
const VIEWER: &str = "query Viewer { viewer { id name displayName email active admin } }";
const ORGANIZATION: &str = "query Organization { organization { id name urlKey } }";
pub(crate) const DOCUMENTS: &[(&str, &str)] = &[("Viewer", VIEWER), ("Organization", ORGANIZATION)];
impl LinearClient {
pub async fn viewer(&self) -> Result<Viewer> {
#[derive(Deserialize)]
struct Data {
viewer: Viewer,
}
Ok(self
.query::<_, Data>("Viewer", VIEWER, serde_json::json!({}))
.await?
.viewer)
}
pub async fn organization(&self) -> Result<Organization> {
#[derive(Deserialize)]
struct Data {
organization: Organization,
}
Ok(self
.query::<_, Data>("Organization", ORGANIZATION, serde_json::json!({}))
.await?
.organization)
}
}