spatio_sdk/apis/
logos_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 GetDomainLogoError {
22 Status401(models::ApiError),
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum GetEmailLogoError {
30 Status401(models::ApiError),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum GetLogosBatchError {
38 Status401(models::ApiError),
39 UnknownValue(serde_json::Value),
40}
41
42
43pub async fn get_domain_logo(configuration: &configuration::Configuration, domain: &str) -> Result<models::GetDomainLogo200Response, Error<GetDomainLogoError>> {
44 let p_path_domain = domain;
46
47 let uri_str = format!("{}/v1/logos/domain/{domain}", configuration.base_path, domain=crate::apis::urlencode(p_path_domain));
48 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
49
50 if let Some(ref user_agent) = configuration.user_agent {
51 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
52 }
53 if let Some(ref token) = configuration.bearer_access_token {
54 req_builder = req_builder.bearer_auth(token.to_owned());
55 };
56
57 let req = req_builder.build()?;
58 let resp = configuration.client.execute(req).await?;
59
60 let status = resp.status();
61 let content_type = resp
62 .headers()
63 .get("content-type")
64 .and_then(|v| v.to_str().ok())
65 .unwrap_or("application/octet-stream");
66 let content_type = super::ContentType::from(content_type);
67
68 if !status.is_client_error() && !status.is_server_error() {
69 let content = resp.text().await?;
70 match content_type {
71 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
72 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetDomainLogo200Response`"))),
73 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::GetDomainLogo200Response`")))),
74 }
75 } else {
76 let content = resp.text().await?;
77 let entity: Option<GetDomainLogoError> = serde_json::from_str(&content).ok();
78 Err(Error::ResponseError(ResponseContent { status, content, entity }))
79 }
80}
81
82pub async fn get_email_logo(configuration: &configuration::Configuration, email: &str) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<GetEmailLogoError>> {
83 let p_path_email = email;
85
86 let uri_str = format!("{}/v1/logos/email/{email}", configuration.base_path, email=crate::apis::urlencode(p_path_email));
87 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
88
89 if let Some(ref user_agent) = configuration.user_agent {
90 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
91 }
92 if let Some(ref token) = configuration.bearer_access_token {
93 req_builder = req_builder.bearer_auth(token.to_owned());
94 };
95
96 let req = req_builder.build()?;
97 let resp = configuration.client.execute(req).await?;
98
99 let status = resp.status();
100 let content_type = resp
101 .headers()
102 .get("content-type")
103 .and_then(|v| v.to_str().ok())
104 .unwrap_or("application/octet-stream");
105 let content_type = super::ContentType::from(content_type);
106
107 if !status.is_client_error() && !status.is_server_error() {
108 let content = resp.text().await?;
109 match content_type {
110 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
111 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`"))),
112 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`")))),
113 }
114 } else {
115 let content = resp.text().await?;
116 let entity: Option<GetEmailLogoError> = serde_json::from_str(&content).ok();
117 Err(Error::ResponseError(ResponseContent { status, content, entity }))
118 }
119}
120
121pub async fn get_logos_batch(configuration: &configuration::Configuration, request_body: std::collections::HashMap<String, serde_json::Value>) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<GetLogosBatchError>> {
122 let p_body_request_body = request_body;
124
125 let uri_str = format!("{}/v1/logos/batch", configuration.base_path);
126 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
127
128 if let Some(ref user_agent) = configuration.user_agent {
129 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
130 }
131 if let Some(ref token) = configuration.bearer_access_token {
132 req_builder = req_builder.bearer_auth(token.to_owned());
133 };
134 req_builder = req_builder.json(&p_body_request_body);
135
136 let req = req_builder.build()?;
137 let resp = configuration.client.execute(req).await?;
138
139 let status = resp.status();
140 let content_type = resp
141 .headers()
142 .get("content-type")
143 .and_then(|v| v.to_str().ok())
144 .unwrap_or("application/octet-stream");
145 let content_type = super::ContentType::from(content_type);
146
147 if !status.is_client_error() && !status.is_server_error() {
148 let content = resp.text().await?;
149 match content_type {
150 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
151 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`"))),
152 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`")))),
153 }
154 } else {
155 let content = resp.text().await?;
156 let entity: Option<GetLogosBatchError> = serde_json::from_str(&content).ok();
157 Err(Error::ResponseError(ResponseContent { status, content, entity }))
158 }
159}
160