artcoded_api/apis/
sms_rest_controller_api.rs

1/*
2 * Artcoded
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: 1.0.0
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16/// struct for typed errors of method [`send`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum SendError {
20    UnknownValue(serde_json::Value),
21}
22
23pub async fn send(
24    configuration: &configuration::Configuration,
25    sms: models::Sms,
26) -> Result<(), Error<SendError>> {
27    // add a prefix to parameters to efficiently prevent name collisions
28    let p_body_sms = sms;
29
30    let uri_str = format!("{}/api/sms", configuration.base_path);
31    let mut req_builder = configuration
32        .client
33        .request(reqwest::Method::POST, &uri_str);
34
35    if let Some(ref user_agent) = configuration.user_agent {
36        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
37    }
38    if let Some(ref token) = configuration.bearer_access_token {
39        req_builder = req_builder.bearer_auth(token.to_owned());
40    };
41    req_builder = req_builder.json(&p_body_sms);
42
43    let req = req_builder.build()?;
44    let resp = configuration.client.execute(req).await?;
45
46    let status = resp.status();
47
48    if !status.is_client_error() && !status.is_server_error() {
49        Ok(())
50    } else {
51        let content = resp.text().await?;
52        let entity: Option<SendError> = serde_json::from_str(&content).ok();
53        Err(Error::ResponseError(ResponseContent {
54            status,
55            content,
56            entity,
57        }))
58    }
59}