Skip to main content

hanzo_client/apis/
notify_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 [`get_notify_health`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetNotifyHealthError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`post_notify_send`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum PostNotifySendError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`post_notify_send_email`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum PostNotifySendEmailError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`post_notify_send_sms`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum PostNotifySendSmsError {
43    UnknownValue(serde_json::Value),
44}
45
46
47/// Reports that the notify send surface is mounted.  It is a pure liveness probe: it answers 200 whenever this subsystem is mounted and checks nothing downstream, so an \"ok\" here says the routes are reachable, not that any provider credential is configured. The body is notifyd's verbatim, so probes and clients that keyed on the standalone service keep working unchanged.
48pub async fn get_notify_health(configuration: &configuration::Configuration, ) -> Result<models::NotifyHealth, Error<GetNotifyHealthError>> {
49
50    let uri_str = format!("{}/v1/notify/health", configuration.base_path);
51    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
52
53    if let Some(ref user_agent) = configuration.user_agent {
54        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
55    }
56    if let Some(ref token) = configuration.bearer_access_token {
57        req_builder = req_builder.bearer_auth(token.to_owned());
58    };
59
60    let req = req_builder.build()?;
61    let resp = configuration.client.execute(req).await?;
62
63    let status = resp.status();
64    let content_type = resp
65        .headers()
66        .get("content-type")
67        .and_then(|v| v.to_str().ok())
68        .unwrap_or("application/octet-stream");
69    let content_type = super::ContentType::from(content_type);
70
71    if !status.is_client_error() && !status.is_server_error() {
72        let content = resp.text().await?;
73        match content_type {
74            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
75            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::NotifyHealth`"))),
76            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::NotifyHealth`")))),
77        }
78    } else {
79        let content = resp.text().await?;
80        let entity: Option<GetNotifyHealthError> = serde_json::from_str(&content).ok();
81        Err(Error::ResponseError(ResponseContent { status, content, entity }))
82    }
83}
84
85/// Delivers one transactional message by email or SMS through the caller org's own provider credential.  The channel comes from the body — sms or email — and the provider credential is read from KMS at orgs/<org>/notify/<service>/<key>, never from the environment. The org is the validated principal's, never a client-supplied value, so a caller can only ever send as their own tenant; an unauthenticated caller gets 401. Naming no provider picks the one whose credentials are actually configured (Twilio, then Plivo for SMS; Twilio Email, then SMTP for email) and fails closed when none is. Delivery is synchronous and per recipient: one recipient answers the bare {message_id,status} outcome, several answer the {items:[…]} envelope. A terminal provider failure is a 200 whose status is failed with the reason in error, never a transport error. sync=true is REQUIRED — an async dispatch answers 503, because the queue plane that would run it is owned elsewhere. The message body wins verbatim when present; otherwise template_id (or the event name) selects a built-in template rendered against template_vars.
86pub async fn post_notify_send(configuration: &configuration::Configuration, notify_send: models::NotifySend) -> Result<serde_json::Value, Error<PostNotifySendError>> {
87    // add a prefix to parameters to efficiently prevent name collisions
88    let p_notify_send = notify_send;
89
90    let uri_str = format!("{}/v1/notify/send", configuration.base_path);
91    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
92
93    if let Some(ref user_agent) = configuration.user_agent {
94        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
95    }
96    if let Some(ref token) = configuration.bearer_access_token {
97        req_builder = req_builder.bearer_auth(token.to_owned());
98    };
99    req_builder = req_builder.json(&p_notify_send);
100
101    let req = req_builder.build()?;
102    let resp = configuration.client.execute(req).await?;
103
104    let status = resp.status();
105    let content_type = resp
106        .headers()
107        .get("content-type")
108        .and_then(|v| v.to_str().ok())
109        .unwrap_or("application/octet-stream");
110    let content_type = super::ContentType::from(content_type);
111
112    if !status.is_client_error() && !status.is_server_error() {
113        let content = resp.text().await?;
114        match content_type {
115            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
116            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `serde_json::Value`"))),
117            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`")))),
118        }
119    } else {
120        let content = resp.text().await?;
121        let entity: Option<PostNotifySendError> = serde_json::from_str(&content).ok();
122        Err(Error::ResponseError(ResponseContent { status, content, entity }))
123    }
124}
125
126/// Delivers one transactional email through the caller org's own provider credential.  It is the channel-pinned form of the generic send: identical in every respect except that the channel is fixed to email, OVERRIDING whatever the body names — so a body that says sms still goes out as mail. The provider is the org's own email credential from KMS (Twilio Email, then SMTP), resolved for the validated principal's org; an unauthenticated caller gets 401. Subject is carried on the email channel only.
127pub async fn post_notify_send_email(configuration: &configuration::Configuration, notify_send: models::NotifySend) -> Result<serde_json::Value, Error<PostNotifySendEmailError>> {
128    // add a prefix to parameters to efficiently prevent name collisions
129    let p_notify_send = notify_send;
130
131    let uri_str = format!("{}/v1/notify/send/email", configuration.base_path);
132    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
133
134    if let Some(ref user_agent) = configuration.user_agent {
135        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
136    }
137    if let Some(ref token) = configuration.bearer_access_token {
138        req_builder = req_builder.bearer_auth(token.to_owned());
139    };
140    req_builder = req_builder.json(&p_notify_send);
141
142    let req = req_builder.build()?;
143    let resp = configuration.client.execute(req).await?;
144
145    let status = resp.status();
146    let content_type = resp
147        .headers()
148        .get("content-type")
149        .and_then(|v| v.to_str().ok())
150        .unwrap_or("application/octet-stream");
151    let content_type = super::ContentType::from(content_type);
152
153    if !status.is_client_error() && !status.is_server_error() {
154        let content = resp.text().await?;
155        match content_type {
156            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
157            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `serde_json::Value`"))),
158            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`")))),
159        }
160    } else {
161        let content = resp.text().await?;
162        let entity: Option<PostNotifySendEmailError> = serde_json::from_str(&content).ok();
163        Err(Error::ResponseError(ResponseContent { status, content, entity }))
164    }
165}
166
167/// Delivers one transactional SMS through the caller org's own provider credential.  It is the channel-pinned form of the generic send: identical in every respect except that the channel is fixed to sms, OVERRIDING whatever the body names — so a body that says email still goes out as a text message. The provider is the org's own SMS credential from KMS (Twilio, then Plivo), resolved for the validated principal's org; an unauthenticated caller gets 401.
168pub async fn post_notify_send_sms(configuration: &configuration::Configuration, notify_send: models::NotifySend) -> Result<serde_json::Value, Error<PostNotifySendSmsError>> {
169    // add a prefix to parameters to efficiently prevent name collisions
170    let p_notify_send = notify_send;
171
172    let uri_str = format!("{}/v1/notify/send/sms", configuration.base_path);
173    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
174
175    if let Some(ref user_agent) = configuration.user_agent {
176        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
177    }
178    if let Some(ref token) = configuration.bearer_access_token {
179        req_builder = req_builder.bearer_auth(token.to_owned());
180    };
181    req_builder = req_builder.json(&p_notify_send);
182
183    let req = req_builder.build()?;
184    let resp = configuration.client.execute(req).await?;
185
186    let status = resp.status();
187    let content_type = resp
188        .headers()
189        .get("content-type")
190        .and_then(|v| v.to_str().ok())
191        .unwrap_or("application/octet-stream");
192    let content_type = super::ContentType::from(content_type);
193
194    if !status.is_client_error() && !status.is_server_error() {
195        let content = resp.text().await?;
196        match content_type {
197            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
198            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `serde_json::Value`"))),
199            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`")))),
200        }
201    } else {
202        let content = resp.text().await?;
203        let entity: Option<PostNotifySendSmsError> = serde_json::from_str(&content).ok();
204        Err(Error::ResponseError(ResponseContent { status, content, entity }))
205    }
206}
207