use openlark_core::{
api::{ApiRequest, ApiResponseTrait, ResponseFormat},
config::Config,
http::Transport,
req_option::RequestOption,
SDKResult,
};
use serde::{Deserialize, Serialize};
use std::sync::Arc;
#[derive(Debug, Clone)]
pub struct ApproveDeviceRequest {
config: Arc<Config>,
device_id: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ApproveDeviceResponse {
pub data: Option<serde_json::Value>,
}
impl ApiResponseTrait for ApproveDeviceResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
impl ApproveDeviceRequest {
pub fn new(config: Arc<Config>, device_id: impl Into<String>) -> Self {
Self {
config,
device_id: device_id.into(),
}
}
pub async fn execute(self) -> SDKResult<ApproveDeviceResponse> {
self.execute_with_options(RequestOption::default()).await
}
pub async fn execute_with_options(
self,
option: RequestOption,
) -> SDKResult<ApproveDeviceResponse> {
let path = format!("/open-apis/acs/v1/devices/{}/approve", self.device_id);
let req: ApiRequest<ApproveDeviceResponse> = ApiRequest::post(&path);
let _resp: openlark_core::api::Response<ApproveDeviceResponse> =
Transport::request(req, &self.config, Some(option)).await?;
Ok(ApproveDeviceResponse { data: None })
}
}
#[cfg(test)]
mod tests {
use super::*;
use serde_json;
#[test]
fn test_serialization_roundtrip() {
let json = r#"{"test": "value"}"#;
assert!(serde_json::from_str::<serde_json::Value>(json).is_ok());
}
#[test]
fn test_deserialization_from_json() {
let json = r#"{"field": "data"}"#;
let value: serde_json::Value = serde_json::from_str(json).expect("JSON 反序列化失败");
assert_eq!(value["field"], "data");
}
}