Skip to main content

hanzo_client/apis/
tel_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_tel_calls_by_id`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DeleteTelCallsByIdError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`delete_tel_numbers_by_id`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum DeleteTelNumbersByIdError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`get_tel_calls`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetTelCallsError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`get_tel_messages`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetTelMessagesError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`get_tel_numbers`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum GetTelNumbersError {
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`get_tel_numbers_available`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum GetTelNumbersAvailableError {
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method [`get_tel_summary`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum GetTelSummaryError {
64    UnknownValue(serde_json::Value),
65}
66
67/// struct for typed errors of method [`post_tel_calls`]
68#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum PostTelCallsError {
71    UnknownValue(serde_json::Value),
72}
73
74/// struct for typed errors of method [`post_tel_messages`]
75#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum PostTelMessagesError {
78    UnknownValue(serde_json::Value),
79}
80
81/// struct for typed errors of method [`post_tel_numbers`]
82#[derive(Debug, Clone, Serialize, Deserialize)]
83#[serde(untagged)]
84pub enum PostTelNumbersError {
85    UnknownValue(serde_json::Value),
86}
87
88
89/// Ends a call this org placed. The holding is read for THIS org before the carrier is asked, for the reason releaseNumber gives one surface up: an id belonging to another tenant would otherwise be hung up by whoever guessed it.
90pub async fn delete_tel_calls_by_id(configuration: &configuration::Configuration, id: &str) -> Result<serde_json::Value, Error<DeleteTelCallsByIdError>> {
91    // add a prefix to parameters to efficiently prevent name collisions
92    let p_id = id;
93
94    let uri_str = format!("{}/v1/tel/calls/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
95    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
96
97    if let Some(ref user_agent) = configuration.user_agent {
98        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
99    }
100    if let Some(ref token) = configuration.bearer_access_token {
101        req_builder = req_builder.bearer_auth(token.to_owned());
102    };
103
104    let req = req_builder.build()?;
105    let resp = configuration.client.execute(req).await?;
106
107    let status = resp.status();
108    let content_type = resp
109        .headers()
110        .get("content-type")
111        .and_then(|v| v.to_str().ok())
112        .unwrap_or("application/octet-stream");
113    let content_type = super::ContentType::from(content_type);
114
115    if !status.is_client_error() && !status.is_server_error() {
116        let content = resp.text().await?;
117        match content_type {
118            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
119            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `serde_json::Value`"))),
120            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`")))),
121        }
122    } else {
123        let content = resp.text().await?;
124        let entity: Option<DeleteTelCallsByIdError> = serde_json::from_str(&content).ok();
125        Err(Error::ResponseError(ResponseContent { status, content, entity }))
126    }
127}
128
129/// Checks the holding is THIS org's before it reaches the carrier. Without that read, an id belonging to another tenant would be released by whoever guessed it.
130pub async fn delete_tel_numbers_by_id(configuration: &configuration::Configuration, id: &str) -> Result<serde_json::Value, Error<DeleteTelNumbersByIdError>> {
131    // add a prefix to parameters to efficiently prevent name collisions
132    let p_id = id;
133
134    let uri_str = format!("{}/v1/tel/numbers/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
135    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
136
137    if let Some(ref user_agent) = configuration.user_agent {
138        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
139    }
140    if let Some(ref token) = configuration.bearer_access_token {
141        req_builder = req_builder.bearer_auth(token.to_owned());
142    };
143
144    let req = req_builder.build()?;
145    let resp = configuration.client.execute(req).await?;
146
147    let status = resp.status();
148    let content_type = resp
149        .headers()
150        .get("content-type")
151        .and_then(|v| v.to_str().ok())
152        .unwrap_or("application/octet-stream");
153    let content_type = super::ContentType::from(content_type);
154
155    if !status.is_client_error() && !status.is_server_error() {
156        let content = resp.text().await?;
157        match content_type {
158            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
159            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `serde_json::Value`"))),
160            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`")))),
161        }
162    } else {
163        let content = resp.text().await?;
164        let entity: Option<DeleteTelNumbersByIdError> = serde_json::from_str(&content).ok();
165        Err(Error::ResponseError(ResponseContent { status, content, entity }))
166    }
167}
168
169/// Lists the calls this org has placed or received, newest first. Like the message list beside it, these are our own records rather than the carrier's.
170pub async fn get_tel_calls(configuration: &configuration::Configuration, ) -> Result<models::CallList, Error<GetTelCallsError>> {
171
172    let uri_str = format!("{}/v1/tel/calls", configuration.base_path);
173    let mut req_builder = configuration.client.request(reqwest::Method::GET, &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
182    let req = req_builder.build()?;
183    let resp = configuration.client.execute(req).await?;
184
185    let status = resp.status();
186    let content_type = resp
187        .headers()
188        .get("content-type")
189        .and_then(|v| v.to_str().ok())
190        .unwrap_or("application/octet-stream");
191    let content_type = super::ContentType::from(content_type);
192
193    if !status.is_client_error() && !status.is_server_error() {
194        let content = resp.text().await?;
195        match content_type {
196            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
197            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CallList`"))),
198            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::CallList`")))),
199        }
200    } else {
201        let content = resp.text().await?;
202        let entity: Option<GetTelCallsError> = serde_json::from_str(&content).ok();
203        Err(Error::ResponseError(ResponseContent { status, content, entity }))
204    }
205}
206
207/// Lists the messages this org has sent or received, newest first. Records from our own store, not the carrier's — so it is what this platform did on the org's behalf, which is the set an audit or a bill has to agree with.
208pub async fn get_tel_messages(configuration: &configuration::Configuration, ) -> Result<models::MessageList, Error<GetTelMessagesError>> {
209
210    let uri_str = format!("{}/v1/tel/messages", configuration.base_path);
211    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
212
213    if let Some(ref user_agent) = configuration.user_agent {
214        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
215    }
216    if let Some(ref token) = configuration.bearer_access_token {
217        req_builder = req_builder.bearer_auth(token.to_owned());
218    };
219
220    let req = req_builder.build()?;
221    let resp = configuration.client.execute(req).await?;
222
223    let status = resp.status();
224    let content_type = resp
225        .headers()
226        .get("content-type")
227        .and_then(|v| v.to_str().ok())
228        .unwrap_or("application/octet-stream");
229    let content_type = super::ContentType::from(content_type);
230
231    if !status.is_client_error() && !status.is_server_error() {
232        let content = resp.text().await?;
233        match content_type {
234            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
235            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MessageList`"))),
236            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::MessageList`")))),
237        }
238    } else {
239        let content = resp.text().await?;
240        let entity: Option<GetTelMessagesError> = serde_json::from_str(&content).ok();
241        Err(Error::ResponseError(ResponseContent { status, content, entity }))
242    }
243}
244
245/// Lists the phone numbers this org HOLDS — the ones it has bought and not released. Distinct from the availability search one path down (`/numbers/available`), which asks the carrier what could be bought: this answers only from our own store, so it is what an org owns rather than what it could own.
246pub async fn get_tel_numbers(configuration: &configuration::Configuration, ) -> Result<models::NumberList, Error<GetTelNumbersError>> {
247
248    let uri_str = format!("{}/v1/tel/numbers", configuration.base_path);
249    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
250
251    if let Some(ref user_agent) = configuration.user_agent {
252        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
253    }
254    if let Some(ref token) = configuration.bearer_access_token {
255        req_builder = req_builder.bearer_auth(token.to_owned());
256    };
257
258    let req = req_builder.build()?;
259    let resp = configuration.client.execute(req).await?;
260
261    let status = resp.status();
262    let content_type = resp
263        .headers()
264        .get("content-type")
265        .and_then(|v| v.to_str().ok())
266        .unwrap_or("application/octet-stream");
267    let content_type = super::ContentType::from(content_type);
268
269    if !status.is_client_error() && !status.is_server_error() {
270        let content = resp.text().await?;
271        match content_type {
272            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
273            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::NumberList`"))),
274            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::NumberList`")))),
275        }
276    } else {
277        let content = resp.text().await?;
278        let entity: Option<GetTelNumbersError> = serde_json::from_str(&content).ok();
279        Err(Error::ResponseError(ResponseContent { status, content, entity }))
280    }
281}
282
283/// Asks the carrier what is available to buy. Nothing is recorded — a search is not a holding, and treating it as one is how inventory leaks.
284pub async fn get_tel_numbers_available(configuration: &configuration::Configuration, country: Option<&str>, area: Option<&str>, r#type: Option<&str>, limit: Option<i32>) -> Result<models::NumberList, Error<GetTelNumbersAvailableError>> {
285    // add a prefix to parameters to efficiently prevent name collisions
286    let p_country = country;
287    let p_area = area;
288    let p_type = r#type;
289    let p_limit = limit;
290
291    let uri_str = format!("{}/v1/tel/numbers/available", configuration.base_path);
292    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
293
294    if let Some(ref param_value) = p_country {
295        req_builder = req_builder.query(&[("Country", &param_value.to_string())]);
296    }
297    if let Some(ref param_value) = p_area {
298        req_builder = req_builder.query(&[("Area", &param_value.to_string())]);
299    }
300    if let Some(ref param_value) = p_type {
301        req_builder = req_builder.query(&[("Type", &param_value.to_string())]);
302    }
303    if let Some(ref param_value) = p_limit {
304        req_builder = req_builder.query(&[("Limit", &param_value.to_string())]);
305    }
306    if let Some(ref user_agent) = configuration.user_agent {
307        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
308    }
309    if let Some(ref token) = configuration.bearer_access_token {
310        req_builder = req_builder.bearer_auth(token.to_owned());
311    };
312
313    let req = req_builder.build()?;
314    let resp = configuration.client.execute(req).await?;
315
316    let status = resp.status();
317    let content_type = resp
318        .headers()
319        .get("content-type")
320        .and_then(|v| v.to_str().ok())
321        .unwrap_or("application/octet-stream");
322    let content_type = super::ContentType::from(content_type);
323
324    if !status.is_client_error() && !status.is_server_error() {
325        let content = resp.text().await?;
326        match content_type {
327            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
328            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::NumberList`"))),
329            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::NumberList`")))),
330        }
331    } else {
332        let content = resp.text().await?;
333        let entity: Option<GetTelNumbersAvailableError> = serde_json::from_str(&content).ok();
334        Err(Error::ResponseError(ResponseContent { status, content, entity }))
335    }
336}
337
338/// Counts what this org holds on the telephony plane: its numbers, its calls and its messages. The one read a dashboard makes before it asks for any list, so it answers three totals and no rows.
339pub async fn get_tel_summary(configuration: &configuration::Configuration, ) -> Result<models::Summary, Error<GetTelSummaryError>> {
340
341    let uri_str = format!("{}/v1/tel/summary", configuration.base_path);
342    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
343
344    if let Some(ref user_agent) = configuration.user_agent {
345        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
346    }
347    if let Some(ref token) = configuration.bearer_access_token {
348        req_builder = req_builder.bearer_auth(token.to_owned());
349    };
350
351    let req = req_builder.build()?;
352    let resp = configuration.client.execute(req).await?;
353
354    let status = resp.status();
355    let content_type = resp
356        .headers()
357        .get("content-type")
358        .and_then(|v| v.to_str().ok())
359        .unwrap_or("application/octet-stream");
360    let content_type = super::ContentType::from(content_type);
361
362    if !status.is_client_error() && !status.is_server_error() {
363        let content = resp.text().await?;
364        match content_type {
365            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
366            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Summary`"))),
367            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::Summary`")))),
368        }
369    } else {
370        let content = resp.text().await?;
371        let entity: Option<GetTelSummaryError> = serde_json::from_str(&content).ok();
372        Err(Error::ResponseError(ResponseContent { status, content, entity }))
373    }
374}
375
376/// Dials. An `agent` names a Hanzo assistant to answer it; the call is refused up front when no assistant plane is configured, because a call that connects to silence has already cost the person who answered it.
377pub async fn post_tel_calls(configuration: &configuration::Configuration, call_input: models::CallInput) -> Result<models::Call, Error<PostTelCallsError>> {
378    // add a prefix to parameters to efficiently prevent name collisions
379    let p_call_input = call_input;
380
381    let uri_str = format!("{}/v1/tel/calls", configuration.base_path);
382    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
383
384    if let Some(ref user_agent) = configuration.user_agent {
385        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
386    }
387    if let Some(ref token) = configuration.bearer_access_token {
388        req_builder = req_builder.bearer_auth(token.to_owned());
389    };
390    req_builder = req_builder.json(&p_call_input);
391
392    let req = req_builder.build()?;
393    let resp = configuration.client.execute(req).await?;
394
395    let status = resp.status();
396    let content_type = resp
397        .headers()
398        .get("content-type")
399        .and_then(|v| v.to_str().ok())
400        .unwrap_or("application/octet-stream");
401    let content_type = super::ContentType::from(content_type);
402
403    if !status.is_client_error() && !status.is_server_error() {
404        let content = resp.text().await?;
405        match content_type {
406            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
407            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Call`"))),
408            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::Call`")))),
409        }
410    } else {
411        let content = resp.text().await?;
412        let entity: Option<PostTelCallsError> = serde_json::from_str(&content).ok();
413        Err(Error::ResponseError(ResponseContent { status, content, entity }))
414    }
415}
416
417/// Sends a message from one of this org's own numbers.  `from` must be a number the org HOLDS, checked against the store rather than taken on trust — a caller that could send from any number could impersonate one, and the carrier would deliver it. `to` is required, and the body needs text or media, because a message with neither is delivered as nothing and billed as something.
418pub async fn post_tel_messages(configuration: &configuration::Configuration, message_input: models::MessageInput) -> Result<models::Sms, Error<PostTelMessagesError>> {
419    // add a prefix to parameters to efficiently prevent name collisions
420    let p_message_input = message_input;
421
422    let uri_str = format!("{}/v1/tel/messages", configuration.base_path);
423    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
424
425    if let Some(ref user_agent) = configuration.user_agent {
426        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
427    }
428    if let Some(ref token) = configuration.bearer_access_token {
429        req_builder = req_builder.bearer_auth(token.to_owned());
430    };
431    req_builder = req_builder.json(&p_message_input);
432
433    let req = req_builder.build()?;
434    let resp = configuration.client.execute(req).await?;
435
436    let status = resp.status();
437    let content_type = resp
438        .headers()
439        .get("content-type")
440        .and_then(|v| v.to_str().ok())
441        .unwrap_or("application/octet-stream");
442    let content_type = super::ContentType::from(content_type);
443
444    if !status.is_client_error() && !status.is_server_error() {
445        let content = resp.text().await?;
446        match content_type {
447            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
448            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Sms`"))),
449            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::Sms`")))),
450        }
451    } else {
452        let content = resp.text().await?;
453        let entity: Option<PostTelMessagesError> = serde_json::from_str(&content).ok();
454        Err(Error::ResponseError(ResponseContent { status, content, entity }))
455    }
456}
457
458/// Provisions with the carrier FIRST and records second. The other order records a holding that may not exist, and a number the platform believes it owns but cannot use is worse than one it failed to buy.
459pub async fn post_tel_numbers(configuration: &configuration::Configuration, buy_input: models::BuyInput) -> Result<models::Number, Error<PostTelNumbersError>> {
460    // add a prefix to parameters to efficiently prevent name collisions
461    let p_buy_input = buy_input;
462
463    let uri_str = format!("{}/v1/tel/numbers", configuration.base_path);
464    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
465
466    if let Some(ref user_agent) = configuration.user_agent {
467        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
468    }
469    if let Some(ref token) = configuration.bearer_access_token {
470        req_builder = req_builder.bearer_auth(token.to_owned());
471    };
472    req_builder = req_builder.json(&p_buy_input);
473
474    let req = req_builder.build()?;
475    let resp = configuration.client.execute(req).await?;
476
477    let status = resp.status();
478    let content_type = resp
479        .headers()
480        .get("content-type")
481        .and_then(|v| v.to_str().ok())
482        .unwrap_or("application/octet-stream");
483    let content_type = super::ContentType::from(content_type);
484
485    if !status.is_client_error() && !status.is_server_error() {
486        let content = resp.text().await?;
487        match content_type {
488            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
489            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Number`"))),
490            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::Number`")))),
491        }
492    } else {
493        let content = resp.text().await?;
494        let entity: Option<PostTelNumbersError> = serde_json::from_str(&content).ok();
495        Err(Error::ResponseError(ResponseContent { status, content, entity }))
496    }
497}
498