open_lark/service/cloud_docs/sheets/v3/float_image/
get.rs1use reqwest::Method;
2use serde::{Deserialize, Serialize};
3
4use crate::{
5 core::{
6 api_req::ApiRequest,
7 api_resp::{ApiResponseTrait, BaseResponse, ResponseFormat},
8 constants::AccessTokenType,
9 endpoints::cloud_docs::*,
10 http::Transport,
11 req_option::RequestOption,
12 SDKResult,
13 },
14 impl_executable_builder_owned,
15 service::sheets::v3::SpreadsheetSheetService,
16};
17
18use super::create::FloatImageData;
19
20impl SpreadsheetSheetService {
21 pub async fn get_float_image(
23 &self,
24 request: GetFloatImageRequest,
25 option: Option<RequestOption>,
26 ) -> SDKResult<BaseResponse<GetFloatImageResponseData>> {
27 let mut api_req = request.api_request;
28 api_req.http_method = Method::GET;
29 api_req.api_path = SHEETS_V3_SPREADSHEET_FLOAT_IMAGE_GET
30 .replace("{}", &request.spreadsheet_token)
31 .replace("{}", &request.sheet_id)
32 .replace("{}", &request.float_image_id);
33 api_req.supported_access_token_types = vec![AccessTokenType::Tenant, AccessTokenType::User];
34
35 let api_resp = Transport::request(api_req, &self.config, option).await?;
36
37 Ok(api_resp)
38 }
39}
40
41#[derive(Default, Debug, Serialize, Deserialize)]
43pub struct GetFloatImageRequest {
44 #[serde(skip)]
45 api_request: ApiRequest,
46 spreadsheet_token: String,
48 sheet_id: String,
50 float_image_id: String,
52}
53
54impl GetFloatImageRequest {
55 pub fn builder() -> GetFloatImageRequestBuilder {
56 GetFloatImageRequestBuilder::default()
57 }
58}
59
60#[derive(Default)]
61pub struct GetFloatImageRequestBuilder {
62 request: GetFloatImageRequest,
63}
64
65impl GetFloatImageRequestBuilder {
66 pub fn spreadsheet_token(mut self, spreadsheet_token: impl ToString) -> Self {
67 self.request.spreadsheet_token = spreadsheet_token.to_string();
68 self
69 }
70
71 pub fn sheet_id(mut self, sheet_id: impl ToString) -> Self {
72 self.request.sheet_id = sheet_id.to_string();
73 self
74 }
75
76 pub fn float_image_id(mut self, float_image_id: impl ToString) -> Self {
77 self.request.float_image_id = float_image_id.to_string();
78 self
79 }
80
81 pub fn build(mut self) -> GetFloatImageRequest {
82 self.request.api_request.body = serde_json::to_vec(&self.request).unwrap();
83 self.request
84 }
85}
86
87impl_executable_builder_owned!(
88 GetFloatImageRequestBuilder,
89 SpreadsheetSheetService,
90 GetFloatImageRequest,
91 BaseResponse<GetFloatImageResponseData>,
92 get_float_image
93);
94
95#[derive(Deserialize, Debug)]
97pub struct GetFloatImageResponseData {
98 #[serde(flatten)]
100 pub float_image: FloatImageInfo,
101}
102
103#[derive(Deserialize, Debug)]
105pub struct FloatImageInfo {
106 pub float_image_id: String,
108 #[serde(flatten)]
110 pub float_image: FloatImageData,
111}
112
113impl ApiResponseTrait for GetFloatImageResponseData {
114 fn data_format() -> ResponseFormat {
115 ResponseFormat::Data
116 }
117}
118
119#[cfg(test)]
120#[allow(unused_variables, unused_unsafe)]
121mod test {
122 use super::*;
123 use serde_json::json;
124
125 #[test]
126 fn test_get_float_image_response() {
127 let json = json!({
128 "float_image_id": "fimg_001",
129 "image_token": "img_token_123",
130 "position": {
131 "start_col_index": 1,
132 "start_row_index": 1,
133 "offset_x": 10.0,
134 "offset_y": 20.0
135 },
136 "size": {
137 "width": 200.0,
138 "height": 150.0
139 },
140 "name": "示例图片"
141 });
142
143 let response: GetFloatImageResponseData = serde_json::from_value(json).unwrap();
144 assert_eq!(response.float_image.float_image_id, "fimg_001");
145 assert_eq!(
146 response.float_image.float_image.image_token,
147 "img_token_123"
148 );
149 }
150}