1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetFileError {
22 Status400(models::InlineObject16),
23 Status403(models::InlineObject19),
24 Status404(models::InlineObject21),
25 Status429(models::InlineObject23),
26 Status500(models::InlineObject25),
27 UnknownValue(serde_json::Value),
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
32#[serde(untagged)]
33pub enum GetFileMetaError {
34 Status400(models::InlineObject16),
35 Status403(models::InlineObject19),
36 Status404(models::InlineObject21),
37 Status429(models::InlineObject23),
38 Status500(models::InlineObject25),
39 UnknownValue(serde_json::Value),
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum GetFileNodesError {
46 Status400(models::InlineObject16),
47 Status403(models::InlineObject19),
48 Status404(models::InlineObject21),
49 Status429(models::InlineObject23),
50 Status500(models::InlineObject25),
51 UnknownValue(serde_json::Value),
52}
53
54#[derive(Debug, Clone, Serialize, Deserialize)]
56#[serde(untagged)]
57pub enum GetImageFillsError {
58 Status400(models::InlineObject16),
59 Status403(models::InlineObject19),
60 Status404(models::InlineObject21),
61 Status429(models::InlineObject23),
62 Status500(models::InlineObject25),
63 UnknownValue(serde_json::Value),
64}
65
66#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum GetImagesError {
70 Status400(models::InlineObject16),
71 Status403(models::InlineObject19),
72 Status404(models::InlineObject21),
73 Status429(models::InlineObject23),
74 Status500(models::InlineObject25),
75 UnknownValue(serde_json::Value),
76}
77
78
79pub async fn get_file(configuration: &configuration::Configuration, file_key: &str, version: Option<&str>, ids: Option<&str>, depth: Option<f64>, geometry: Option<&str>, plugin_data: Option<&str>, branch_data: Option<bool>) -> Result<models::InlineObject, Error<GetFileError>> {
81 let p_file_key = file_key;
83 let p_version = version;
84 let p_ids = ids;
85 let p_depth = depth;
86 let p_geometry = geometry;
87 let p_plugin_data = plugin_data;
88 let p_branch_data = branch_data;
89
90 let uri_str = format!("{}/v1/files/{file_key}", configuration.base_path, file_key=crate::apis::urlencode(p_file_key));
91 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
92
93 if let Some(ref param_value) = p_version {
94 req_builder = req_builder.query(&[("version", ¶m_value.to_string())]);
95 }
96 if let Some(ref param_value) = p_ids {
97 req_builder = req_builder.query(&[("ids", ¶m_value.to_string())]);
98 }
99 if let Some(ref param_value) = p_depth {
100 req_builder = req_builder.query(&[("depth", ¶m_value.to_string())]);
101 }
102 if let Some(ref param_value) = p_geometry {
103 req_builder = req_builder.query(&[("geometry", ¶m_value.to_string())]);
104 }
105 if let Some(ref param_value) = p_plugin_data {
106 req_builder = req_builder.query(&[("plugin_data", ¶m_value.to_string())]);
107 }
108 if let Some(ref param_value) = p_branch_data {
109 req_builder = req_builder.query(&[("branch_data", ¶m_value.to_string())]);
110 }
111 if let Some(ref user_agent) = configuration.user_agent {
112 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
113 }
114 if let Some(ref token) = configuration.oauth_access_token {
115 req_builder = req_builder.bearer_auth(token.to_owned());
116 };
117 if let Some(ref apikey) = configuration.api_key {
118 let key = apikey.key.clone();
119 let value = match apikey.prefix {
120 Some(ref prefix) => format!("{} {}", prefix, key),
121 None => key,
122 };
123 req_builder = req_builder.header("X-Figma-Token", value);
124 };
125
126 let req = req_builder.build()?;
127 let resp = configuration.client.execute(req).await?;
128
129 let status = resp.status();
130 let content_type = resp
131 .headers()
132 .get("content-type")
133 .and_then(|v| v.to_str().ok())
134 .unwrap_or("application/octet-stream");
135 let content_type = super::ContentType::from(content_type);
136
137 if !status.is_client_error() && !status.is_server_error() {
138 let content = resp.text().await?;
139 match content_type {
140 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
141 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::InlineObject`"))),
142 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::InlineObject`")))),
143 }
144 } else {
145 let content = resp.text().await?;
146 let entity: Option<GetFileError> = serde_json::from_str(&content).ok();
147 Err(Error::ResponseError(ResponseContent { status, content, entity }))
148 }
149}
150
151pub async fn get_file_meta(configuration: &configuration::Configuration, file_key: &str) -> Result<models::InlineObject4, Error<GetFileMetaError>> {
153 let p_file_key = file_key;
155
156 let uri_str = format!("{}/v1/files/{file_key}/meta", configuration.base_path, file_key=crate::apis::urlencode(p_file_key));
157 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
158
159 if let Some(ref user_agent) = configuration.user_agent {
160 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
161 }
162 if let Some(ref token) = configuration.oauth_access_token {
163 req_builder = req_builder.bearer_auth(token.to_owned());
164 };
165 if let Some(ref apikey) = configuration.api_key {
166 let key = apikey.key.clone();
167 let value = match apikey.prefix {
168 Some(ref prefix) => format!("{} {}", prefix, key),
169 None => key,
170 };
171 req_builder = req_builder.header("X-Figma-Token", value);
172 };
173
174 let req = req_builder.build()?;
175 let resp = configuration.client.execute(req).await?;
176
177 let status = resp.status();
178 let content_type = resp
179 .headers()
180 .get("content-type")
181 .and_then(|v| v.to_str().ok())
182 .unwrap_or("application/octet-stream");
183 let content_type = super::ContentType::from(content_type);
184
185 if !status.is_client_error() && !status.is_server_error() {
186 let content = resp.text().await?;
187 match content_type {
188 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
189 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::InlineObject4`"))),
190 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::InlineObject4`")))),
191 }
192 } else {
193 let content = resp.text().await?;
194 let entity: Option<GetFileMetaError> = serde_json::from_str(&content).ok();
195 Err(Error::ResponseError(ResponseContent { status, content, entity }))
196 }
197}
198
199pub async fn get_file_nodes(configuration: &configuration::Configuration, file_key: &str, ids: &str, version: Option<&str>, depth: Option<f64>, geometry: Option<&str>, plugin_data: Option<&str>) -> Result<models::InlineObject1, Error<GetFileNodesError>> {
201 let p_file_key = file_key;
203 let p_ids = ids;
204 let p_version = version;
205 let p_depth = depth;
206 let p_geometry = geometry;
207 let p_plugin_data = plugin_data;
208
209 let uri_str = format!("{}/v1/files/{file_key}/nodes", configuration.base_path, file_key=crate::apis::urlencode(p_file_key));
210 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
211
212 req_builder = req_builder.query(&[("ids", &p_ids.to_string())]);
213 if let Some(ref param_value) = p_version {
214 req_builder = req_builder.query(&[("version", ¶m_value.to_string())]);
215 }
216 if let Some(ref param_value) = p_depth {
217 req_builder = req_builder.query(&[("depth", ¶m_value.to_string())]);
218 }
219 if let Some(ref param_value) = p_geometry {
220 req_builder = req_builder.query(&[("geometry", ¶m_value.to_string())]);
221 }
222 if let Some(ref param_value) = p_plugin_data {
223 req_builder = req_builder.query(&[("plugin_data", ¶m_value.to_string())]);
224 }
225 if let Some(ref user_agent) = configuration.user_agent {
226 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
227 }
228 if let Some(ref token) = configuration.oauth_access_token {
229 req_builder = req_builder.bearer_auth(token.to_owned());
230 };
231 if let Some(ref apikey) = configuration.api_key {
232 let key = apikey.key.clone();
233 let value = match apikey.prefix {
234 Some(ref prefix) => format!("{} {}", prefix, key),
235 None => key,
236 };
237 req_builder = req_builder.header("X-Figma-Token", value);
238 };
239
240 let req = req_builder.build()?;
241 let resp = configuration.client.execute(req).await?;
242
243 let status = resp.status();
244 let content_type = resp
245 .headers()
246 .get("content-type")
247 .and_then(|v| v.to_str().ok())
248 .unwrap_or("application/octet-stream");
249 let content_type = super::ContentType::from(content_type);
250
251 if !status.is_client_error() && !status.is_server_error() {
252 let content = resp.text().await?;
253 match content_type {
254 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
255 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::InlineObject1`"))),
256 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::InlineObject1`")))),
257 }
258 } else {
259 let content = resp.text().await?;
260 let entity: Option<GetFileNodesError> = serde_json::from_str(&content).ok();
261 Err(Error::ResponseError(ResponseContent { status, content, entity }))
262 }
263}
264
265pub async fn get_image_fills(configuration: &configuration::Configuration, file_key: &str) -> Result<models::InlineObject3, Error<GetImageFillsError>> {
267 let p_file_key = file_key;
269
270 let uri_str = format!("{}/v1/files/{file_key}/images", configuration.base_path, file_key=crate::apis::urlencode(p_file_key));
271 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
272
273 if let Some(ref user_agent) = configuration.user_agent {
274 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
275 }
276 if let Some(ref token) = configuration.oauth_access_token {
277 req_builder = req_builder.bearer_auth(token.to_owned());
278 };
279 if let Some(ref apikey) = configuration.api_key {
280 let key = apikey.key.clone();
281 let value = match apikey.prefix {
282 Some(ref prefix) => format!("{} {}", prefix, key),
283 None => key,
284 };
285 req_builder = req_builder.header("X-Figma-Token", value);
286 };
287
288 let req = req_builder.build()?;
289 let resp = configuration.client.execute(req).await?;
290
291 let status = resp.status();
292 let content_type = resp
293 .headers()
294 .get("content-type")
295 .and_then(|v| v.to_str().ok())
296 .unwrap_or("application/octet-stream");
297 let content_type = super::ContentType::from(content_type);
298
299 if !status.is_client_error() && !status.is_server_error() {
300 let content = resp.text().await?;
301 match content_type {
302 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
303 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::InlineObject3`"))),
304 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::InlineObject3`")))),
305 }
306 } else {
307 let content = resp.text().await?;
308 let entity: Option<GetImageFillsError> = serde_json::from_str(&content).ok();
309 Err(Error::ResponseError(ResponseContent { status, content, entity }))
310 }
311}
312
313pub async fn get_images(configuration: &configuration::Configuration, file_key: &str, ids: &str, version: Option<&str>, scale: Option<f64>, format: Option<&str>, svg_outline_text: Option<bool>, svg_include_id: Option<bool>, svg_include_node_id: Option<bool>, svg_simplify_stroke: Option<bool>, contents_only: Option<bool>, use_absolute_bounds: Option<bool>) -> Result<models::InlineObject2, Error<GetImagesError>> {
315 let p_file_key = file_key;
317 let p_ids = ids;
318 let p_version = version;
319 let p_scale = scale;
320 let p_format = format;
321 let p_svg_outline_text = svg_outline_text;
322 let p_svg_include_id = svg_include_id;
323 let p_svg_include_node_id = svg_include_node_id;
324 let p_svg_simplify_stroke = svg_simplify_stroke;
325 let p_contents_only = contents_only;
326 let p_use_absolute_bounds = use_absolute_bounds;
327
328 let uri_str = format!("{}/v1/images/{file_key}", configuration.base_path, file_key=crate::apis::urlencode(p_file_key));
329 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
330
331 req_builder = req_builder.query(&[("ids", &p_ids.to_string())]);
332 if let Some(ref param_value) = p_version {
333 req_builder = req_builder.query(&[("version", ¶m_value.to_string())]);
334 }
335 if let Some(ref param_value) = p_scale {
336 req_builder = req_builder.query(&[("scale", ¶m_value.to_string())]);
337 }
338 if let Some(ref param_value) = p_format {
339 req_builder = req_builder.query(&[("format", ¶m_value.to_string())]);
340 }
341 if let Some(ref param_value) = p_svg_outline_text {
342 req_builder = req_builder.query(&[("svg_outline_text", ¶m_value.to_string())]);
343 }
344 if let Some(ref param_value) = p_svg_include_id {
345 req_builder = req_builder.query(&[("svg_include_id", ¶m_value.to_string())]);
346 }
347 if let Some(ref param_value) = p_svg_include_node_id {
348 req_builder = req_builder.query(&[("svg_include_node_id", ¶m_value.to_string())]);
349 }
350 if let Some(ref param_value) = p_svg_simplify_stroke {
351 req_builder = req_builder.query(&[("svg_simplify_stroke", ¶m_value.to_string())]);
352 }
353 if let Some(ref param_value) = p_contents_only {
354 req_builder = req_builder.query(&[("contents_only", ¶m_value.to_string())]);
355 }
356 if let Some(ref param_value) = p_use_absolute_bounds {
357 req_builder = req_builder.query(&[("use_absolute_bounds", ¶m_value.to_string())]);
358 }
359 if let Some(ref user_agent) = configuration.user_agent {
360 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
361 }
362 if let Some(ref token) = configuration.oauth_access_token {
363 req_builder = req_builder.bearer_auth(token.to_owned());
364 };
365 if let Some(ref apikey) = configuration.api_key {
366 let key = apikey.key.clone();
367 let value = match apikey.prefix {
368 Some(ref prefix) => format!("{} {}", prefix, key),
369 None => key,
370 };
371 req_builder = req_builder.header("X-Figma-Token", value);
372 };
373
374 let req = req_builder.build()?;
375 let resp = configuration.client.execute(req).await?;
376
377 let status = resp.status();
378 let content_type = resp
379 .headers()
380 .get("content-type")
381 .and_then(|v| v.to_str().ok())
382 .unwrap_or("application/octet-stream");
383 let content_type = super::ContentType::from(content_type);
384
385 if !status.is_client_error() && !status.is_server_error() {
386 let content = resp.text().await?;
387 match content_type {
388 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
389 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::InlineObject2`"))),
390 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::InlineObject2`")))),
391 }
392 } else {
393 let content = resp.text().await?;
394 let entity: Option<GetImagesError> = serde_json::from_str(&content).ok();
395 Err(Error::ResponseError(ResponseContent { status, content, entity }))
396 }
397}
398