traq/apis/
activity_api.rs

1/*
2 * traQ v3
3 *
4 * traQ v3 API
5 *
6 * The version of the OpenAPI document: 3.0
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use reqwest;
12
13use super::{configuration, Error};
14use crate::apis::ResponseContent;
15
16/// struct for typed errors of method [`get_activity_timeline`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum GetActivityTimelineError {
20    Status400(),
21    UnknownValue(serde_json::Value),
22}
23
24/// struct for typed errors of method [`get_online_users`]
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum GetOnlineUsersError {
28    UnknownValue(serde_json::Value),
29}
30
31/// パブリックチャンネルの直近の投稿メッセージを作成日時の降順で取得します。 `all`が`true`でない場合、購読チャンネルのみのタイムラインを取得します
32pub async fn get_activity_timeline(
33    configuration: &configuration::Configuration,
34    limit: Option<i32>,
35    all: Option<bool>,
36    per_channel: Option<bool>,
37) -> Result<Vec<crate::models::ActivityTimelineMessage>, Error<GetActivityTimelineError>> {
38    let local_var_configuration = configuration;
39
40    let local_var_client = &local_var_configuration.client;
41
42    let local_var_uri_str = format!("{}/activity/timeline", local_var_configuration.base_path);
43    let mut local_var_req_builder =
44        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
45
46    if let Some(ref local_var_str) = limit {
47        local_var_req_builder =
48            local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
49    }
50    if let Some(ref local_var_str) = all {
51        local_var_req_builder = local_var_req_builder.query(&[("all", &local_var_str.to_string())]);
52    }
53    if let Some(ref local_var_str) = per_channel {
54        local_var_req_builder =
55            local_var_req_builder.query(&[("per_channel", &local_var_str.to_string())]);
56    }
57    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
58        local_var_req_builder =
59            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
60    }
61    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
62        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
63    };
64    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
65        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
66    };
67
68    let local_var_req = local_var_req_builder.build()?;
69    let local_var_resp = local_var_client.execute(local_var_req).await?;
70
71    let local_var_status = local_var_resp.status();
72    let local_var_content = local_var_resp.text().await?;
73
74    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
75        serde_json::from_str(&local_var_content).map_err(Error::from)
76    } else {
77        let local_var_entity: Option<GetActivityTimelineError> =
78            serde_json::from_str(&local_var_content).ok();
79        let local_var_error = ResponseContent {
80            status: local_var_status,
81            content: local_var_content,
82            entity: local_var_entity,
83        };
84        Err(Error::ResponseError(local_var_error))
85    }
86}
87
88/// 現在オンラインな(SSEまたはWSが接続中)ユーザーのUUIDのリストを返します。
89pub async fn get_online_users(
90    configuration: &configuration::Configuration,
91) -> Result<Vec<String>, Error<GetOnlineUsersError>> {
92    let local_var_configuration = configuration;
93
94    let local_var_client = &local_var_configuration.client;
95
96    let local_var_uri_str = format!("{}/activity/onlines", local_var_configuration.base_path);
97    let mut local_var_req_builder =
98        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
99
100    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
101        local_var_req_builder =
102            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
103    }
104    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
105        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
106    };
107    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
108        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
109    };
110
111    let local_var_req = local_var_req_builder.build()?;
112    let local_var_resp = local_var_client.execute(local_var_req).await?;
113
114    let local_var_status = local_var_resp.status();
115    let local_var_content = local_var_resp.text().await?;
116
117    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
118        serde_json::from_str(&local_var_content).map_err(Error::from)
119    } else {
120        let local_var_entity: Option<GetOnlineUsersError> =
121            serde_json::from_str(&local_var_content).ok();
122        let local_var_error = ResponseContent {
123            status: local_var_status,
124            content: local_var_content,
125            entity: local_var_entity,
126        };
127        Err(Error::ResponseError(local_var_error))
128    }
129}