Skip to main content

hanzo_client/apis/
ad_api.rs

1/*
2 * Hanzo Cloud API
3 *
4 * The Hanzo Cloud API as a customer calls it: every operation under /v1/ except the operator's admin product, relay routes, legacy spellings and capabilities still reached by flag. Tagged by product: the first path segment after /v1/.
5 *
6 * The version of the OpenAPI document: v1
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`delete_ad_campaigns_by_id`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DeleteAdCampaignsByIdError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`get_ad_campaigns`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetAdCampaignsError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`get_ad_campaigns_by_id`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetAdCampaignsByIdError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`get_ad_summary`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetAdSummaryError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`post_ad_campaigns`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum PostAdCampaignsError {
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`post_ad_campaigns_by_id_launch`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum PostAdCampaignsByIdLaunchError {
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method [`put_ad_campaigns_by_id`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum PutAdCampaignsByIdError {
64    UnknownValue(serde_json::Value),
65}
66
67
68/// Removes one of the caller org's campaigns and answers 204 with no body. It deletes the stored record only: a campaign already launched keeps running on the ad network, which must be stopped there. An id another org owns reads as not found.
69pub async fn delete_ad_campaigns_by_id(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteAdCampaignsByIdError>> {
70    // add a prefix to parameters to efficiently prevent name collisions
71    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
97/// Returns the caller org's ad campaigns, most recently updated first, optionally narrowed to one lifecycle status. The listing is bounded by the org: another tenant's campaigns are not reachable from here at all.
98pub async fn get_ad_campaigns(configuration: &configuration::Configuration, status: Option<&str>, limit: Option<i32>) -> Result<models::CampaignList, Error<GetAdCampaignsError>> {
99    // add a prefix to parameters to efficiently prevent name collisions
100    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", &param_value.to_string())]);
108    }
109    if let Some(ref param_value) = p_limit {
110        req_builder = req_builder.query(&[("limit", &param_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
144/// Returns one of the caller org's campaigns. An id another org owns reads as not found, so the response cannot confirm that it exists.
145pub async fn get_ad_campaigns_by_id(configuration: &configuration::Configuration, id: &str) -> Result<models::AdCampaign, Error<GetAdCampaignsByIdError>> {
146    // add a prefix to parameters to efficiently prevent name collisions
147    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
184/// Rolls the caller org's ad campaigns up into four numbers: how many campaigns exist, how many are active, and the summed budget and spend across all of them. Budget and spend are MINOR units (cents), the same units the campaign rows carry. It counts only this org's campaigns.
185pub 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
222/// Registers a new ad campaign for the caller's org and answers 201 with the stored row. It only records the campaign — nothing is sent to the ad network until POST /v1/ad/campaigns/{id}/launch runs it. The org is stamped by the server from the validated principal, so a body can never place a campaign in another tenant.
223pub async fn post_ad_campaigns(configuration: &configuration::Configuration, campaign_input: models::CampaignInput) -> Result<models::AdCampaign, Error<PostAdCampaignsError>> {
224    // add a prefix to parameters to efficiently prevent name collisions
225    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
263/// Creates the campaign on its platform under the CALLER ORG'S own connected ad account, records the provider campaign id, flips the stored campaign to active and answers the updated record. No ad-network token is held here: it is resolved from KMS through the org's connector at launch time, BEFORE any provider call, so an org that has not connected that platform gets 424 and no spend can ever start on a connection the org did not make. Meta is executed for real; a campaign on a platform whose provider is not wired yet answers 501 even when the connector is connected, and an edge failure at the platform is 502. The optional {account} body overrides the target ad account for this launch and is TOLERANT — a malformed or non-JSON body is ignored and the campaign launches on its stored account rather than being refused. A campaign id another org owns reads as not found.
264pub async fn post_ad_campaigns_by_id_launch(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<PostAdCampaignsByIdLaunchError>> {
265    // add a prefix to parameters to efficiently prevent name collisions
266    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
292/// Replaces the user-owned fields of one of the caller org's campaigns and answers the stored row. It is a full replace, not a patch: every field is written from the request, so an omitted one is cleared. externalId is launch-owned and is never touched here, so editing a campaign cannot break its link to a live provider execution.
293pub async fn put_ad_campaigns_by_id(configuration: &configuration::Configuration, id: &str, update_campaign_in: models::UpdateCampaignIn) -> Result<models::AdCampaign, Error<PutAdCampaignsByIdError>> {
294    // add a prefix to parameters to efficiently prevent name collisions
295    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