Skip to main content

openlark_platform/spark/v1/app/
patch.rs

1//! 更新妙搭应用信息
2//!
3//! docPath:
4
5use openlark_core::{
6    SDKResult, api::ApiRequest, config::Config, http::Transport, req_option::RequestOption,
7    validate_required,
8};
9use std::sync::Arc;
10
11/// 更新妙搭应用信息请求。
12#[derive(Debug, Clone)]
13pub struct PatchSparkAppRequest {
14    config: Arc<Config>,
15    app_id: String,
16}
17
18impl PatchSparkAppRequest {
19    /// 创建新的请求构建器。
20    pub fn new(config: Arc<Config>, app_id: impl Into<String>) -> Self {
21        Self {
22            config,
23            app_id: app_id.into(),
24        }
25    }
26
27    /// 使用默认请求选项执行请求。
28    pub async fn execute(self, body: serde_json::Value) -> SDKResult<serde_json::Value> {
29        self.execute_with_options(body, RequestOption::default())
30            .await
31    }
32
33    /// 使用指定请求选项执行请求。
34    pub async fn execute_with_options(
35        self,
36        body: serde_json::Value,
37        option: RequestOption,
38    ) -> SDKResult<serde_json::Value> {
39        validate_required!(self.app_id.trim(), "app_id 不能为空");
40        let path = format!("/open-apis/spark/v1/apps/{}", self.app_id);
41        let req = ApiRequest::<serde_json::Value>::patch(path).body(body);
42        let resp = Transport::request(req, &self.config, Some(option)).await?;
43        resp.data.ok_or_else(|| {
44            openlark_core::error::validation_error("更新妙搭应用信息", "响应数据为空")
45        })
46    }
47}