figma_api/apis/
component_sets_api.rs1use 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 GetComponentSetError {
22 Status400(models::InlineObject16),
23 Status403(models::InlineObject19),
24 Status404(models::InlineObject22),
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 GetFileComponentSetsError {
34 Status400(models::InlineObject16),
35 Status403(models::InlineObject19),
36 Status404(models::InlineObject22),
37 Status429(models::InlineObject23),
38 Status500(models::InlineObject25),
39 UnknownValue(serde_json::Value),
40}
41
42
43pub async fn get_component_set(configuration: &configuration::Configuration, key: &str) -> Result<models::InlineObject9, Error<GetComponentSetError>> {
45 let p_key = key;
47
48 let uri_str = format!("{}/v1/component_sets/{key}", configuration.base_path, key=crate::apis::urlencode(p_key));
49 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
50
51 if let Some(ref user_agent) = configuration.user_agent {
52 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
53 }
54 if let Some(ref token) = configuration.oauth_access_token {
55 req_builder = req_builder.bearer_auth(token.to_owned());
56 };
57 if let Some(ref apikey) = configuration.api_key {
58 let key = apikey.key.clone();
59 let value = match apikey.prefix {
60 Some(ref prefix) => format!("{} {}", prefix, key),
61 None => key,
62 };
63 req_builder = req_builder.header("X-Figma-Token", value);
64 };
65
66 let req = req_builder.build()?;
67 let resp = configuration.client.execute(req).await?;
68
69 let status = resp.status();
70 let content_type = resp
71 .headers()
72 .get("content-type")
73 .and_then(|v| v.to_str().ok())
74 .unwrap_or("application/octet-stream");
75 let content_type = super::ContentType::from(content_type);
76
77 if !status.is_client_error() && !status.is_server_error() {
78 let content = resp.text().await?;
79 match content_type {
80 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
81 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::InlineObject9`"))),
82 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::InlineObject9`")))),
83 }
84 } else {
85 let content = resp.text().await?;
86 let entity: Option<GetComponentSetError> = serde_json::from_str(&content).ok();
87 Err(Error::ResponseError(ResponseContent { status, content, entity }))
88 }
89}
90
91pub async fn get_file_component_sets(configuration: &configuration::Configuration, file_key: &str) -> Result<models::InlineObject8, Error<GetFileComponentSetsError>> {
93 let p_file_key = file_key;
95
96 let uri_str = format!("{}/v1/files/{file_key}/component_sets", configuration.base_path, file_key=crate::apis::urlencode(p_file_key));
97 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
98
99 if let Some(ref user_agent) = configuration.user_agent {
100 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
101 }
102 if let Some(ref token) = configuration.oauth_access_token {
103 req_builder = req_builder.bearer_auth(token.to_owned());
104 };
105 if let Some(ref apikey) = configuration.api_key {
106 let key = apikey.key.clone();
107 let value = match apikey.prefix {
108 Some(ref prefix) => format!("{} {}", prefix, key),
109 None => key,
110 };
111 req_builder = req_builder.header("X-Figma-Token", value);
112 };
113
114 let req = req_builder.build()?;
115 let resp = configuration.client.execute(req).await?;
116
117 let status = resp.status();
118 let content_type = resp
119 .headers()
120 .get("content-type")
121 .and_then(|v| v.to_str().ok())
122 .unwrap_or("application/octet-stream");
123 let content_type = super::ContentType::from(content_type);
124
125 if !status.is_client_error() && !status.is_server_error() {
126 let content = resp.text().await?;
127 match content_type {
128 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
129 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::InlineObject8`"))),
130 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::InlineObject8`")))),
131 }
132 } else {
133 let content = resp.text().await?;
134 let entity: Option<GetFileComponentSetsError> = serde_json::from_str(&content).ok();
135 Err(Error::ResponseError(ResponseContent { status, content, entity }))
136 }
137}
138