use super::{ContentType, Error, configuration};
use crate::clients::rest::{apis::ResponseContent, models};
use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum V1WebhookCreateError {
Status400(models::V1TaskGet400Response),
Status403(models::V1TaskGet400Response),
Status404(models::V1TaskGet400Response),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum V1WebhookDeleteError {
Status400(models::V1TaskGet400Response),
Status403(models::V1TaskGet400Response),
Status404(models::V1TaskGet400Response),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum V1WebhookGetError {
Status400(models::V1TaskGet400Response),
Status403(models::V1TaskGet400Response),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum V1WebhookListError {
Status400(models::V1TaskGet400Response),
Status403(models::V1TaskGet400Response),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum V1WebhookReceiveError {
Status400(models::V1TaskGet400Response),
Status403(models::V1TaskGet400Response),
UnknownValue(serde_json::Value),
}
pub async fn v1_webhook_create(
configuration: &configuration::Configuration,
tenant: &str,
v1_webhook_create_request: models::V1WebhookCreateRequest,
) -> Result<models::V1WebhookList200ResponseRowsInner, Error<V1WebhookCreateError>> {
let p_tenant = tenant;
let p_v1_webhook_create_request = v1_webhook_create_request;
let uri_str = format!(
"{}/api/v1/stable/tenants/{tenant}/webhooks",
configuration.base_path,
tenant = crate::clients::rest::apis::urlencode(p_tenant)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_v1_webhook_create_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::V1WebhookList200ResponseRowsInner`",
)));
}
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::V1WebhookList200ResponseRowsInner`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<V1WebhookCreateError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn v1_webhook_delete(
configuration: &configuration::Configuration,
tenant: &str,
v1_webhook: &str,
) -> Result<models::V1WebhookList200ResponseRowsInner, Error<V1WebhookDeleteError>> {
let p_tenant = tenant;
let p_v1_webhook = v1_webhook;
let uri_str = format!(
"{}/api/v1/stable/tenants/{tenant}/webhooks/{v1_webhook}",
configuration.base_path,
tenant = crate::clients::rest::apis::urlencode(p_tenant),
v1_webhook = crate::clients::rest::apis::urlencode(p_v1_webhook)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::DELETE, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::V1WebhookList200ResponseRowsInner`",
)));
}
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::V1WebhookList200ResponseRowsInner`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<V1WebhookDeleteError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn v1_webhook_get(
configuration: &configuration::Configuration,
tenant: &str,
v1_webhook: &str,
) -> Result<models::V1WebhookList200ResponseRowsInner, Error<V1WebhookGetError>> {
let p_tenant = tenant;
let p_v1_webhook = v1_webhook;
let uri_str = format!(
"{}/api/v1/stable/tenants/{tenant}/webhooks/{v1_webhook}",
configuration.base_path,
tenant = crate::clients::rest::apis::urlencode(p_tenant),
v1_webhook = crate::clients::rest::apis::urlencode(p_v1_webhook)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::V1WebhookList200ResponseRowsInner`",
)));
}
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::V1WebhookList200ResponseRowsInner`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<V1WebhookGetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn v1_webhook_list(
configuration: &configuration::Configuration,
tenant: &str,
offset: Option<i64>,
limit: Option<i64>,
source_names: Option<Vec<String>>,
webhook_names: Option<Vec<String>>,
) -> Result<models::V1WebhookList200Response, Error<V1WebhookListError>> {
let p_tenant = tenant;
let p_offset = offset;
let p_limit = limit;
let p_source_names = source_names;
let p_webhook_names = webhook_names;
let uri_str = format!(
"{}/api/v1/stable/tenants/{tenant}/webhooks",
configuration.base_path,
tenant = crate::clients::rest::apis::urlencode(p_tenant)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_offset {
req_builder = req_builder.query(&[("offset", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_source_names {
req_builder = match "multi" {
"multi" => req_builder.query(
¶m_value
.into_iter()
.map(|p| ("sourceNames".to_owned(), p.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"sourceNames",
¶m_value
.into_iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]),
};
}
if let Some(ref param_value) = p_webhook_names {
req_builder = match "multi" {
"multi" => req_builder.query(
¶m_value
.into_iter()
.map(|p| ("webhookNames".to_owned(), p.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"webhookNames",
¶m_value
.into_iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]),
};
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::V1WebhookList200Response`",
)));
}
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::V1WebhookList200Response`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<V1WebhookListError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn v1_webhook_receive(
configuration: &configuration::Configuration,
tenant: &str,
v1_webhook: &str,
) -> Result<models::V1WebhookReceive200Response, Error<V1WebhookReceiveError>> {
let p_tenant = tenant;
let p_v1_webhook = v1_webhook;
let uri_str = format!(
"{}/api/v1/stable/tenants/{tenant}/webhooks/{v1_webhook}",
configuration.base_path,
tenant = crate::clients::rest::apis::urlencode(p_tenant),
v1_webhook = crate::clients::rest::apis::urlencode(p_v1_webhook)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::V1WebhookReceive200Response`",
)));
}
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::V1WebhookReceive200Response`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<V1WebhookReceiveError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}