1use serde::Deserialize;
5
6use crate::client::LinearClient;
7use crate::error::Result;
8use crate::ids::{OrganizationId, UserId};
9
10#[derive(Debug, Clone, Deserialize)]
12#[serde(rename_all = "camelCase")]
13#[non_exhaustive]
14pub struct Viewer {
15 pub id: UserId,
17 pub name: String,
19 pub display_name: String,
21 pub email: String,
23 pub active: bool,
25 pub admin: bool,
27}
28
29#[derive(Debug, Clone, Deserialize)]
31#[serde(rename_all = "camelCase")]
32#[non_exhaustive]
33pub struct Organization {
34 pub id: OrganizationId,
36 pub name: String,
38 pub url_key: String,
40}
41
42const VIEWER: &str = "query Viewer { viewer { id name displayName email active admin } }";
43const ORGANIZATION: &str = "query Organization { organization { id name urlKey } }";
44
45pub(crate) const DOCUMENTS: &[(&str, &str)] = &[("Viewer", VIEWER), ("Organization", ORGANIZATION)];
46
47impl LinearClient {
48 pub async fn viewer(&self) -> Result<Viewer> {
50 #[derive(Deserialize)]
51 struct Data {
52 viewer: Viewer,
53 }
54 Ok(self
55 .query::<_, Data>("Viewer", VIEWER, serde_json::json!({}))
56 .await?
57 .viewer)
58 }
59
60 pub async fn organization(&self) -> Result<Organization> {
62 #[derive(Deserialize)]
63 struct Data {
64 organization: Organization,
65 }
66 Ok(self
67 .query::<_, Data>("Organization", ORGANIZATION, serde_json::json!({}))
68 .await?
69 .organization)
70 }
71}