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 DeleteAdCampaignsByIdError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetAdCampaignsError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetAdCampaignsByIdError {
36 UnknownValue(serde_json::Value),
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetAdSummaryError {
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum PostAdCampaignsError {
50 UnknownValue(serde_json::Value),
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum PostAdCampaignsByIdLaunchError {
57 UnknownValue(serde_json::Value),
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum PutAdCampaignsByIdError {
64 UnknownValue(serde_json::Value),
65}
66
67
68pub async fn delete_ad_campaigns_by_id(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteAdCampaignsByIdError>> {
70 let p_id = id;
72
73 let uri_str = format!("{}/v1/ad/campaigns/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
74 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
75
76 if let Some(ref user_agent) = configuration.user_agent {
77 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
78 }
79 if let Some(ref token) = configuration.bearer_access_token {
80 req_builder = req_builder.bearer_auth(token.to_owned());
81 };
82
83 let req = req_builder.build()?;
84 let resp = configuration.client.execute(req).await?;
85
86 let status = resp.status();
87
88 if !status.is_client_error() && !status.is_server_error() {
89 Ok(())
90 } else {
91 let content = resp.text().await?;
92 let entity: Option<DeleteAdCampaignsByIdError> = serde_json::from_str(&content).ok();
93 Err(Error::ResponseError(ResponseContent { status, content, entity }))
94 }
95}
96
97pub async fn get_ad_campaigns(configuration: &configuration::Configuration, status: Option<&str>, limit: Option<i32>) -> Result<models::CampaignList, Error<GetAdCampaignsError>> {
99 let p_status = status;
101 let p_limit = limit;
102
103 let uri_str = format!("{}/v1/ad/campaigns", configuration.base_path);
104 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
105
106 if let Some(ref param_value) = p_status {
107 req_builder = req_builder.query(&[("status", ¶m_value.to_string())]);
108 }
109 if let Some(ref param_value) = p_limit {
110 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
111 }
112 if let Some(ref user_agent) = configuration.user_agent {
113 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
114 }
115 if let Some(ref token) = configuration.bearer_access_token {
116 req_builder = req_builder.bearer_auth(token.to_owned());
117 };
118
119 let req = req_builder.build()?;
120 let resp = configuration.client.execute(req).await?;
121
122 let status = resp.status();
123 let content_type = resp
124 .headers()
125 .get("content-type")
126 .and_then(|v| v.to_str().ok())
127 .unwrap_or("application/octet-stream");
128 let content_type = super::ContentType::from(content_type);
129
130 if !status.is_client_error() && !status.is_server_error() {
131 let content = resp.text().await?;
132 match content_type {
133 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
134 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CampaignList`"))),
135 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::CampaignList`")))),
136 }
137 } else {
138 let content = resp.text().await?;
139 let entity: Option<GetAdCampaignsError> = serde_json::from_str(&content).ok();
140 Err(Error::ResponseError(ResponseContent { status, content, entity }))
141 }
142}
143
144pub async fn get_ad_campaigns_by_id(configuration: &configuration::Configuration, id: &str) -> Result<models::AdCampaign, Error<GetAdCampaignsByIdError>> {
146 let p_id = id;
148
149 let uri_str = format!("{}/v1/ad/campaigns/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
150 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
151
152 if let Some(ref user_agent) = configuration.user_agent {
153 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
154 }
155 if let Some(ref token) = configuration.bearer_access_token {
156 req_builder = req_builder.bearer_auth(token.to_owned());
157 };
158
159 let req = req_builder.build()?;
160 let resp = configuration.client.execute(req).await?;
161
162 let status = resp.status();
163 let content_type = resp
164 .headers()
165 .get("content-type")
166 .and_then(|v| v.to_str().ok())
167 .unwrap_or("application/octet-stream");
168 let content_type = super::ContentType::from(content_type);
169
170 if !status.is_client_error() && !status.is_server_error() {
171 let content = resp.text().await?;
172 match content_type {
173 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
174 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AdCampaign`"))),
175 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::AdCampaign`")))),
176 }
177 } else {
178 let content = resp.text().await?;
179 let entity: Option<GetAdCampaignsByIdError> = serde_json::from_str(&content).ok();
180 Err(Error::ResponseError(ResponseContent { status, content, entity }))
181 }
182}
183
184pub async fn get_ad_summary(configuration: &configuration::Configuration, ) -> Result<models::AdSummary, Error<GetAdSummaryError>> {
186
187 let uri_str = format!("{}/v1/ad/summary", configuration.base_path);
188 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
189
190 if let Some(ref user_agent) = configuration.user_agent {
191 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
192 }
193 if let Some(ref token) = configuration.bearer_access_token {
194 req_builder = req_builder.bearer_auth(token.to_owned());
195 };
196
197 let req = req_builder.build()?;
198 let resp = configuration.client.execute(req).await?;
199
200 let status = resp.status();
201 let content_type = resp
202 .headers()
203 .get("content-type")
204 .and_then(|v| v.to_str().ok())
205 .unwrap_or("application/octet-stream");
206 let content_type = super::ContentType::from(content_type);
207
208 if !status.is_client_error() && !status.is_server_error() {
209 let content = resp.text().await?;
210 match content_type {
211 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
212 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AdSummary`"))),
213 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::AdSummary`")))),
214 }
215 } else {
216 let content = resp.text().await?;
217 let entity: Option<GetAdSummaryError> = serde_json::from_str(&content).ok();
218 Err(Error::ResponseError(ResponseContent { status, content, entity }))
219 }
220}
221
222pub async fn post_ad_campaigns(configuration: &configuration::Configuration, campaign_input: models::CampaignInput) -> Result<models::AdCampaign, Error<PostAdCampaignsError>> {
224 let p_campaign_input = campaign_input;
226
227 let uri_str = format!("{}/v1/ad/campaigns", configuration.base_path);
228 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
229
230 if let Some(ref user_agent) = configuration.user_agent {
231 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
232 }
233 if let Some(ref token) = configuration.bearer_access_token {
234 req_builder = req_builder.bearer_auth(token.to_owned());
235 };
236 req_builder = req_builder.json(&p_campaign_input);
237
238 let req = req_builder.build()?;
239 let resp = configuration.client.execute(req).await?;
240
241 let status = resp.status();
242 let content_type = resp
243 .headers()
244 .get("content-type")
245 .and_then(|v| v.to_str().ok())
246 .unwrap_or("application/octet-stream");
247 let content_type = super::ContentType::from(content_type);
248
249 if !status.is_client_error() && !status.is_server_error() {
250 let content = resp.text().await?;
251 match content_type {
252 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
253 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AdCampaign`"))),
254 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::AdCampaign`")))),
255 }
256 } else {
257 let content = resp.text().await?;
258 let entity: Option<PostAdCampaignsError> = serde_json::from_str(&content).ok();
259 Err(Error::ResponseError(ResponseContent { status, content, entity }))
260 }
261}
262
263pub async fn post_ad_campaigns_by_id_launch(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<PostAdCampaignsByIdLaunchError>> {
265 let p_id = id;
267
268 let uri_str = format!("{}/v1/ad/campaigns/{id}/launch", configuration.base_path, id=crate::apis::urlencode(p_id));
269 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
270
271 if let Some(ref user_agent) = configuration.user_agent {
272 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
273 }
274 if let Some(ref token) = configuration.bearer_access_token {
275 req_builder = req_builder.bearer_auth(token.to_owned());
276 };
277
278 let req = req_builder.build()?;
279 let resp = configuration.client.execute(req).await?;
280
281 let status = resp.status();
282
283 if !status.is_client_error() && !status.is_server_error() {
284 Ok(())
285 } else {
286 let content = resp.text().await?;
287 let entity: Option<PostAdCampaignsByIdLaunchError> = serde_json::from_str(&content).ok();
288 Err(Error::ResponseError(ResponseContent { status, content, entity }))
289 }
290}
291
292pub async fn put_ad_campaigns_by_id(configuration: &configuration::Configuration, id: &str, update_campaign_in: models::UpdateCampaignIn) -> Result<models::AdCampaign, Error<PutAdCampaignsByIdError>> {
294 let p_id = id;
296 let p_update_campaign_in = update_campaign_in;
297
298 let uri_str = format!("{}/v1/ad/campaigns/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
299 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
300
301 if let Some(ref user_agent) = configuration.user_agent {
302 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
303 }
304 if let Some(ref token) = configuration.bearer_access_token {
305 req_builder = req_builder.bearer_auth(token.to_owned());
306 };
307 req_builder = req_builder.json(&p_update_campaign_in);
308
309 let req = req_builder.build()?;
310 let resp = configuration.client.execute(req).await?;
311
312 let status = resp.status();
313 let content_type = resp
314 .headers()
315 .get("content-type")
316 .and_then(|v| v.to_str().ok())
317 .unwrap_or("application/octet-stream");
318 let content_type = super::ContentType::from(content_type);
319
320 if !status.is_client_error() && !status.is_server_error() {
321 let content = resp.text().await?;
322 match content_type {
323 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
324 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AdCampaign`"))),
325 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::AdCampaign`")))),
326 }
327 } else {
328 let content = resp.text().await?;
329 let entity: Option<PutAdCampaignsByIdError> = serde_json::from_str(&content).ok();
330 Err(Error::ResponseError(ResponseContent { status, content, entity }))
331 }
332}
333